File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes hyperlink-event using a servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "hyperlink-event using a servlet" Watch "hyperlink-event using a servlet" New topic

hyperlink-event using a servlet

stathis tas

Joined: Apr 04, 2011
Posts: 1
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

Joined: Jan 10, 2002
Posts: 63858

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.

[Asking smart questions] [About Bear] [Books by Bear]
Madhan Sundararajan Devaki
Ranch Hand

Joined: Mar 18, 2011
Posts: 312

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.

Not many get the right opportunity !
I agree. Here's the link:
subject: hyperlink-event using a servlet
It's not a secret anymore!