jsp 登陆验证用户和密码,验证成功后跳转到主页面。
jsp登陆验证用户和密码,验证成功后跳转到主页面。我的思路是建一个web工程,然后设index.html,和login.jsp和main.jsp能不能帮我看下我的代码那里...
jsp 登陆验证用户和密码,验证成功后跳转到主页面。我的思路是建一个web工程,然后设index.html,和login.jsp和main.jsp能不能帮我看下我的代码那里出错了。谢谢。
index.html代码
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<body>
<table width="337" height="152" border="1">
<form method="post" action="Login.jsp">
<tr>
<td colspan="2" align="center">登陆首页</td>
</tr>
<tr>
<td width="147" align="center">用户名</td>
<td width="174"><input type="text" name="name"></td>
</tr>
<tr>
<td align="center">密码</td>
<td><input type="text" name="password"></td></td>
</tr>
<tr>
<td><input type="submit" value="登录" ></td>
<td><input type="submit" value="取消" ></td>
</tr>
</form>
</table>
</body>
</html>
login.jsp代码
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'Login.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
验证的页面
<%
if(request.getParameter("name").equals("aa123")
&&request.getParameter("password").equals("123"))
{
out.println("登陆成功");
}
else
{
out.println("用户名或密码输入错误!");
}
%>
<br>
</body>
</html>
main.jsp代码
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'main.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>看到就成功了 <br>
</body>
</html> 展开
index.html代码
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<body>
<table width="337" height="152" border="1">
<form method="post" action="Login.jsp">
<tr>
<td colspan="2" align="center">登陆首页</td>
</tr>
<tr>
<td width="147" align="center">用户名</td>
<td width="174"><input type="text" name="name"></td>
</tr>
<tr>
<td align="center">密码</td>
<td><input type="text" name="password"></td></td>
</tr>
<tr>
<td><input type="submit" value="登录" ></td>
<td><input type="submit" value="取消" ></td>
</tr>
</form>
</table>
</body>
</html>
login.jsp代码
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'Login.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
验证的页面
<%
if(request.getParameter("name").equals("aa123")
&&request.getParameter("password").equals("123"))
{
out.println("登陆成功");
}
else
{
out.println("用户名或密码输入错误!");
}
%>
<br>
</body>
</html>
main.jsp代码
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'main.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>看到就成功了 <br>
</body>
</html> 展开
3个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询