URL*_*L87 5 java jsp servlets request
我有jsp页面(比方说source.jsp),表格如下:
<html>
<head>
<body>
<form action="Servlet123" method="POST">
// form fileds ...
</form>
</body>
</head>
</html>
Run Code Online (Sandbox Code Playgroud)
doPostservlet中所需的 -
@WebServlet("/Servlet123")
public class Servlet123 extends HttpServlet {
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
//use with requset...
}
}
Run Code Online (Sandbox Code Playgroud)
如何获取source.jsp向此servlet发送请求的页面(在本例中为 - )?请求/会话中是否有方法?
通过隐藏字段在请求中传递参数:
在你的jsp页面中:
<form action="Servlet123" method="post">
<input type="hidden" name="namePage" value="sourcePage" />
</form>
Run Code Online (Sandbox Code Playgroud)
在您的 servlet 中:
String namePage = request.getParameter("namePage");
Run Code Online (Sandbox Code Playgroud)