Win a copy of Succeeding with AI this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Junilu Lacar
Sheriffs:
  • Tim Cooke
  • Jeanne Boyarsky
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • fred rosenberger
  • Frits Walraven

Servlet Response

 
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 536
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how do you handle exceptions in your servlet?
 
Em Aiy
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ???
 
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 226
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
"Don't believe every tiny ad you see on the internet. But this one is rock solid." - George Washington
Two software engineers solve most of the world's problems in one K&R sized book
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic