File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Passing value to a servlet through Hyperlink Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Passing value to a servlet through Hyperlink" Watch "Passing value to a servlet through Hyperlink" New topic
Author

Passing value to a servlet through Hyperlink

Anam Zahra
Greenhorn

Joined: Jan 12, 2009
Posts: 4
I want to pass value from hyperlink to the servlet. But servlet is unable to recieve the value. Code in servlet is something like that
---------servlet code---------


Jsp page code is something like that
<a href="files/check.jsp?value=MyName">Image</a>

Here check.jsp file calling the servlet which shows some other information with image


I dont know why the servlet is unable to recieve the value? But when I pass value through session then servlet receive the value. However I cannot set the session for each hyperlink. If I am doing something wrong then please correct me.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61191
    
  66

Your link references a JSP, not a servlet. If you're not activating a servlet, it can't very well receive any values, can it?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61191
    
  66

OK, I see that you changed your post after you posted it. Please do not do that -- it makes the time I spent answering the un-changed post a waste of time.
ronney singh
Ranch Hand

Joined: Feb 10, 2012
Posts: 40

Hafiz ehsan wrote:I want to pass value from hyperlink to the servlet.

You are not actually passing value to servlet instead your link refer to jsp page.


Live Life King Size
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18564
    
    8

Hafiz ehsan wrote:Here check.jsp file calling the servlet which shows some other information with image


I dont know why the servlet is unable to recieve the value? But when I pass value through session then servlet receive the value. However I cannot set the session for each hyperlink. If I am doing something wrong then please correct me.


Did you imagine that the "C" inside the string literal at line of that posted code would have some relation with the variable "C" which you declared and initialized at line 2?
Anam Zahra
Greenhorn

Joined: Jan 12, 2009
Posts: 4
Ok I make my query clear.I have one JSP page say admin.jsp on which a hyperlink is available to get another check.jsp page which access the servlet. Servlet is used to retrieve the image from database.
---------------------------------------------------
admin.jsp code is something like that

<a href="files/check.jsp?value=MyImage">
---------------------------------------------------
check.jsp code is like that

String C=request.getParameter("value");

<form method="post" action="/servlet/DBImage?paramtr=\'"+C+"\'">
---------------------------------------------------
DBImage.java code

String C=request.getParameter("paramtr");
--------------------------------------------------
When I click on hyperlink in admin.jsp to get check.jsp page. Then String C in servlet shows null.
Piyush Mangal
Ranch Hand

Joined: Jan 22, 2007
Posts: 196
Hafiz ehsan wrote:
check.jsp code is like that

String C=request.getParameter("value");

<form method="post" action="/servlet/DBImage?paramtr=\'"+C+"\'">


Could you please post the complete jsp code for check.jsp? The action url does not seem to be looking correct to me.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Passing value to a servlet through Hyperlink