aspose file tools*
The moose likes Servlets and the fly likes How to show the jsp Url while forwarding from a servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to show the jsp Url while forwarding from a servlet" Watch "How to show the jsp Url while forwarding from a servlet" New topic
Author

How to show the jsp Url while forwarding from a servlet

Rajibul Alam
Greenhorn

Joined: Jul 01, 2009
Posts: 13
Hi,

I have a login servlet and based on the user type it needs to forward user to specific types of profile/main pages. It does whats it suppose to do but the url on the browser shows the servlet name. "http://localhost:8080/project/LoginServlet" instead of showing "http://localhost:8080/project/Admin/mainPage.jsp"

How do I achieve this???




thanks

Rajib



Himanshu Kansal
Ranch Hand

Joined: Jul 05, 2009
Posts: 257
You'll ned to give a mapping for the servlet to a particular jsp. Do it in web.xml if you are not using any framework like Struts.

Regards


Experience and talent are independent of age
Rajibul Alam
Greenhorn

Joined: Jul 01, 2009
Posts: 13
Himanshu Kansal wrote:You'll ned to give a mapping for the servlet to a particular jsp. Do it in web.xml if you are not using any framework like Struts.

Regards



Thanks for the reply

But how do I map a servlet that can map to several JSP like this case. Can you please give an example of multiple mapping from one servlet. Or an example to do the mapping for the servlet to a particular jsp


thanks in advance

Rajib
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60055
    
  65

You don't. That's the whole point of the forward!

Why would you want it to?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Rajibul Alam
Greenhorn

Joined: Jul 01, 2009
Posts: 13
Bear Bibeault wrote:You don't. That's the whole point of the forward!

Why would you want it to?


Well I was just curious if there was a way to show the right jsp rather than the servlet in the url. It would help me fix some problem with the urls that i am facing in later part of the project. for example after deleting a user It sends the admin back to main page and from that page if I click any link that gets messed up as the context url is showing the deletservlet link.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Then you're probably forwarding instead of redirecting.

But as Bear said--you don't *want* to show the JSP in the URL, you want to show the URL of the servlet.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60055
    
  65

You're not following the proper patterns -- that's what's causing your problems. The solution isn't to try and trick the forward (you can't) but to structure your application correctly.

Read this article and pay particular attention to the "PRG Pattern".
Rajibul Alam
Greenhorn

Joined: Jul 01, 2009
Posts: 13
Bear Bibeault wrote:You're not following the proper patterns -- that's what's causing your problems. The solution isn't to try and trick the forward (you can't) but to structure your application correctly.

Read this article and pay particular attention to the "PRG Pattern".


thanks a lot....for the article

I guess now I get to spend my weekend in a productive way
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to show the jsp Url while forwarding from a servlet
 
Similar Threads
Default page for some path
AJAX Problem in JSP
multiple URL mapping for one web app
AJAX in JSP
Servlets not loading