File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Query about Request Forwarding Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Query about Request Forwarding" Watch "Query about Request Forwarding" New topic

Query about Request Forwarding

Ragav Baskaran
Ranch Hand

Joined: Nov 04, 2007
Posts: 36

I have a requirement where the user will fill some information in a HTML page and upon page submit, it sends the entered information to a Servlet through "POST" method.

Now in the Servlet i have a business logic where it creates a file, based on the inputs from the page.

After this i want to open up a seperate browser/popup to display the content of the file which i newly created.

I'm able to do this in the same browser. But my requirement is to open it up in a seperate(new) browser/popup.

Steve Luke

Joined: Jan 28, 2003
Posts: 4181

Set the target for the form to a blank window (new window every time form is submitted), or a window with a name (submissions go to the same window if it is left open).

Ragav Baskaran
Ranch Hand

Joined: Nov 04, 2007
Posts: 36
Hi Steve,
Thanks for your inputs.

Though the solution given by you works, but it won't fit to my requirement as a whole, because in my case i'm doing a validation (of the input given in the form) in my servlet and then based on the validation result i may have to decide either to open a new window(if validation is successful) or else display an error message in the old window itself with out opening the new window.

Is there any way, where we can instruct the browser to do this based on the servlet response ??

[ August 03, 2008: Message edited by: Raga Vendran ]
anubechara Gupta

Joined: Jul 05, 2006
Posts: 17
I think you can set some flag in the request object and based on this flag you can execute javascript in your target page to open new window.
eg. If your form data is validated set value of "validationFlag" in request object as "true" and on page load use java script to open new window if flag is true.
<script> ("outputfile.txt","mywindow");
Ankit Garg

Joined: Aug 03, 2008
Posts: 9463

Have you read the book Java Servlet Programming By Jason Hunter(Oreilly). In the 6th chapter it uses it's custom library to send a multi-part response. It's fairly simple. I think you should try it...

SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
I agree. Here's the link:
subject: Query about Request Forwarding
It's not a secret anymore!