aspose file tools*
The moose likes JSP and the fly likes Servlet Response Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Servlet Response" Watch "Servlet Response" New topic
Author

Servlet Response

Em Aiy
Ranch Hand

Joined: May 11, 2006
Posts: 226
There is a jsp page, which have few links to download a file. Now when user clicks on those links a servlet is called say "downloadReport" servlet, which make a temporary file of that particular report, set the response type accordingly and write all the data to the stream. it is working fine to download the report and THAT JSP page remain visible. No change and no apparent submission of that page.

But the problem arises when there is some exception in the servlet. the jsp page disappear and there is servlet error msg. Now how can handle this?


The difference between <b>failure</b> and <b>success</b> is often being <b>right</b> and being <b>exactly right</b>.
Richard Green
Ranch Hand

Joined: Aug 25, 2005
Posts: 536
how do you handle exceptions in your servlet?


MCSD, SCJP, SCWCD, SCBCD, SCJD (in progress - URLybird 1.2.1)
Em Aiy
Ranch Hand

Joined: May 11, 2006
Posts: 226
to my astonish, i haven't writen any try/catch clause. I just read the parameters i get from request, make the appropriate file through some other class (in which i have handled exceptions and return false to servlet if some occurs) ... The returned false status of file tell the servlet whether the file is ready to download or not. if it is then i make the stream and write it ... now what should i do if the return status is FALSE from the makeReportClass ???
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
You can implement "please wait..." mechanism here.

Searching the same or servlet forum with the string "please wait" would result in a number of threads discussing the same.
Darren Edwards
Ranch Hand

Joined: Aug 17, 2005
Posts: 69
You have to decide who's fault it is.

If the user entered invalid parameters you should tell them which ones were invalid and ask them to correct them.

If there is an error at the server (maybe IOException) all you can do is show the user a friendly error message like "Unable to create report, please try again later".
Em Aiy
Ranch Hand

Joined: May 11, 2006
Posts: 226
User has nothing to do with input. he just have to click on either of the links telling the report format (CSV/PDF/XLS) ... the javascript get the userclick option and submit the form at DownloadReport serlvet. (The jsp remain visible in the browser) ... now from DownloadReport i call Report class to generate the report ... if it is successfull it writes data onstream .. which make a download box appear at tha page to save the file (working fine)

Now if the report is not created (IOException) ... how can i manage to get the response of the JSP that is already been displayed to display some info there ??? I want to display the information at the same JSP file.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Servlet Response