错误这样
HTTP Status 500 - --------------------------------------------------------------------------------type Exception reportmessage 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
StudentLoginSvlt.doError(StudentLoginSvlt.java:107)
StudentLoginSvlt.doEnrol(StudentLoginSvlt.java:69)
StudentLoginSvlt.doGet(StudentLoginSvlt.java:47)
javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)jsp中这样
<td><a href="StudentLoginSvlt?action=enrol&id=<%=id%>&cour_id=<%=cour_id%>&class_id=<%=class_id%>&prepare=<%=prepare%> ">注册</a> studentologinsvlt.java代码
import java.io.*;
import java.sql.ResultSet;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
import com.sqlBean;
import com.checkEnrol;
public class StudentLoginSvlt extends HttpServlet{
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
String stu_id =req.getParameter("id");
String cour_id=req.getParameter("cour_id");
String class_id=req.getParameter("class_id");
String prepare=req.getParameter("prepare");
String pw1=null;
String pw2=null;
String e_mail=null;
String tel=null;
String action = req.getParameter("action"); ResultSet rs=null; if ("update".equalsIgnoreCase(action)) { stu_id =req.getParameter("id");
pw1=req.getParameter("password1");
pw2=req.getParameter("password2");
if(pw1.equals("") || pw2.equals("") || pw1==null || pw2==null)
doError(req,res,"密码不能为空!");
e_mail=req.getParameter("e_mail");
tel=req.getParameter("tel");
doUpdate(req,res,pw1,pw2,e_mail,tel,stu_id);
res.sendRedirect("/test/student.jsp");
}
if ("check".equalsIgnoreCase(action)) {
rs=getScore(stu_id) ;
sendResultSet(req,res,rs,"/check.jsp");
}
if("enrol".equalsIgnoreCase(action)){
doEnrol(req,res,stu_id,cour_id,class_id,prepare);
//res.sendRedirect("/test/DisplayCourse.jsp");
} }
public void doEnrol(HttpServletRequest req, HttpServletResponse res,String stu_id,String cour_id,String class_id,String prepare) throws ServletException, IOException {
int num=0;
checkEnrol check=new checkEnrol();
if(prepare.equals("0") )
{ num= check.enrol(class_id,stu_id); }
else {
if( check.hasPassPrepare(prepare))
{num= check.enrol(class_id,stu_id);}
else doError(req,res,"清先完成预修课");
}
if(num==0){
doError(req,res,"注册课程失败!!");
}
}
public void doUpdate(HttpServletRequest req, HttpServletResponse res,
String pw1,String pw2,String e_mail,String tel,String id)
throws ServletException, IOException{
int num=0;
if(!pw1.equals(pw2))
doError(req,res,"密码不一致,请重输!");
checkEnrol check=new checkEnrol();
sqlBean db = new sqlBean();
num= check.updatestu(pw1,id,e_mail,tel);
if(num==0) doError(req,res,"更新失败");
}
public ResultSet getScore(String stu_id){
String sql="select enrol.score , course.name ,course. "+
"from enrol ,course ,classes "+
"where stu_id='"+stu_id+"' "+
"and enrol.class_id=classes.id "+
"and classes.cour_id=course.id ";
sqlBean db = new sqlBean();
ResultSet rs= db.executeQuery(sql);
return rs;
}
public void doError(HttpServletRequest req,
HttpServletResponse res,
String str)
throws ServletException, IOException {
req.setAttribute("problem", str);
RequestDispatcher rd = getServletContext().getRequestDispatcher("/errorpage.jsp");
rd.forward(req, res);
}
public void sendResultSet(HttpServletRequest req, HttpServletResponse res,
java.sql.ResultSet rs, String target)
throws ServletException, IOException {
req.setAttribute("rs", rs);
RequestDispatcher rd = getServletContext().getRequestDispatcher(target);
rd.forward(req, res);
return;
}
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException { doGet(req, res); }
}
HTTP Status 500 - --------------------------------------------------------------------------------type Exception reportmessage 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
StudentLoginSvlt.doError(StudentLoginSvlt.java:107)
StudentLoginSvlt.doEnrol(StudentLoginSvlt.java:69)
StudentLoginSvlt.doGet(StudentLoginSvlt.java:47)
javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)jsp中这样
<td><a href="StudentLoginSvlt?action=enrol&id=<%=id%>&cour_id=<%=cour_id%>&class_id=<%=class_id%>&prepare=<%=prepare%> ">注册</a> studentologinsvlt.java代码
import java.io.*;
import java.sql.ResultSet;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
import com.sqlBean;
import com.checkEnrol;
public class StudentLoginSvlt extends HttpServlet{
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
String stu_id =req.getParameter("id");
String cour_id=req.getParameter("cour_id");
String class_id=req.getParameter("class_id");
String prepare=req.getParameter("prepare");
String pw1=null;
String pw2=null;
String e_mail=null;
String tel=null;
String action = req.getParameter("action"); ResultSet rs=null; if ("update".equalsIgnoreCase(action)) { stu_id =req.getParameter("id");
pw1=req.getParameter("password1");
pw2=req.getParameter("password2");
if(pw1.equals("") || pw2.equals("") || pw1==null || pw2==null)
doError(req,res,"密码不能为空!");
e_mail=req.getParameter("e_mail");
tel=req.getParameter("tel");
doUpdate(req,res,pw1,pw2,e_mail,tel,stu_id);
res.sendRedirect("/test/student.jsp");
}
if ("check".equalsIgnoreCase(action)) {
rs=getScore(stu_id) ;
sendResultSet(req,res,rs,"/check.jsp");
}
if("enrol".equalsIgnoreCase(action)){
doEnrol(req,res,stu_id,cour_id,class_id,prepare);
//res.sendRedirect("/test/DisplayCourse.jsp");
} }
public void doEnrol(HttpServletRequest req, HttpServletResponse res,String stu_id,String cour_id,String class_id,String prepare) throws ServletException, IOException {
int num=0;
checkEnrol check=new checkEnrol();
if(prepare.equals("0") )
{ num= check.enrol(class_id,stu_id); }
else {
if( check.hasPassPrepare(prepare))
{num= check.enrol(class_id,stu_id);}
else doError(req,res,"清先完成预修课");
}
if(num==0){
doError(req,res,"注册课程失败!!");
}
}
public void doUpdate(HttpServletRequest req, HttpServletResponse res,
String pw1,String pw2,String e_mail,String tel,String id)
throws ServletException, IOException{
int num=0;
if(!pw1.equals(pw2))
doError(req,res,"密码不一致,请重输!");
checkEnrol check=new checkEnrol();
sqlBean db = new sqlBean();
num= check.updatestu(pw1,id,e_mail,tel);
if(num==0) doError(req,res,"更新失败");
}
public ResultSet getScore(String stu_id){
String sql="select enrol.score , course.name ,course. "+
"from enrol ,course ,classes "+
"where stu_id='"+stu_id+"' "+
"and enrol.class_id=classes.id "+
"and classes.cour_id=course.id ";
sqlBean db = new sqlBean();
ResultSet rs= db.executeQuery(sql);
return rs;
}
public void doError(HttpServletRequest req,
HttpServletResponse res,
String str)
throws ServletException, IOException {
req.setAttribute("problem", str);
RequestDispatcher rd = getServletContext().getRequestDispatcher("/errorpage.jsp");
rd.forward(req, res);
}
public void sendResultSet(HttpServletRequest req, HttpServletResponse res,
java.sql.ResultSet rs, String target)
throws ServletException, IOException {
req.setAttribute("rs", rs);
RequestDispatcher rd = getServletContext().getRequestDispatcher(target);
rd.forward(req, res);
return;
}
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException { doGet(req, res); }
}
解决方案 »
- ORA-00933: SQL 命令未正确结束,使用JDBC执行出错,但语句在PL/SQL中执行通过
- no session or session was closed
- 谁有freemarker 开发资料
- 关于session的问题,大家帮帮忙
- OutputStream output.write(b, 0, i); 用这个输出客户端,人多的时候, 服务器会死吗
- 请问在jsp中写的System.out.println("")输出放在哪里?
- 简单问题
- 怎样解决长时间登陆问题??高分求解!
- JSP小问题
- 弱弱的问下CSDN为什么不做些统计分析的功能?
- 这是个什么exception?
- 神啊 救救我 ssh(struts2)出错
return和sendRedirect 都执行了 重复提交