This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Svelte and Sapper in Action and have Mark Volkmann on-line!
See this thread for details.
Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Servlet request

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Jules
 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As Julian Said use a hidden variable with some "xxx" name and assign different values depending on the page submit to a servlet

request.getParameter("xxx");

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


regards
satish
 
Ranch Hand
Posts: 645
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

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
else
if(redirect!=null && redirect.equals("jsp2"))
again go where ever you like

hope this helps

Cheers
Praful
 
It's never done THAT before. Explain it to me tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic