这是登录页面代码:
<html>
<head>
<title>
用户登陆界面
</title>
</head>
<body>
<form Method="post" action="check.jsp">
<table width="600" border="1" bordercolor="#00FFFF" align="center" cellpadding="0" cellspacing="0">
<tr>
<th colspan="2" bgcolor="#00FFFF"> </th>
</tr>
<tr>
<th height="37" colspan="2" align="center"><font size="5">请输入你的用户名和密码</font></th>
</tr>
<tr>
<th width="35%" height="32" align="right" scope="row"><font size="5">账号:</font></th>
<td align="left"><input type="text" size="30" name="adminName" id="adminName"></td>
</tr>
<tr>
<th width="35%" height="33" align="right" scope="row"><font size="5">密码:</font></th>
<td align="left"><input type="password" size="33" name="password" id="password"></td>
</tr>
<tr>
<td height="35" align="right"> </td>
<td align="left"><input type="reset" value="重置" name="reset"> <input type="submit" value="提交" name="submit"></td>
</tr>
</table>
这是JSP处理代码:
<%@ page contentType="text/html;charset=gb2312" %>
<jsp:useBean id="login" scope="page" class="mybean.loginBean"/>
<jsp:setProperty name="login" property="*" />
<%
int iResult=login.check();
if(iResult==1){
%><jsp:forward page="main.html" />
<%}
if(iResult==0){
%>
<h2 align="center">登录失败</h2><p/>
<h2 align="center"><a href="javascript:history.back(-1);">点击重新登录</a></h2>
<%}
%>
这是链接数据库的JAVABEAN:
package mybean;
import java.io.*;
import java.util.*;
import java.sql.*;
public class loginBean
{
private String adminName=null;
private String password=null;
public loginBean()
{
}
public void setAdminName(String value)
{
adminName=value;
}
public void setPassword(String value)
{
password= value;
}
public String getAdminName()
{
return adminName;
}
public String getPassword()
{
return password;
}
public int check()
{
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String strConn="jdbcdbc:LIBERARY_data";
String strUser="pt";
String strPassword="";
Connection conn=DriverManager.getConnection(strConn,strUser,strPassword);
Statement stat=conn.createStatement();
String strSql="SELECT COUNT(*) FROM dbo.administrator WHERE adminName='"+adminName+"' and password='"+password+"'";
ResultSet result=stat.executeQuery(strSql);
result.next();
if(result.getInt(1)==1)
{
return 1;
}
else
{
return 0;
}
}
catch (Exception e)
{
return 0;
}
}
}
各文档在tomcat中的目录:
javabean所在目录:D:\Program Files\apache-tomcat-6.0.26\webapps\book_shop\WEB-INF\classes\mybean\loginBean.class
JSP/HTML所在目录:D:\Program Files\apache-tomcat-6.0.26\webapps\book_shop
麻烦高手帮我看看问题出在哪里~~~
谢谢~~