• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Redirecting to different pages using a servlet Controller

 
Peter Maxwell
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • 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.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • 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
 
harilal ithikkat
Ranch Hand
Posts: 221
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think Request Dispatcher wil help you
 
Peter Maxwell
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • 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 Java Windows XP
  • Mark post as helpful
  • send pies
  • 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
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64720
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic