aspose file tools*
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


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "hyperlink-event using a servlet" Watch "hyperlink-event using a servlet" New topic
Author

hyperlink-event using a servlet

stathis tas
Greenhorn

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
Marshal

Joined: Jan 10, 2002
Posts: 61066
    
  66

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] [Bear's FrontMan] [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.


S.D. MADHAN
Not many get the right opportunity !
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: hyperlink-event using a servlet