I have jsp page -傳遞值使用<a href>
<html>
<head>
</head>
<body>
<%
String valueToPass = "Hello" ;
%>
<a href="goToServlet...">Go to servlet</a>
</body>
</html>
And servlet -
@WebServlet(name="/servlet123",
urlPatterns={"/servlet123"})
public class servlet123 extends HttpServlet {
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
}
public void foo() {
}
}
What should I write in <a href="goToServlet...">Go to servlet</a>
in order to pass values (like valueToPass
or maybe add the value as argument in the ) to the servlet123
?
Can I invoke specific method in servlet123
(like foo()
) using the link in the jsp ?
EDIT:
How can I call servlet in URL ? My pages hierarchy is like the follow -
WebContent
|-- JSPtest
| |-- callServletFromLink.jsp
|-- WEB-INF
: :
And I want to call the servlet123
in the folder src->control .
I tried <a href="servlet123">Go to servlet</a>
but it not find the servlet when I press on the link .
2nd EDIT:
I tried <a href="http://localhost:8080/MyProjectName/servlet123">Go to servlet</a>
and it work .
謝謝,所以如果我使用像「goToServlet?param1 = value1&param2 = value2」這樣的使用URL,將會調用servlet中的哪個方法? doGet? – URL87 2012-08-07 07:10:33
您應該使用doGet。看看這個答案:http://stackoverflow.com/a/2349741/980472 – jddsantaella 2012-08-07 07:17:34
好的。最後Q,看我編輯的帖子。 – URL87 2012-08-07 07:25:03