我对两种不同的表单数据使用相同的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");
}
编辑:我的会话getter工作正常。但是request.getParameter无效。
答案 0 :(得分:2)
您正在访问会话变量,而不是您的请求参数。
您可以使用
访问它们request.getParameter("which")
答案 1 :(得分:2)
如果我理解您的问题,您应该使用ServletRequest.getParameter(String)
,
String v = request.getParameter("which");
if (v.equals("schema")) {
} else if (v.equals("edit")) {
}