• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Passing value to a servlet through Hyperlink

 
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.
 
Sheriff
Posts: 67266
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • 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
Sheriff
Posts: 67266
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • 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.
 
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.
 
Marshal
Posts: 24594
55
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.
 
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!