请大家给出意见或建议。谢谢!
jdk版本:1.4.2
tomcat版本:5.0
MySQL版本:5.0
一共三个文件:index.jsp,login.jsp,LinkBean.java
数据库名:ziyuan
表名:zyd_user
字段:usercode,username,password
<!-- [if gte mso 9]><![endif]--><!-- [if gte mso 9]><![endif]--><!-- /* Font Definitions */ @font-face{font-family:宋体;panose-1:2 1 6 0 3 1 1 1 1 1;mso-font-alt:SimSun;mso-font-charset:134;mso-generic-font-family:auto;mso-font-pitch:variable;mso-font-signature:3 135135232 16 0 262145 0;}@font-face{font-family:"Cambria Math";panose-1:2 4 5 3 5 4 6 3 2 4;mso-font-charset:0;mso-generic-font-family:roman;mso-font-pitch:variable;mso-font-signature:-1610611985 1107304683 0 0 159 0;}@font-face{font-family:Calibri;panose-1:2 15 5 2 2 2 4 3 2 4;mso-font-charset:0;mso-generic-font-family:swiss;mso-font-pitch:variable;mso-font-signature:-1610611985 1073750139 0 0 159 0;}@font-face{font-family:"/@宋体";panose-1:2 1 6 0 3 1 1 1 1 1;mso-font-charset:134;mso-generic-font-family:auto;mso-font-pitch:variable;mso-font-signature:3 135135232 16 0 262145 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal{mso-style-unhide:no;mso-style-qformat:yes;mso-style-parent:"";margin:0cm;margin-bottom:.0001pt;text-align:justify;text-justify:inter-ideograph;mso-pagination:none;font-size:10.5pt;mso-bidi-font-size:11.0pt;font-family:"Calibri","sans-serif";mso-fareast-font-family:宋体;mso-bidi-font-family:"Times New Roman";mso-font-kerning:1.0pt;}.MsoChpDefault{mso-style-type:export-only;mso-default-props:yes;font-size:10.0pt;mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt;mso-ascii-font-family:Calibri;mso-fareast-font-family:宋体;mso-hansi-font-family:Calibri;mso-font-kerning:0pt;} /* Page Definitions */ @page{mso-page-border-surround-header:no;mso-page-border-surround-footer:no;}@page Section1{size:612.0pt 792.0pt;margin:72.0pt 90.0pt 72.0pt 90.0pt;mso-header-margin:36.0pt;mso-footer-margin:36.0pt;mso-paper-source:0;}div.Section1{page:Section1;}--><!-- [if gte mso 10]><![endif]-->
Index.jsp
<%
response.sendRedirect("login.jsp");
%>
Login.jsp
<%@page contentType="text/html;charset=gb2312"import="java.sql.*" language="java"%>
<%@page import="util.login.logon.LinkBean"%>
<html>
<head>
<title>登陆!</title>
</head>
<body>
<form method="post">
<table border="0"width="898">
<tr>
<tdwidth="890" align="left" colspan="2">
<b> <fontsize="5">开始登陆!!! </font> </b>
<hr>
</td>
</tr>
<tr>
<td width="75"align="center">
<palign="right">
账号:
</p>
</td>
<td width="809"align="center">
<palign="left">
<inputtype="text" name="memberid" size="20">
</td>
</tr>
<tr>
<td width="75"align="center">
<palign="right">
密码:
</p>
</td>
<tdwidth="809" align="center">
<palign="left">
<inputtype="password" name="memberpwd" size="20">
<inputtype="submit" value="登陆"name="loginButton">
</td>
</tr>
</table>
<jsp:useBean id="Link"scope="page" class="util.login.logon.LinkBean" />
<%
String code =request.getParameter("memberid");
String pass =request.getParameter("memberpwd");
ResultSet rs = null;
Connection conn = null;
boolean flag=false;
if (code != null &&pass != null) {
String sql = "select *from zyd_user where usercode='" + code + "' and password='" +pass + "'";
conn = Link.connectdb();
rs =Link.executeQuery(sql);
if (rs.next()) {
flag = true;
}
if (flag)
{
//合法用户
response.sendRedirect("main.jsp");
}
else
{
//非法用户
response.sendRedirect("login_failure.jsp");
}
}
%>
</form>
</body>
</html>
LinkBean.java
packageutil.login.logon;
importjava.sql.*;
importjava.lang.*;
publicclass LinkBean
{
StringsDBDriver="org.gjt.mm.mysql.Driver";
private Stringurl="jdbc:mysql://localhost:3306/ziyuan";
String user="root"; //root为用户名称,12345为密码
String password="12345";
private Connection conn=null;
private Statement stmt=null;
ResultSet rs=null;
public LinkBean()
{
}
public Connection connectdb()
{
try
{
// Class.forName(sDBDriver).newInstance();
Class.forName(sDBDriver);
}
catch(java.lang.ClassNotFoundException e)
// catch (Exception e)
{
System.err.println("conectdb(): " + e.getMessage());
// e.printStackTrace();
// System.out.println(e.toString());
}
return conn;
}
public ResultSet executeQuery(String sqls)
{
rs=null;
try
{
conn=DriverManager.getConnection(url,user,password);
stmt=conn.createStatement();
rs=stmt.executeQuery(sqls);
}
catch(Exception ex)
{
System.err.println("aq.executeQuery: " + ex.getMessage());
// e.printStackTrace();
// System.err.println("aq.executeQuery: " + ex.getMessage());
}
return rs;
}
public void executeUpdate(String sql)
{
stmt=null;
rs=null;
try
{
conn=DriverManager.getConnection(url,user,password);
stmt=conn.createStatement();
stmt.executeUpdate(sql);
stmt.close();
conn.close();
}
catch(SQLException ex)
{
System.err.println("aq.executeQuery: " + ex.getMessage());
}
}
public void closeStmt()
{
try
{
stmt.close();
}
catch(SQLException e)
{
e.printStackTrace();
}
}
public void closeConn()
{
try
{
conn.close();
}
catch(SQLException e)
{
e.printStackTrace();
}
}
}