Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to show the jsp Url while forwarding from a servlet

 
Rajibul Alam
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 257
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Rajibul Alam
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64830
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don't. That's the whole point of the forward!

Why would you want it to?
 
Rajibul Alam
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64830
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic