This week's book giveaway is in the Spring forum.
We're giving away four copies of Spring in Action (5th edition) and have Craig Walls on-line!
See this thread for details.
Win a copy of Spring in Action (5th edition) this week in the Spring 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
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

Creating a new JSP from a Servlet  RSS feed

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not sure if this should be in Servlets or JSP so I appologize if it's in the wrong spot. Here's what I've got...

The user can click a link on the jsp which will start a separate custom thread object running. This thread queries the database and creates a "report", actually a multidimensional array of Strings. Meanwhile the user is forwarded back to the page that they were on and may continue to traverse the web site. When the report is finished it is suppose to display the results in a new browser window with a content type of "text/tab-separated-values". I have two issues.

1) When trying to forward the user back to their web page I get an ArrayOutOfBounds Exception.

2) I can't get the report to display once it's finished. My latest attempt was to pass the HTTPServletResponse object back to the thread class so that I can use a PrintWriter to create the new jsp. Didn't work.

Does anyone have experience trying to do something like this? Any help would be greatly appreciated.
 
Marshal
Posts: 67163
169
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can't help you with (1), that's an issue somewhere in your code.

For (2), you cannot keep the response object around -- it goes out of scope as soon as it is returned to the client. You'll need to rethink your approach on this as you cannot send a response object back to the client at the end of your thread. HTTP just doesn't work that way.

The most obvious approach would be to spawn a new window at the time of the original request and submit the long-process to it while returning the user to the original page in the main window. When the procesing is complete, it displays in the new window.
 
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an example app that does something similar:
http://simple.souther.us/not-so-simple.html

Look for Long Running Process.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!