tags:

views:

35

answers:

3

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     
+2  A: 

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?

BalusC
Java method is not throwing any exception. and I able to get the method return value. but i is not rendering in jsp
Satya
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
@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
Also try testing in different browsers. MSIE6/7 is known to choke like that when it gets an enormously large HTML `<table>`.
BalusC
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
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
Well, I clarified/updated some bits in answer. It's bedtime for me, I'll see tomorrow how it ends up.
BalusC
ok, thanks BalusC , When I comment the call to obj.getDynamicData(), jsp page rendered properly.
Satya
A: 

You provided very brief information. Having said that, it looks to me that you are not really very familiar with the technology. One thing you should know first and foremost that JSP is not a client-side technology. It runs on server, and present HTML document to the client, most probably a browser. Browsers knows how to render HTML.

One of the best resource to start learning JSP, JavaRanch: A Friendly Place for Java Beginners.

Adeel Ansari
All nice and well, but how does this *answer* the question? It's easy to recommend ones having trouble with technology X to learn technology X. Since this is basically all what this answer is telling, rather post that as a comment :)
BalusC
@BalusC: In my opinion, I already answered the question by suggesting that JSP is a server-side technology. It will help in case my assumption is right. I based my assumption on previous experience. New folks think JSP is being processed on client-side. And for that reason I have seen very stupid code which used to involve scriptlets in the middle of JavaScript loop, and they assume some result based on this wrong assumption. What you have said in your answer, might not make any sense to him, if he is really new and don't even know what the heck is Servlet, error page, and response.
Adeel Ansari
@BalusC: And he might think that from where this halfbaked HTML come into play when I am actually working with JSP, not HTML. Therefore, I think it better to suggest him some tutorials instead, before telling him to avoid Java code in JSP.
Adeel Ansari
The OP could just ask for clarification.
BalusC
@BalusC: Yes, indeed. And he is doing that already.
Adeel Ansari
+1  A: 

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.

matt b