JAVA+JSP的作业题目:
Login.jsp页面: 用表单输入用户名和口令,如果正确(假设正确的用户名是sky, 正确的口令是ocean,),进入select.jsp, 如果错误,提示用户名或口令错误;
效果是当用户输入账号密码点击提交之后在当前的JSP页面实现验证,如果正确就跳转到指定的页面,错误则给出错误信息要求重新输入
<%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*" errorPage="" %>
<!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=utf-8" />
<title>无标题文档</title>
</head>
<body>
<form id="form1" name="form1" method="post" action="">
<p>
<label>用户名:
<input type="text" name="User" id="textfield" />
</label>
</p>
<p>
<label>密码:
<input type="password" name="Password" id="textfield2" />
</label>
</p>
<p>
<label>
<input type="submit" name="button" id="button" value="提交" />
</label>
<label>
<input type="reset" name="button2" id="button2" value="重置" />
</label>
</p>
</form>
<%
String name=request.getParameter("name");
String pw=request.getParameter("password");
if(name.equals("sky")&&pw.equals("ocean"))
{
session.setAttribute("name", name);
request.getRequestDispatcher("Select.jsp").forward(request, response);
}
else{
out.write("用户名或密码错误!");
out.println("<br><a href= Login.jsp>返回登录");
}
%>
</body>
</html>