File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes How to open a new jsp page from servlets ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to open a new jsp page from servlets ?" Watch "How to open a new jsp page from servlets ?" New topic
Author

How to open a new jsp page from servlets ?

Tanima Gupta
Greenhorn

Joined: Mar 18, 2011
Posts: 12
Hello,
I want to open a new jsp page after the processing done in servlets... How is this possible??
Hussein Baghdadi
clojure forum advocate
Bartender

Joined: Nov 08, 2003
Posts: 3476

You aren't opening a JSP page, you are forwarding or redirecting to a JSP page.
Check Servlet API for forwarding and redirecting.
Tanima Gupta
Greenhorn

Joined: Mar 18, 2011
Posts: 12
thanks for the reply....i tried both forwarding and redirecting.. but instead of navigating to other page it sends the code of the new jsp in the form of response to index.jsp instead..
Hussein Baghdadi
clojure forum advocate
Bartender

Joined: Nov 08, 2003
Posts: 3476

Sorry, I didn't understand. Would you please elaborate more?
Ryan Beckett
Ranch Hand

Joined: Feb 22, 2009
Posts: 192
You can forward using RequestDispatcher.forward and redirect using HttpServletResponse.sendRedirect.

Inside your Servlet:
Tanima Gupta
Greenhorn

Joined: Mar 18, 2011
Posts: 12
John Todd wrote:Sorry, I didn't understand. Would you please elaborate more?


ohk i have made a jsp page where i am using both jsp and ajax.. in ajax you use xmlhttp.responseText to get the response from the server(through servlet)..
In servlets, verification is done properly...after the verification i want to navigate the user to his profile i.e. a new jsp page .....for that i am using both RequestDispatcher as well as sendRedirect..
In sendRedirect, response is first sent to client and then to the server for accessing another page..which i dont want..
In RequestDispatcher its happening the same as well.....the entire code of the new jsp sent in the form of response to client in xmlhttp.responseText....
it does not forward to another jsp from servlet...

I hope you get it now..
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60059
    
  65

If you want to move to a new page, don't use Ajax. The whole purpose of Ajax is to make a request without doing a page reload.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Tanima Gupta
Greenhorn

Joined: Mar 18, 2011
Posts: 12
Bear Bibeault wrote:If you want to move to a new page, don't use Ajax. The whole purpose of Ajax is to make a request without doing a page reload.



Yes probably this was my mistake. The Ajax call was making the response come back to the client. I removed Ajax code and doing with simple jsp and servlets and its working fine..

Thankyou all for your help
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to open a new jsp page from servlets ?
 
Similar Threads
Automate login..... HELP
Doubt with JSTL
why struts
java script for open jsp file
opening a pdf from jsp page