File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes Creating a new JSP from a Servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Creating a new JSP from a Servlet" Watch "Creating a new JSP from a Servlet" New topic
Author

Creating a new JSP from a Servlet

Christopher Elkins
Ranch Hand

Joined: Oct 26, 2004
Posts: 45
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.


Christopher Elkins, SCJP Java 2 Platform
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60765
    
  65

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

I have an example app that does something similar:
http://simple.souther.us/not-so-simple.html

Look for Long Running Process.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Creating a new JSP from a Servlet
 
Similar Threads
"Right Way" to kick off CPU-intensive task from servlet
serving HTML with images from the database
send some dummy response to client while keep executing current jsp page
oracle stored proc for tree
Request input stream