站内搜索: 请输入搜索关键词

当前页面: 开发资料首页JSP 专题帮忙看看这个错误是怎么回事

帮忙看看这个错误是怎么回事

摘要: 帮忙看看这个错误是怎么回事


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);
}



res 是什么东西


代码有点少


好,我基本上知道你的问题出到哪啦。你的页面的其他部分,肯定还有类似response.sendRedirect()或标签之类,因为同时满足了条件服务器不知道究竟该转到哪儿,你仔细找找


不错,是还有其他的forword。
上面的条件不成立之后就forword,其他的forword还有作用吗???


package db;

import java.io.IOException;
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);

}
}



在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");
}

}中,你有没有看一下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);
}

恐怕也执行吧,你再仔细找找吧,肯定是这方面的错误,不了解你的业务



↑返回目录
前一篇: 刚学jsp,怎么感觉jsp读sqlserver的速度比asp读sqlserver慢点呢?高手指点下
后一篇: 简单问题