81,092
社区成员
发帖
与我相关
我的任务
分享
<%@page import="java.sql.*" import="java.util.*"
import="java.io.*,com.function" import="java.text.*"
contentType="text/html;charset=gb2312" buffer="20kb"%>
<jsp:useBean id="req" class="com.Sqlselect" scope="page" />
<%
String action = request.getParameter("action");
if (action == null)
action = "";
if (action.equals("loginout")) {
session.setAttribute("login", "no");
}
if (!action.equals("login")) {
%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>登陆</title>
</head>
<body>
<form id="form1" name="login" method="post" action="login.jsp">
<p> </p>
<p> </p>
<p> </p>
<table width="280" border="1" align="center">
<tr>
<td colspan="2"><div align="center">用户登陆</div></td>
</tr>
<tr>
<td width="78">用户名:</td>
<td width="186"><label>
<input type="text" name="username"/>
</label></td>
</tr>
<tr>
<td> 密码:</td>
<td><label>
<input type="text" name="userPwd" />
</label></td>
</tr>
<input type="hidden" name="action" value="login" />
<tr>
<td><label>
<input type="submit" name="Submit" value="提交" />
</label></td>
<td><label>
<input type="reset" name="Submit2" value="重置" />
</label></td>
</tr>
</table>
</form>
</body>
</html>
<%
} else {
try {
String username = request.getParameter("username");
String userpasswd = request.getParameter("userPwd");
String sql = "select * from user where u_name='"
+ username + "'";
ResultSet info = req.executeQuery(sql);
info.next();
if (!userpasswd.equals(info.getString("u_passwd"))) {
out
.println("<script language=\"javascript\">alert(\"用户名或密码不正确...\");</script>");//密码不正确为了安全期间,都提示用户名密码不正确
out.println(" <script language='javascript'>");
out.println("location='./login.jsp'; </script>");
} else {
session.setAttribute("login", "ok");//使用session对像将登陆信息存入
out.println(" <script language='javascript'>");
out.println("location='./index.jsp?'; </script>");
}
} catch (Exception e) {
out
.println("<script language=\"javascript\">alert(\"用户名或密码不正确...\");</script>");//用户名不正确为了安全期间,都提示用户名密码不正确
out.println(" <script language='javascript'>");
out.println("location='./index.jsp'; </script>");
}
}
%>
首页代码:(首页现在什么都没写,主要用来测试显示用户名)
<%@ page language="java" contentType="text/html; charset=gb2312"
pageEncoding="gb2312"%>
<!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=gb2312">
<title>首页</title>
</head>
<body>
<%
String name="";
name=(String)session.getAttribute("username");
%>
<p>欢迎你,<%=name %></p>
</body>
</html>
大家帮我修改修改,谢谢了