首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

为何jsp不能跳转

2013-03-28 
为什么jsp不能跳转%@ page languagejava contentTypetext/html charsetutf-8pageEncodingutf-8

为什么jsp不能跳转
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!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=utf-8">
<title>Insert title here</title>
</head>
<body>
<%@ page language="java" contentType="text/html; charset=utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%@ page import="net.taobaoge.entity.*"%>
<%@ page import="net.taobaoge.dao.*"%>
<%@ page import="net.taobaoge.dao.impl.*"%>
<html>
<head>
<script type="text/javascript">
 function returnPage(){
 alert(123);
   window.location.href="register.jsp"; 
 }

</script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>doForm.jsp</title>
</head>
<body>

<%
request.setCharacterEncoding("UTF-8");
String userName = request.getParameter("userName");
String password = request.getParameter("password");
String sex = request.getParameter("sex");
String habby1 = request.getParameter("checkbox1");
String habby2 = request.getParameter("checkbox2");
String habby3 = request.getParameter("checkbox3");
String address = request.getParameter("addressList");
String resume = request.getParameter("resume");

InformationDAO dao = new InformationDAOImpl();

Information entity = new Information(userName, password, sex,
habby1, habby2, habby3, address, resume);

boolean flg = dao.hasRegister(entity);

if (!flg) {

//这里我需要实现弹出对话框,并跳转页面,但是现在无法弹出对话框,
//如果把下面的request.getRequestDispatcher(),去掉就可以出来对话框,这是为什么?如何解决!!!!
String outt = "<script type="text/javascript">alert("用户名已经被注册过,请重新注册!");</script>";
out.println(outt);
request.getRequestDispatcher("register.jsp").forward(request,
response);
} else {
dao.insertOneMsg(entity);

String outt = "<script type="text/javascript">alert("注册成功");</script>";
out.println(outt);
request.getRequestDispatcher("register.jsp").forward(request,
response);

}
%>


</body>
</html>
[解决办法]
out.println(outt);
request.getRequestDispatcher("register.jsp").forward(request,
response);

后面加上return;
[解决办法]
out.println 之后就不能再转发请求了。
[解决办法]
试试response.setHeader("refresh", "2;url=");
url后面自己填. 2代表2秒跳转
[解决办法]
在Servlet中有倆中跳转
啊 你在这用了重定向 所以弹不出提示框!

热点排行