请教经验认识
我用strut在做注册页面时 出现
java.lang.IllegalStateException: getOutputStream() has already been called for this response如何解决 ?
action代码如下:
package com.yourcompany.struts.action;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import vo.User;
import com.yourcompany.struts.form.NewUserForm;
import dao.UserDao;
public class NewUserAction extends Action {
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
NewUserForm NewUserForm = (NewUserForm) form;// TODO Auto-generated method stub
String username=NewUserForm.getUsername();
String password=NewUserForm.getPassword();
String password2=NewUserForm.getPassword2();
String certCode=NewUserForm.getCertCode();
HttpSession session=request.getSession();
String sRand =(String)session.getAttribute("rand");
String result=null;
if(!sRand.equals(certCode)){
result="验证码错误";
request.setAttribute("result", result);
return new ActionForward("/newUser.jsp");
}
if(!password.equals(password2)){
result="密码不一致";
request.setAttribute("result", result);
return new ActionForward("/newUser.jsp");
}
User user=new User();
user.setUid(username);
user.setPassword(password);
UserDao userDao=new UserDao();
userDao.insertUser(user);
result = "注册成功";
request.setAttribute("result", result);
return new ActionForward("/login.jsp");
}
}
------解决方案--------------------参考 http://www.java2000.net/viewthread.jsp?tid=1201
------解决方案--------------------有验证码就是原因的所在,因为页面上的out与jsp本身的out冲突而引起的
在页面最后加入:
out.clear();
out = pageContext.pushBody();
即可解决问题