jsp Cannot forward after response has been committed问题,String username = request.getParameter("username");String password = request.getParameter("password");String confirmPassword = request.getParameter("confirmPassword");String sql = "select use

来源:学生作业帮助网 编辑:作业帮 时间:2024/11/23 14:59:30
jsp Cannot forward after response has been committed问题,String username = request.getParameter(
xV]sF+[?IA#1!tNd{mʒ"M)Ì!P;q&@!!($FwRPmLNH8{=fX;0LL{JH͹F6v,p0:(2f.W҄kkFlj3YĎ+{Ya %F.8S&Kl%c9.\>s}gRuq豴$NBDl$ QB@ln;(}j0I//b6˛(BL+{$N4W0yIs\ydugi񮢤j@k@7_ˆJd0M2ا+gt(Qȸ2`La1 e r'\5B>bd@ar14@(ªeGEڹsmTwVVEYZf6E b (svqAtBG㔔-oJk]or]u9#f f^3d8O)Q3u8]aԈ| 5y C=)_U _Kbj(A;?n~oqcvVVX; ]3q8IR'w]X(?ez&t9mi{k}{%֖V?[w%2Dm?x1ed$|!֞ߙ¢D^|nHI*GdC!'_ZoR٠w@= `/uEx."EZ7ldΕ";+L6Ycy^%/` 7O>$ez̾ *dcwG[rP]d=aDh&rЂqT߮2iVrՀ"eS 2 Hq r_Q. t{olm]OIGF{P}'Bʢؤ{-R)˟97\q{{/Xͤ4RC71/hC@8tbʷ

jsp Cannot forward after response has been committed问题,String username = request.getParameter("username");String password = request.getParameter("password");String confirmPassword = request.getParameter("confirmPassword");String sql = "select use
jsp Cannot forward after response has been committed问题,
String username = request.getParameter("username");
String password = request.getParameter("password");
String confirmPassword = request.getParameter("confirmPassword");
String sql = "select username,password from users ";
QueryRunner qr = DbHelper.getQueryRunner();//工具类,数据库肯定没问题
List list = null;
User user = null;//bean类
try {
list = (List) qr.query(sql,new BeanListHandler(User.class));
} catch (Exception e) {
e.printStackTrace();
}
if (password.equals(confirmPassword)) {
for (int i = 0; i < list.size(); i++) {
user = (User) list.get(i);
if (user.getUsername().equals(username)) {
request.setAttribute("message","用户名已经被注册!");
request.getRequestDispatcher("/admin/login.jsp").forward(
request,response);
}else {
sql = "insert into users(username,password) values(?,)";
String params[] = { username,password };
qr = DbHelper.getQueryRunner();
try {
qr.update(sql,params);
} catch (SQLException e) {
e.printStackTrace();
}
request.setAttribute("message","注册成功!");
request.getRequestDispatcher("/admin/login.jsp").forward(request,
response);
}
}
}
else {
request.setAttribute("message","两次密码不一样,请重新输入");
request.getRequestDispatcher("/admin/reg.jsp").forward(request,
response);
}

jsp Cannot forward after response has been committed问题,String username = request.getParameter("username");String password = request.getParameter("password");String confirmPassword = request.getParameter("confirmPassword");String sql = "select use
/**
1.对于转发,只能转发一次,否则抛出异常.
2.你的判断重名的逻辑有问题,你的逻辑是与list里面所有名字比较,只要不相同就入库并转发.
这将导致入库很多次,转发了很多次.而转发多次将抛出异常
正确的逻辑是应该先遍历完list,才能确定是否用户重名,最后转发一次.
3.判断逻辑有问题,应该先遍历完list,才能确定是否用户重名,一旦重名转发,并return结束
**/
//下面的代码是我修改的部分.
if (password.equals(confirmPassword)) {
for (int i = 0; i < list.size(); i++) {
user = (User) list.get(i);
if (user.getUsername().equals(username)) {
request.setAttribute("message","用户名已经被注册!");
request.getRequestDispatcher("/admin/login.jsp").forward(
request,response);
return;//必须判断完整个list列表才能确定是否重名.
}
}
sql = "insert into users(username,password) values(?,)";
String params[] = { username,password };
qr = DbHelper.getQueryRunner();
try {
qr.update(sql,params);
} catch (SQLException e) {
e.printStackTrace();
}
request.setAttribute("message","注册成功!");
request.getRequestDispatcher("/admin/login.jsp").forward(request,
response);
}
else {
request.setAttribute("message","两次密码不一样,请重新输入");
request.getRequestDispatcher("/admin/reg.jsp").forward(request,
response);
}
}