我有 jsp 页面(例如,source.jsp
),其形式为:
<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 发送请求? request/session中有方法吗?
最佳答案
通过隐藏字段在请求中使用传递参数:
在你的jsp页面中:
<form action="Servlet123" method="post">
<input type="hidden" name="namePage" value="sourcePage" />
</form>
在您的 servlet 中:
String namePage = request.getParameter("namePage");
关于java - Reveal/know/get 发送页面使用servlet中的request或session,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11830038/