用java做好的登陆界面,当登陆成功后跳转到下个页面的代码是什么?

如题所述

用java做好的登陆界面,当登陆成功后跳转到下个页面的代码如下:
如果登陆验证是在jsp中,那么跳转可以写成
1.response.sendRedirct("跳转到页面");
2.<jsp:forward page="跳转页面"/>
3.response.setHeader("Location","");
如果是登陆验证是在servlet中,那么中转可以写成
1.response.sendRedirect("/a.jsp");
2.RequestDispatcher dispatcher = request.getRequestDispatcher("/a.jsp");
dispatcher .forward(request, response);
也可以使用js代码实现:
<script>
function validate(){
window.location.href="/index.jsp";
}
</script>
温馨提示:答案为网友推荐,仅供参考
第1个回答  2019-09-25
<form
action="写你要跳转的acting或者servlet"
method="post">
</form>
然后action或者servlet处理完之后再跳转到下一个页面
response.sendRedirct("跳转到的下一个页面");
第2个回答  2010-01-26
如果登陆验证是在jsp中,那么跳转可以写成
1.response.sendRedirct("跳转到页面");
2.<jsp:forward page="跳转页面"/>
3.response.setHeader("Location","");

如果是登陆验证是在servlet中,那么中转可以写成
1.response.sendRedirect("/a.jsp");
2.RequestDispatcher dispatcher = request.getRequestDispatcher("/a.jsp");
dispatcher .forward(request, response);本回答被网友采纳
第3个回答  2010-01-26
<form action="写你要跳转的acting或者servlet" method="post">
</form>

然后action或者servlet处理完之后再跳转到下一个页面
response.sendRedirct("跳转到的下一个页面");

参考资料:天高云淡(◆ノSimply)

第4个回答  2010-01-26
登录页面:login.html
<html>
<head>
<title>登录</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta http-equiv="Content-Language" content="ch-cn">
</head>
<body>
<!-- Form 用来提取用户填入并提交的信息-->
<form method="post" name="frmLogin" action="LoginServlet">
<h1 align="center">用户登录</h1><br>
<div align="center">用户名:
<input type="text" name="txtUserName" value="Your name"
size="20" maxlength="20"
onfocus="if(this.value=='Your name')this.value='';"><br>密码:
<input type="password" name="txtPassword" value="Your password"
size="20" maxlength="20"
onfocus="if(this.value=='Your password')this.value='';"><br>
<input type="submit" name="Submit" value="提交" onClick="validateLogin();" >
     
<input type="reset" name="Reset" value="重置"><br>
</div>
</form>
<!-- javaScript 函数 validateLogin(),用来验证用户名和密码是否为空 -->
<script language="javaScript">
function validateLogin()
{
var sUserName = document.frmLogin.txtUserName.value;
var sPassword = document.frmLogin.txtPassword.value;
if( sUserName=="" )
{
alert("请输入用户名!");
return false;
}
if( sPassword=="" )
{
alert("请输入密码!");
return false;
}
}
</script>
</body>
</html>

登录成功页面:login_success.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP 'login_success.jsp' starting page</title>
</head>
<body>
<%
String userName = (String)session.getAttribute ( "UserName" );
%>
<div align=center><%=userName%> 欢迎您,登录成功!</div>
</body>
</html>

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网