Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

JSP Page fires twice

Avatar

Level 6

Hi,

I have a problem with some jsp pages firing twice.

In a jsp page I have a bundle. It is called exactly once. Inside the bundle it makes a save to the jcr. This save is called exactly once inside the bundle. It is done at the entrance to the bundle. This save method is not part of a conditional or a loop.

When debugging the page in Eclipse I attach to LocalHost set up in debug mode.

Straight after the bundle is created then its service method called in the jsp I place an arbitrary html header tag to print out an arbitrary numerator.

Inside Eclipse as I debug the code inside the bundle gets called, then straight after the bundle exits it immediately gets called again.

The jsp still has not got to the next line straight after the bundle's method is called.

Straight after the second iteration through the bundle the control returns to the jsp.

This also occurred on a separate component that ends up sending an email twice.

 

Regards

Clive Stewart

1 Accepted Solution

Avatar

Correct answer by
Level 6

I have found what caused the jsp to fire twice in my case.

If any variable on the jsp gains a null and then a read to the variable is done the server re parses the page.

In the jsp any variable calling to a service that could fail or return a null needs to be first checks for null.
Example


var a = whateverMethod();//where {in pseduocode where var can be an object, String etc} private String whateverMethod() {returns a variable that is null from a failed process inside a try catch}.
String b = (String) a;
The server appears to try parse the line twice before continuing onto the next line in the jsp.

In my case I resolved it by using
String b = "";
if (a != null) {
  b =(String) a;
} else {
 b = {default};
}


        
 

View solution in original post

1 Reply

Avatar

Correct answer by
Level 6

I have found what caused the jsp to fire twice in my case.

If any variable on the jsp gains a null and then a read to the variable is done the server re parses the page.

In the jsp any variable calling to a service that could fail or return a null needs to be first checks for null.
Example


var a = whateverMethod();//where {in pseduocode where var can be an object, String etc} private String whateverMethod() {returns a variable that is null from a failed process inside a try catch}.
String b = (String) a;
The server appears to try parse the line twice before continuing onto the next line in the jsp.

In my case I resolved it by using
String b = "";
if (a != null) {
  b =(String) a;
} else {
 b = {default};
}