<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*,bookBeans.ConnDB" errorPage="" %><html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head><body>
<%
String name=request.getParameter("USER");
String pass=request.getParameter("PASSWORD");
ConnDB conn=new ConnDB();
String sql="select * from ADMIN where ADMINNAME='"+name+"' and PASSWORD='"+pass+"'";
ResultSet rs=conn.doQuery(sql);
if(rs.next())
{
name=rs.getString("ADMINNAME");
response.sendRedirect("index.html");
}
else
{ %>
登录失败,请重新登录!!!
<% // response.sendRedirect("login.jsp");
response.setHeader("Refresh","15;URL=login.html");
}
%>
</body>
</html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head><body>
<%
String name=request.getParameter("USER");
String pass=request.getParameter("PASSWORD");
ConnDB conn=new ConnDB();
String sql="select * from ADMIN where ADMINNAME='"+name+"' and PASSWORD='"+pass+"'";
ResultSet rs=conn.doQuery(sql);
if(rs.next())
{
name=rs.getString("ADMINNAME");
response.sendRedirect("index.html");
}
else
{ %>
登录失败,请重新登录!!!
<% // response.sendRedirect("login.jsp");
response.setHeader("Refresh","15;URL=login.html");
}
%>
</body>
</html>
解决方案 »
- 刚刚看了一个月经贴,讨论java与 那个 c 井 ??特此转篇文章与大家分享……
- jsp 能用相对路径写文件吗?
- 一个超棘手问题,各位进来,高分,来者有分?????????不看后悔哦?????????????????
- 有人用过proStep开发的PLM_service吗?
- 请问STRUTS中等价于request.getParameter()的标签是什么
- 使用jspSmartUpload下載的中文问题,谢谢!
- 菜鸟问题:关于临时文件
- 求解决!数据全查出来,但是有一条客户的不想要,怎么办?
- 放在哪里好??
- 在学JSP,有何比较经典的好书?
- 雪地里跪求 场景描述的 正确格式和 编写思路
- jsp实现一个简单的注册跳转界面
15: ConnDB conn=new ConnDB();
16: String sql="select * from ADMIN where ADMINNAME='"+name+"' and PASSWORD='"+pass+"'";
17: ResultSet rs=conn.doQuery(sql);
18: if(rs.next())
19: {
20: name=rs.getString("ADMINNAME");
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:510)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:419)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
这个是错误页面
在这个页面的17行看下 是不是哪里写错了
也许是conn.doQuery(sql);这个doQuery方法错了,也许是conn对象初始化的时候错了。。把conn的代码贴出来看看
import java.sql.*;
import java.io.*;
import java.util.*;public class ConnDB
{
public Connection conn=null;
public Statement stmt=null;
public ResultSet rs=null;
private static String dbDriver="sun.jdbc.odbc.JdbcOdbcDriver";
private static String dbUrl="jdbc:odbc:BOOK";
private static String dbUser="sa";
private static String dbPwd=""; //打开数据库连接
public static Connection getConnection()
{
Connection conn=null;
try
{
Class.forName(dbDriver);
conn=DriverManager.getConnection(dbUrl,dbUser,dbPwd);
}
catch(Exception e)
{
e.printStackTrace();
}
if (conn == null)
{
System.err.println("警告:数据库连接失败!");
}
return conn;
}
//读取结果集
public ResultSet doQuery(String sql)
{
try
{
conn=ConnDB.getConnection();
stmt=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
rs=stmt.executeQuery(sql);
}
catch(SQLException e)
{
e.printStackTrace();
}
return rs;
}
//更新数据
public int doUpdate(String sql)
{
int result=0;
try
{
conn=ConnDB.getConnection();
stmt=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
result=stmt.executeUpdate(sql);
}
catch(SQLException e)
{
result=0;
}
return result;
}
//关闭数据库连接
public void closeConnection()
{
try
{
if (rs!=null)
rs.close();
}
catch(Exception e)
{
e.printStackTrace();
}
try
{
if (stmt!=null)
stmt.close();
}
catch(Exception e)
{
e.printStackTrace();
}
try
{
if (conn!=null)
conn.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
这是CONN的代码
能不能正常执行
这个url不对把
String url=“jdbc:odbc:Driver={MicroSoft Access Driver (*.mdb)};DBQ=“+application.getRealPath(“/Data/ReportDemo.mdb“);
你这样试试