wood burning stoves 2.0*
The moose likes Servlets and the fly likes passing  parameter from jsp to servlet  Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "passing  parameter from jsp to servlet  " Watch "passing  parameter from jsp to servlet  " New topic
Author

passing parameter from jsp to servlet

Pandurang Shenoy
Greenhorn

Joined: Mar 31, 2003
Posts: 10
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

Joined: Sep 11, 2000
Posts: 94
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

Joined: Oct 31, 2000
Posts: 160
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


Rgds<p>--Siva Jagadeesan<br /><a href="http://java2simple.blog-city.com" target="_blank" rel="nofollow">http://java2simple.blog-city.com</a><br />Sun Certified Java2 Programmer<br />Sun Certified Web Component Developer<br />BEA Certified Weblogic Server 7 Enterprise Developer
Fisher Daniel
Ranch Hand

Joined: Sep 14, 2001
Posts: 582
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

Joined: Sep 11, 2000
Posts: 94
one small change
<a href=<%=Stringwhichholdstheservletanddata%> >Go to server</a>
Pandurang Shenoy
Greenhorn

Joined: Mar 31, 2003
Posts: 10
Thanks to all for your answers
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: passing parameter from jsp to servlet
 
Similar Threads
JSP Page Translation + Tomcat
Accessing HttpRequest Parameteres in ActionForm
Communicate between JSP and Servlet
Passing JSP parameters to Java Method
Servlet - doGet - doPost - parameter