• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Passing value to a servlet through Hyperlink

 
Anam Zahra
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65216
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
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
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
Posts: 40
IBM DB2 Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 196
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic