The server encountered an internal error () that prevented it from fulfilling this request.
java.lang.IllegalStateException: Cannot forward after response has been committed
=============================
if(name==null || name.equals("")) {
f=false;
message="用户名不能为空,请重新填写!";
req.setAttribute("bug", message);
RequestDispatcher rd = getServletContext().getRequestDispatcher("/errorpage.jsp");
rd.forward(req, res);
}
java.lang.IllegalStateException: Cannot forward after response has been committed
=============================
if(name==null || name.equals("")) {
f=false;
message="用户名不能为空,请重新填写!";
req.setAttribute("bug", message);
RequestDispatcher rd = getServletContext().getRequestDispatcher("/errorpage.jsp");
rd.forward(req, res);
}
解决方案 »
- tomcat占用cpu很高
- jsp问题 关于数据库连接
- hibernate,一个困扰,请高手帮忙想想办法
- 当 IDENTITY_INSERT 设置为 OFF 时,不能为表 'Putup' 中的标识列插入显式值。
- 请问在JSP中,如何取得一个特定的session
- 高度关注:提一个关于在OA中公文显示的分页问题(web页面),字数太长分页问题?
- 装了Jbuider8,存取jsp文件的时候出问题了!!
- 如何实现ID号的合法性检查
- 'hibernate.dialect' must be set when no Connection available
- tomcat不能访问8080报错500,jsp访问不到
- 关于上传文件更新数据库问题(急)
- 求教各位高手,Radio的问题!
上面的条件不成立之后就forword,其他的forword还有作用吗???
import java.sql.*;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;public class UserSvlt extends HttpServlet {
/**
*
*/
private static final long serialVersionUID = -4968662884010434009L;
String message="";
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
String user_id =req.getParameter("id");
int success = 0;
String action = action = req.getParameter("action");
User us = null;
if ("new".equalsIgnoreCase(action)) {
us = doNew(req,res);
sendBean(req, res, us, "/security/getuser.jsp");
}
if ("update".equalsIgnoreCase(action)) {
try{
us = doUpdate(req,res, user_id); sendBean(req,res,us,"/security/getuser.jsp");
}
catch(SQLException e){}
}
if ("delete".equalsIgnoreCase(action)) {
try{
success = doDelete(user_id);
}
catch(SQLException e){}
if (success != 1) {
doError(req, res, "UserSvlt: Delete unsuccessful. Rows affected: " + success);
} else {
res.sendRedirect("/security/getuser.jsp");
}
}
}
public User doNew(HttpServletRequest req,HttpServletResponse res )
throws ServletException,IOException{
User us = new User();
String user_id=req.getParameter("id");
String username=new String(req.getParameter("username").getBytes("ISO8859_1"));
String password= req.getParameter("password");
//数据库采用自动递增ID
//if(isTrue(req,res,user_id,username,password) && hasLogin(req,res,user_id)){
if(isTrue(req,res,user_id,username,password)){
us.setId(user_id);
us.setUsername(username);
us.setPassword(password);
us.addUser();
}
return us;
} public User doUpdate(HttpServletRequest req,HttpServletResponse res , String id)
throws ServletException,IOException,SQLException {
User us = new User();
String username=new String(req.getParameter("username").getBytes("ISO8859_1"));
String password = req.getParameter("password");
if(isTrue(req,res,id,username,password)){
us.setId(id);
us.setUsername(username);
us.setPassword(password);
us.updateUser();}
return us;
} public int doDelete(String id) throws SQLException {
int num=0;
User us = new User();
num=us.deleteUser(id);
return num;
}
public void sendBean(HttpServletRequest req, HttpServletResponse res,
User us, String target)
throws ServletException, IOException {
req.setAttribute("us", us);
res.sendRedirect(target);
//RequestDispatcher rd = getServletContext().getRequestDispatcher(target);
//rd.forward(req, res);
}
public void doError(HttpServletRequest req,
HttpServletResponse res,
String str)
throws ServletException, IOException {
req.setAttribute("problem", str);
res.sendRedirect("/security/errorpage.jsp");
// RequestDispatcher rd = getServletContext().getRequestDispatcher("/errorpage.jsp");
// rd.forward(req, res);
}
public boolean hasLogin(HttpServletRequest req, HttpServletResponse res,String id)
throws ServletException, IOException{
boolean f=true;
message="对不起,该用户编号已经被注册过了!";
User us= new User();
f= us.hasLogin(id);
if(f==false){
doError(req,res,message);
}
return f;
}
public boolean isTrue(HttpServletRequest req, HttpServletResponse res,
String id,String name,String password)
throws ServletException, IOException {
boolean f=true;
String message =""; /* if(id==null || id.equals("")) {
f=false;
message="错误,编号不能为空!";
doError(req,res,message); }*/
if(name==null || name.equals("")) {
f=false;
message="用户名不能为空,请重新填写!";
doError(req,res,message);
//req.setAttribute("problem", message);
//res.sendRedirect("/security/errorpage.jsp");
//RequestDispatcher rd = getServletContext().getRequestDispatcher("/errorpage.jsp");
//rd.forward(req, res);
}
if(password==null || password.equals("")) {
f=false;
message="密码不能为空,请重新填写!";
doError(req,res,message);
} return f;
}
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException { doGet(req, res); }
}
try{
success = doDelete(user_id);
}
catch(SQLException e){}
if (success != 1) {
doError(req, res, "UserSvlt: Delete unsuccessful. Rows affected: " + success);
} else {
res.sendRedirect("/security/getuser.jsp");
}
}中,你有没有看一下success 的值是几?
恐怕是0吧,而
if(name==null || name.equals("")) {
f=false;
message="用户名不能为空,请重新填写!";
doError(req,res,message);
//req.setAttribute("problem", message);
//res.sendRedirect("/security/errorpage.jsp");
//RequestDispatcher rd = getServletContext().getRequestDispatcher("/errorpage.jsp");
//rd.forward(req, res);
}
恐怕也执行吧,你再仔细找找吧,肯定是这方面的错误,不了解你的业务