• Post Reply Bookmark Topic Watch Topic
  • New Topic

how can I determine which link was clicked?  RSS feed

 
James Byars
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi guys,

in my servlet, I am outputting onto the browser three lines:

A
B
C

When A, B or C are clicked, they will all redirect to another servlet. Now in this new servlet, I want to perform an action depending on which of A, B or C was clicked. How can I determine this? If I was using Java Swing I would use the event source, but how can I do something similar in my servlet?

thanks
 
Jitendra Takalkar
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can pass parameter to new servlet, javax.servlet.http.HttpServlet. based on the parameter value decide what you want to do. Use following API to get the value of parameter.

 
Eduardo Bueno
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[Hi-jack removed]
 
Jitendra Takalkar
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If A, B and C lines are anchor links then you can pass parameter using query string.

For example:
Assume servleturi map to your new servlet.

http://host:port/webapp/servleturi?type=A for line A
http://host:port/webapp/servleturi?type=B for line B etc

Use getParameter() method to get the value of parameter - type, as follows

String parameterType=HttpServletRequest.getParameter("type");


 
James Byars
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jitendra Takalkar wrote:If A, B and C lines are anchor links then you can pass parameter using query string.

For example:
Assume servleturi map to your new servlet.

http://host:port/webapp/servleturi?type=A for line A
http://host:port/webapp/servleturi?type=B for line B etc

Use getParameter() method to get the value of parameter - type, as follows

String parameterType=HttpServletRequest.getParameter("type");





Great answer, that helps a lot

thanks
 
Eduardo Bueno
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[hijack removed]
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[Removed answer for hijacked thread]
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66144
144
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thread hi-jack removed.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!