How can I send data via
<a href="#">link<a/>
to my servlet so that it executes my
protected void doGet()
method?
I want to do something like:
<a href="article?todo=show_article&article_id=23">link<a/>
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Just let the link point to an URL which matches the URL pattern of the servlet as configured in
web.xmlor by@WebServletannotation. The example link as you have expects the servlet to be mapped on an URL pattern of/article. ItsdoGet()method (if properly@Overriden) will then be called. The request parameters will then be available the usual way byrequest.getParameter().With the link example as you’ve given, the JSP page containing the link should by itself however be located in the root folder of the web content or forwarded by a request URL whose base is the context root. Otherwise you need to make the link URL domain-relative by prefixing the URL with
${pageContext.request.contextPath}like so:(please note that you’ve a syntax error in closing tag, I’ve fixed it in above example)
See also: