[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 347
  • Last Modified:

Passing parameters to a servlet from an html link

What is the code to pass a parameter to a servlet from a link in an html page.

Currently I have in my servlet a dynamically created link:

out.println("<ahref= \"http://localhost:80/servlets/sessionservlet?id= " + field0 +"\"> Add item to shopping cart </a><p>");

The 'id=value' is the parameter I would like to pass to the sessionservlet, however when I try to do:

String idbooktoadd = req.getParameter("id")

in the sessionservlet nothing is stored in the string variable 'idbooktoadd'

Please help

Thanks
0
help_me
Asked:
help_me
  • 2
1 Solution
 
Ravindra76Commented:

Hi help_me,

In HTML usage of double quotes is optional. Try with this code.


>> Your code

out.println("<ahref= \"http://localhost:80/servlets/sessionservlet?id=
                      " + field0 +"\"> Add item to shopping cart </a><p>");


>>>>>>>>

new code

out.println("<a href= http//localhost:80/servlets/sessionservlet?id=
                      " + field0 +"> Add item to shopping cart </a><p>");

Best of luck
0
 
Ravindra76Commented:
Hi help_me,

 some error in previous comment.

Try with this

out.println("<a href= http://localhost:80/servlets/sessionservlet?id="+
  field0 +"> Add item to shopping cart </a><p>");

Best of luck
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now