2012-08-06 30 views
5

請求或會話我有jsp頁面(比如,source.jsp)與形式得到發送頁面:顯示/知道/使用的servlet

<html> 
<head> 
<body> 
    <form action="Servlet123" method="POST"> 
     // form fileds ... 
    </form> 
</body> 
</head> 
</html> 

而在Servlet中需要doPost -

@WebServlet("/Servlet123") 
public class Servlet123 extends HttpServlet { 
    protected void doPost(HttpServletRequest request, 
      HttpServletResponse response) throws ServletException, IOException { 

      //use with requset... 
    } 
} 

我怎樣才能得到頁面(在這種情況下 - source.jsp)發送請求到這個servlet?請求/會話中是否有方法?

回答

4

使用傳遞參數的請求通過一個隱藏字段:

在JSP頁面:

<form action="Servlet123" method="post">   
    <input type="hidden" name="namePage" value="sourcePage" /> 
</form> 

在你的servlet:

String namePage = request.getParameter("namePage");