aspose file tools*
The moose likes Servlets and the fly likes accessing clicked hyperlink value of jsp page  in servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "accessing clicked hyperlink value of jsp page  in servlet " Watch "accessing clicked hyperlink value of jsp page  in servlet " New topic
Author

accessing clicked hyperlink value of jsp page in servlet

rammie singh
Ranch Hand

Joined: Mar 26, 2009
Posts: 116
Hi everybody

i am having a application where on a jsp page i have provided many links.
like this



here clicking on respective link , the user goes to corresponding linked page.


REQUIREMENT

What i require is instead of this flat link , i should first go to servlet and there deciding on which link has been clicked
i should move respective page.
can any body help me please , how to achieve this and what will be the servlet code to fetch the clicked link.

This jsp has a form tag which goes to servlet /RequestHandler


Sebastian Janisch
Ranch Hand

Joined: Feb 23, 2009
Posts: 1183
You need to create a servlet mapping in your web.xml to direct your request to the corresponding servlet.



Now, whatever points to http://localhost:8080/PROJECT_NAME/RequestHandler will be redirected to the RequestHandler class.

This class needs to extend HttpServlet and override doGet or doPost.

In the servlet, then determine which page is requested. You could append a parameter to the url like ?page=PAGE_22, pick up this parameter and take it from there.


JDBCSupport - An easy to use, light-weight JDBC framework -
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
You can just append the URL as a parameter when you are constructing the URL string.


Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
rammie singh
Ranch Hand

Joined: Mar 26, 2009
Posts: 116
see what i am trying is writing here.
But is is giving a NumberFormatException.



where ?RequestHandler is the servlet where the action is supposed to go.

Now In my RequestHandler Servlet i am fetching the hidden variable value , which is 60 here and depending on this
value , the corresponding switch case is executed in the servlet.

code in requestHandler


Now on clicking on any link gives error as



presize is the name of my application and the main folder.

in RequestHandler class i am fetching the link clicked as



but it is not printing any of the message and giving NumberFormatException
any suggestions??

I don't know if writing action="/RequestHandler" in form tag and in thehypelink is correct or not. please comment.
rammie singh
Ranch Hand

Joined: Mar 26, 2009
Posts: 116
can any body please help me quickly as i need to implement this in my appplication.
Sean Clark
Rancher

Joined: Jul 15, 2009
Posts: 377

Well first are you clicking the link or submitting the form?

If you click the link then the actionSource value will not be sent to your servlet so of course you will get a number format exception as actionSource is null.

If you click the submit button then you will get a null pointer exception as the param value will not be sent to your servlet.

You need to rethink your solution as the way you are doing it, you can never send actionSource & param to the servlet at the same time.


Sean


I love this place!
rammie singh
Ranch Hand

Joined: Mar 26, 2009
Posts: 116
Hi sean..thanks for your valuable information.
Yaah you are right...i am clicking the link first and that is why actionSource is null.
But my application was earlier designed such that each page has a hidden variable with some no as it's value and
depending on this value fetched in servlet , the corresonding switch case is executed.

now this hyperlink part is on menu page and i want to access(go to respective clicked page ) this clicked hyperlink
through servlet and at the same time pass the actionSource value to servlet because actionSource hidden name is common on evry page and depending on this value only repective case is executed for the corresponding page.


Is there any way to achieve both. Please help me by suggesting the solutions.
Sean Clark
Rancher

Joined: Jul 15, 2009
Posts: 377

Well the simplest way would just be to add the actionSource to the link.



I don't know if that is suitable.

Even better would be to use the <c:url> tag in the core tag library.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: accessing clicked hyperlink value of jsp page in servlet