| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 560 人关注过本帖
标题:[求助]JSP+JavaBean 用户登陆密码错误问题
只看楼主 加入收藏
hougbin
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2007-1-15
收藏
 问题点数:0 回复次数:2 
[求助]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 数据库 
2007-01-15 17:12
千里冰封
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:灌水之王
等 级:版主
威 望:155
帖 子:28477
专家分:59
注 册:2006-2-26
收藏
得分:0 

异常信息也不给


可惜不是你,陪我到最后
2007-01-15 18:57
every
Rank: 1
等 级:新手上路
帖 子:39
专家分:0
注 册:2006-7-11
收藏
得分:0 
怎么能每次都conn = DriverManager.getConnection(url,user,password);效率忒低了吧。

花儿为什么这样红??
2007-01-16 16:35
快速回复:[求助]JSP+JavaBean 用户登陆密码错误问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.012775 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved