当我尝试验证请求参数时,Tomcat 向我显示错误 500。
堆栈跟踪:
HTTP Status 500 - Cannot forward after response has been
type Exception
message Cannot forward after response has been
description The server encountered an internal error that prevented it from
fulfilling this request. exception
java.lang.IllegalStateException: Cannot forward after response has been committed
这是我的 servlet 的一部分(没有 PrintWriter.flash 或类似的东西)。
此代码位于 servlet 的开头。为什么我会收到IllegalArgumentException
“已经提交”的回复?
String login = req.getParameter("login");
String password = req.getParameter("password");
if (login.length() == 0 || password.length() == 0) {
req.setAttribute("wrong", "Your login or password is empty");
RequestDispatcher rd = req.getRequestDispatcher("jsp/index.jsp");
rd.forward(req, resp);
}