当前位置: 代码迷 >> Java Web开发 >> [求助]JSP+JavaBean 用户登陆密码错误问题
  详细解决方案

[求助]JSP+JavaBean 用户登陆密码错误问题

热度:1036   发布时间:2007-01-15 17:12:54.0
[求助]JSP+JavaBean 用户登陆密码错误问题

JSP+JavaBean 用户登陆密码错误,这个问题痛苦了好多天了,望高手赐教.QQ:82689774
在我的代码中处理了password的空格问题,但就是出错,代码如下
连接SERVER数据库 salBean.java
package hou;

import java.sql.*;
public class sqlBean{
String sDBDriver = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=educationi";

String user="sa";
String password="";
Connection conn= null;
Statement stmt = null;
ResultSet rs = null;
public sqlBean()
{
try
{Class.forName(sDBDriver);
}
catch(java.lang.ClassNotFoundException e)
{
System.err.println("sqlBean(): " + e.getMessage());
}
}

/////////////////插入操作
public void executeInsert(String sql)
{
try
{
conn = DriverManager.getConnection(url,user,password);
stmt = conn.createStatement();
stmt.executeUpdate(sql);
stmt.close();
conn.close();
}
catch(SQLException ex)
{System.err.println("sqlBean.executeUpdate:"+ex.getMessage());
}
}

//////////////////////查询操作
public ResultSet executeQuery(String sql)
{
try
{
conn = DriverManager.getConnection(url,user,password);
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
rs = stmt.executeQuery(sql);
}
catch(SQLException ex)
{
System.err.println("sqlBean.executeQuery:"+ex.getMessage());
}
return rs;
}

/////////////////////////更新操作
public void executeUpdate(String sql)
{
try {
conn = DriverManager.getConnection(url,user,password);
stmt = conn.createStatement();
stmt.executeUpdate(sql);
stmt.close();
conn.close();
}
catch(SQLException ex) {
System.err.println("sqlBean.executeQuery: " + ex.getMessage());
}
}

//执行删除操作
public void executeDelete(String sql)
{
try
{conn = DriverManager.getConnection(url,user,password);
stmt = conn.createStatement();
stmt.executeUpdate(sql);
stmt.close();
conn.close();
}
catch(SQLException ex)
{
System.err.println("sqlBean.executeDelete:"+ex.getMessage());
}
}

//关闭操作
public void closeStmt(){
try{
stmt.close();
}
catch(SQLException e){
e.printStackTrace();
}
}

public void closeConn(){
try{
conn.close();
}
catch(SQLException e){
e.printStackTrace();
}
}
}

密码查询校验 login_confirm.java
package hou;

import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class login_confirm extends HttpServlet{


public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
String message=null;
String id=null;
id=req.getParameter("id");
id=id.trim();
HttpSession session=req.getSession(true);
session.setAttribute("id",String.valueOf(id));
String password=null;
password=req.getParameter("password");
password= password.trim();


String temp =getPassword(req,res,id);
if( password.equals(temp))
goo(req,res);
else {
message="用户名或密码有误!";
doError(req,res,message) ;
}
}


public void goo(HttpServletRequest req, HttpServletResponse res)
throws ServletException,IOException
{

RequestDispatcher rd = getServletContext().getRequestDispatcher("/teacher.jsp");

}



public String getPassword(HttpServletRequest req, HttpServletResponse res,
String id)
throws ServletException, IOException {
sqlBean db= new sqlBean();
String pw="";
String sql="select password from member where id='"+id+"'";
try{
ResultSet rs=db.executeQuery(sql);

pw=rs.getString("password");
pw=pw.trim();
}

catch(Exception e)
{ System.out.print(e.toString());}
return pw;
}



public void doError(HttpServletRequest req,
HttpServletResponse res,
String str)
throws ServletException, IOException {

req.setAttribute("problem", str);
RequestDispatcher rd = getServletContext().getRequestDispatcher("/errorpage.jsp");
rd.forward(req, res);
}


public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
String action = action = req.getParameter("action");
if ("logout".equalsIgnoreCase(action)) {
HttpSession session=req.getSession(true);
session.invalidate();
RequestDispatcher rd = getServletContext().getRequestDispatcher("/jiemian.jsp");
rd.forward(req, res);
} }

}

搜索更多相关主题的帖子: 密码错误  JavaBean  JSP  数据库  

----------------解决方案--------------------------------------------------------

异常信息也不给


----------------解决方案--------------------------------------------------------
怎么能每次都conn = DriverManager.getConnection(url,user,password);效率忒低了吧。
----------------解决方案--------------------------------------------------------
  相关解决方案