• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

hyperlink-event using a servlet

 
stathis tas
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a web application that uses a main servlet. My objective is to have everything pointing at the servlet in which most of the business logic is implemented. Currently, my servlet contains a few else-if statements that capture various button-clicks. At this point, I would like to have a jsp page that will have dynamically generated content based on the hyperlink clicked. My problem is that I cannot capture the hyperlink-click event on the servlet; capturing a button can be as easy as having an if-statement, but there is no such feature for the anchors.

One solution might include the use of javascript; if I am not mistaken it is possible to capture such events using a simple function, however I am not sure whether it is possible from inside the function to set a parameter/attribute on the session.

Another solution would be to create more servlets that would take care each hyperlink (by having the hyperlink itself pointing at the servlet and implementing an "on-page-load") however this is not an option because the hyperlinks themselves are dynamically generated and also that would pretty much ruin my design (one main servlet).

I was hoping there is a way when clicking a hyperlink some value would change (in a form maybe?) and this change could be captured by the servlet. (e.g. when clicking the hyperlink set a parameter on the session?)

Any suggestions/directions would be much appreciated.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65216
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You cannot detect clicks while the servlet is executing because the generated HTML hasn't even been sent to the browser yet for the user to click upon. Either relying upon a click generating another request to a servlet, or using JavaScript, are the only means to know when a link is clicked after the page has been sent to the browser.
 
Madhan Sundararajan Devaki
Ranch Hand
Posts: 312
Java MS IE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try generating the hyperlink that points to the required Servlet, along with query strings and values. In the Servlet, get the HTTP parameters and do the needful.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic