将URL从jsp传递到servlet

时间:2015-06-18 13:21:01

标签: jsp url servlets parameters

我有以下JSP代码:

<%
for (int i = 0; i < list.size(); i++) {
Entry var = (Entry) list.get(i);
//[...]
String Cn = var.getCn();
out.println(" <form method=\"get\" action=\"NewServlet\"> "+ "<input \
    type=\"submit\" name=\"act\" value=\" " + var.getCn() + " \" > " + "</form>");
out.println("<br>--------------------<br>");
}
%>

我想将参数var.getCn()发送到servlet,但我不知道如何从servlet中捕获它。我怎么能这样做?

//[....]
   String Cn = new String();
   Cn = request.getParameter("???");                
//[....]

1 个答案:

答案 0 :(得分:0)

public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    String foo = request.getParameter("foo");
    String bar = request.getParameter("bar");
    // Do something with foo & bar.

}

网址:

http://example.com/myservlet/?foo="hey"&bar="funny"

阅读more