Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

passing parameter from jsp to servlet

 
Pandurang Shenoy
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a jsp page(test.jsp) and a servlet.
I have provided link in test.jsp........So,when I click on that link,it invokes the servlet and I need to pass a parameter (say a string) to the invoked Servlet...How can I do this...?Please help
 
Sarada Bhasker
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
create the link href value dynamically and append the string value which you want to pass. Then you can read it using request.getparameter() in the servlet.
 
Siva Jagadeesan
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Append the query String in the link to the Servlet like this
HelloWorldServlet?name=Siva
In the Servlet the name=Siva will be appear as Request parameter.
request.getParameter("name") will return "Siva" as a String
 
Fisher Daniel
Ranch Hand
Posts: 582
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is the code in test.jsp
...
<a href="MyServlet?data=MyData">Go to server</a>
...
and the servlet class :
public class MyServlet extends HttpServlet
{
public void doGet(HttpServletRequest req, HttpServletResponse res) {
String data = req.getParameter("data");
}
}
Hope this help
correct me if i am wrong
daniel
 
Sarada Bhasker
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
one small change
<a href=<%=Stringwhichholdstheservletanddata%> >Go to server</a>
 
Pandurang Shenoy
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks to all for your answers
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic