我对两个不同的表单数据使用相同的 dpPost 方法。我无法访问第二个表单的请求参数。
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
if("schema".equals(session.getAttribute("which"))) {
second_html();
//call second page here
}
String btnClicked= request.getParameter("p2"); // This is getting null after submitting second_html()
if("edit".equals(session.getAttribute("which"))){
/* process second page here after Submit on the second page
I am trying to access request.getParameter() but value is null here for the fields in the second page */
second_html();
}
}
first_html() {
// have form and submit button
session.setAttribute("which","schema");
}
second_html() {
// have form and submit button
<input type='text' name='p2' id='p2' size='3' >
session.setAttribute("which","edit");
}
编辑:我的 session getter 工作正常。但 request.getParameter 不起作用。
最佳答案
您正在访问 session 变量,而不是请求参数。
您可以使用
访问它们request.getParameter("which")
关于java - 无法访问 java servlet 中的请求参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24906172/