0

I am trying to display dynamic data in jsp. for that I am calling java method inside a jsp using jsp expression. this java method is taking much time but it is returning some value.(I cant reduce the method execution time.) But my jsp is showing blank. Can anybody explain what would be the reason and how to resolve. This code is not written by me But I need to find out the root cause.

my jsp code look like

  display.jsp

       ..... hello......start...

       <%= obj.getDynamicData() %>     

      .....completed .... end     
Satya
  • 8,146
  • 9
  • 38
  • 43

2 Answers2

2

It's likely because you're (ab)using JSP to execute some raw Java code. When an exception is been thrown halfway sending the JSP's output, the remnant of the JSP won't be sent to the browser anymore. But the webserver cannot change the response into an error page with exception details anymore as well and the webbrowser will end up with a halfbaked HTML output which is often displayed as a blank page.

Any uncaught exception is usually logged into server's logfile. You need to dig in the server's logs for the exception and stacktrace so that you can fix the root cause of the problem. Exceptions contain worthful information about the cause of the problem.

A halfbaked HTML page is just an incomplete HTML page which caused the webbrowser not to understand how to display it properly. Rightclick the page in webbrowser and choos View Source. Verify if it is as expected, if necessary with help of the w3 validator.

Further, it may be worth the effort trying in different (better) webbrowsers like Firefox and Chrome. MSIE6/7 is namely known to choke like that when it has received an enormously HTML <table>. It has a poor table rendering engine.


To save yourself from future trouble like this, I suggest to move all that Java code out into a Servlet class so that you can get a more friendly (at least, it's better than digging in server's log files) error page in case of an exception in Java code. See also How to avoid Java code in JSP?

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Java method is not throwing any exception. and I able to get the method return value. but i is not rendering in jsp – Satya Oct 06 '10 at 04:38
  • The symptoms tells otherwise. Did you check the server logs anyway? Did you check the retrieved HTML output in browser? Note that exceptions doesn't necessarily go in the standard logfile. Check the error logfile(s) as well. Exact filename/location depends on the servletcontainer used. – BalusC Oct 06 '10 at 04:39
  • @Satya, how do you know you can get the return value if the page you print the return value on is not rendering? – matt b Oct 06 '10 at 04:45
  • Also try testing in different browsers. MSIE6/7 is known to choke like that when it gets an enormously large HTML ``.
    – BalusC Oct 06 '10 at 04:49
  • I am debugging the code using eclipse and by inspecting the method's return value I confirmed that it giving some value without throwing any exception(but it is giving value after some time.) – Satya Oct 06 '10 at 04:50
  • 1
    and the debugger isn't telling you what happens in the JSP-generated Java class after the method in question completes? Or are you testing the method in question with different code, in which case you might be comparing apples to oranges? Here's an easy test - does the JSP render if you temporarily comment out/remove the call to `obj.getDynamicData()`? – matt b Oct 06 '10 at 04:55
  • Well, I clarified/updated some bits in answer. It's bedtime for me, I'll see tomorrow how it ends up. – BalusC Oct 06 '10 at 04:59
  • ok, thanks BalusC , When I comment the call to obj.getDynamicData(), jsp page rendered properly. – Satya Oct 06 '10 at 05:16
1

Based on the comments made in BalusC's answer:

When I comment the call to obj.getDynamicData(), jsp page rendered properly.

Either one of two things could be happening:

  1. obj.getDynamicData() is throwing an exception which is not caught and handled
  2. Your servlet container/server may be configured with some sort of "request timeout" that closes the HTTP connection if it takes more than a certain amount of time to process the request, and obj.getDynamicData() takes so long to execute that this timeout is being triggered.

Do you have any sort of logging in your code or JSP that tells you what happens server-side after this method finishes processing? A strong hint that #2 is occuring would be if you continue to see log activity from the thread processing the JSP request (and obj.getDynamicData()) after the browser has stopped waiting for the request / received the blank page.

And to rule out the simple things, are you sure that the server is actually returning an empty response, and not that your browser is showing a blank page because the server returned half an HTML page? Make sure to check View Source, use a tool like Firebug, and/or make the same HTTP request that you do in a browser from a command-line tool like curl or wget.

Community
  • 1
  • 1
matt b
  • 138,234
  • 66
  • 282
  • 345