首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

请问经验认识

2011-12-31 
请教经验认识我用strut在做注册页面时出现java.lang.IllegalStateException: getOutputStream() has alrea

请教经验认识
我用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();
即可解决问题

热点排行