文档介绍:题一源代码:
登录:
<html>
<head>
<title> 登录</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<form action = "" name="myForm" method="post">
<table>
<tr>
<td>用户名:</td>
<td><input type ="text" name="userName"/></td>
</tr>
<tr>
<td>密码:</td>
<td><input type="password" name="pwd"/></td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" value="登录"/>
</td>
</tr>
</table>
</form>
</body>
</html>
登录处理:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML Transitional//EN" "/html4/">
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head><body>
<%
//获取登录表单提交的用户名和密码,判断是否正确(涉及到数据库操作),如果正确,转向网站首页
String username = ("userName");
String pwd = ("pwd");
if(("tom")&&("123")){
%>
<jsp:forward page=""/>
<%
}else{
%>
<jsp:forward page=""/>
<%
}
%>
</body></html>
登录失败:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML Transitional//EN" "/html4/">
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head><body>
出错了,请重新<a href="">登录</a>
</body