• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Redirecting to different pages using a servlet Controller

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
G'day everyone,

I have four jsps say A,B,C,D and a servlet E.
I would like to have the servlet E display the page C if the request came from page A and page D if the request came from page B.
Is this possible/good idea?
If possible, is there any method available which can tell the servlet from where(which page) the request came?
If not/bad idea, what would be a good alternative?
Thanks.
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Peter Maxwell wrote:
Is this possible/good idea?



Possible . It is not a bad idea, since servlet is a good controller. and you need to check the input parameters(which are from the jsps) in servlet using else if or switch
 
Ranch Hand
Posts: 221
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think Request Dispatcher wil help you
 
Peter Maxwell
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks seetharaman and harilal for quick replies.

seetharaman venkatasamy wrote:

Peter Maxwell wrote:
Is this possible/good idea?



Possible . It is not a bad idea, since servlet is a good controller. and you need to check the input parameters(which are from the jsps) in servlet using else if or switch



Is checking the input parameter is the only way to determine the source of the request or is there any specific method to do this?
I can always use a hidden parameter to differentiate between two pages when they have the same type/number of parameters(or both have no parameters) but it would be nice to know if there are any method specifically to deal with this.

Thanks again.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Peter Maxwell wrote:Thanks seetharaman and harilal for quick replies.


You are welcome

Peter Maxwell wrote:
Is checking the input parameter is the only way to determine the source of the request or is there any specific method to do this?
I can always use a hidden parameter to differentiate between two pages when they have the same type/number of parameters(or both have no parameters) but it would be nice to know if there are any method specifically to deal with this.



Alternate ways:

1.QueryString parameter

2. wild card servlet mapping
 
Sheriff
Posts: 67754
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First, why share the controller in this way? Why does each page not get its own controller? Do you have a good reason for the sharing?

Secondly, it's a bad idea to switch based upon implicit information such as where the page came from. This makes you code tightly coupled and fragile. Better to use explicit information such as a parameter.
 
Peter Maxwell
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:First, why share the controller in this way? Why does each page not get its own controller? Do you have a good reason for the sharing?

Secondly, it's a bad idea to switch based upon implicit information such as where the page came from. This makes you code tightly coupled and fragile. Better to use explicit information such as a parameter.


Thanks Bear Bibeault for replying.
Well I thought it(sharing the controlloer) might save code and extra file for another servlet. Other than that i don't really have a good reason. So i'd be better off with a separate controller i guess.


Alternate ways:

1.QueryString parameter

2. wild card servlet mapping


Thanks Seetharaman,
I tried googling those terms but i couldn't get any pages explaining them.
Could you explain what they are?
Thanks.
reply
    Bookmark Topic Watch Topic
  • New Topic