my dog learned polymorphism
The moose likes Servlets and the fly likes Servlet request Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlet request" Watch "Servlet request" New topic

Servlet request

ALaxmi Shankaran

Joined: Feb 23, 2004
Posts: 26
I have one servlet method .In that depending upon the different request(From 2 different jsp pages ),i want to redirect to 2 different pages .
How can i get that from where the request comes?
Julian Kennedy
Ranch Hand

Joined: Aug 02, 2004
Posts: 823
You could try request.getRequestURI() though I'm not sure that would be good practice. If your two pages are actually doing different things then, from an application design point of view, it makes more sense to have two separate actions, e.g. (very generally) page1.jsp?action=page1_submit and page2.jsp?action=page2_submit. That way you don't need to worry about which page generated the request. You'd just use request.getParameter("action") and then forward appropriately according to the action.

satish sathineni
Ranch Hand

Joined: May 03, 2004
Posts: 46
As Julian Said use a hidden variable with some "xxx" name and assign different values depending on the page submit to a servlet


and then depending on the value u forwarding to different pages.....

Praful Thakare
Ranch Hand

Joined: Feb 10, 2001
Posts: 642

Simplyfying Satish's solution:

In jsp1 define <hidden name="source" value="jsp1">
In jsp21 define <hidden name="source" value="jsp2">

and following thing in servlets method

String redirect=request.getParameter("source");

if(redirect!=null && redirect.equals("jsp1"))
redirect where ever you want
if(redirect!=null && redirect.equals("jsp2"))
again go where ever you like

hope this helps


All desirable things in life are either illegal, banned, expensive or married to someone else !!!
I agree. Here's the link:
subject: Servlet request
It's not a secret anymore!