jsp不能跳转的问题

qq_24906675 2015-10-25 04:05:37
信息: Server startup in 3236 ms
Cannot call sendRedirect() after the response has been committed

希望修改解决
源代码如下:
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link href="css/mycss.css" rel="stylesheet" type="text/css">
<title>家教桥登录</title>
</head>

<body bgim background="images/wangji.jpgsfs">
<br><br><br><br><br><br><br><br><br><br><br><br><br>

<form name="form1" method="post" action="checkLogin.jsp" onSubmit="return check();">
<table width="315" height="101" border="1" align="center" cellpadding="3" cellspacing="0" bordercolor="#33FF66" bgcolor="#6699FF">
<tr>
<td width="105" height="33"><div align="right">用户名:</div></td>
<td width="189"><input name="user" type="text" id="userID" size="20" maxlength="30"></td>
</tr>
<tr>
<td height="33"><div align="right">登录密码:</div></td>
<td><input name="mima" type="password" id="pwd" size="20" maxlength="20"></td>
</tr>
<tr>
<td colspan="2">
<div align="center">
<input type="submit" name="Submit" value=" 登 录 ">
</div></td>
</tr>
</table>

</form>
<table width="315" height="101" border="1" align="center" cellpadding="3" cellspacing="0" bordercolor="#33FF66" bgcolor="#6699FF">

<form name="form3" method="post" action="zhuce.jsp" >
<tr>
<td colspan="2">
<div align="center">
<input type="submit" name="zhuce" value="注册 ">
</div></td>
</tr>
</form>
<form name="form4" method="post" action="wangji.jsp" >
<tr>
<td colspan="2">
<div align="center">
<input type="submit" name="wangji" value="忘记密码">
</div></td>
</tr>
</form>
</table>
</body>
</html>
<script language="javascript">
function check()
{
if(form1.userID.value=="")
{
alert("请输入用户名");
form1.userID.focus();
return false;
}
if(form1.pwd.value=="")
{
alert("请输入登录密码");
form1.pwd.focus();
return false;
}
return true;
}
</script>
这是输入登陆的,checkloginruxia
<%@ page contentType="text/html; charset=GBK" import="java.sql.*" %>
<jsp:useBean id="con1" class="jiajiaoqiao.shujuku" scope="page" />
<%
if(session.getAttribute("user")== null || session.getAttribute("mima").equals(""))
{
response.sendRedirect("index.jsp");
}
%>
<%

try{

Connection conn=con1.getcon();
Statement stmt = conn.createStatement();
String sql = "select * from jiazhang1 where user='" + request.getParameter("user") + "' and mima='" + request.getParameter("mima") + "'";

ResultSet rs = stmt.executeQuery(sql);
if(rs.next())
{
session.setAttribute("user",request.getParameter("user"));
session.setAttribute("mima",request.getParameter("mima"));
session.setAttribute("type","jiazhang");
response.sendRedirect("Center.jsp");
conn.close();
return;
}

else{
String sql1= "select * from jiajiao where user='" + request.getParameter("user") + "' and mima='" + request.getParameter("mima") + "'";
Statement stmt1 = conn.createStatement();
ResultSet rs1 = stmt.executeQuery(sql1);
if(!rs.next()&&rs1.next())
{
session.setAttribute("user",request.getParameter("user"));
session.setAttribute("mima",request.getParameter("mima"));
session.setAttribute("type","jiajiao");
response.sendRedirect("Center.jsp");
conn.close();
return;
}
else
{
%>
<script language="javascript">
alert("用户名或密码错误");

window.history.go(-1);
conn.close();
</script>
<%
return;
}}
}catch(Exception e)
{ %><script language="javascript">
alert("非法操作");
window.history.go(-1);
conn.close();
</script>
<%
System.out.println(e.getMessage());

}


如果成功还有悬赏



%>
请大家看看原因是什么,
...全文
65 点赞 收藏 3
写回复
3 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
街头小贩 2015-10-25

<%
if(session.getAttribute("user")== null || session.getAttribute("mima").equals("")){
  response.sendRedirect("index.jsp");

}
%>

改用 forward试试
回复
qq_24906675 2015-10-25
怎么了?这个是为了防止攻击啊,确保不能直接访问这个页面
回复
slwsss 2015-10-25
<% if(session.getAttribute("user")== null || session.getAttribute("mima").equals("")) { response.sendRedirect("index.jsp"); return; } %>
回复
相关推荐
发帖
Web 开发
创建于2007-09-28

8.0w+

社区成员

Java Web 开发
申请成为版主
帖子事件
创建了帖子
2015-10-25 04:05
社区公告
暂无公告