2015-06-18 96 views
0

我有以下的JSP代碼:從JSP傳遞的網址與Servlet

<% 
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("???");     
//[....] 

回答

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