struts登陆问题,望高手们指点啊!(分不多了,就10分了,谢谢大家了!)
现有2个用户表A,B。A表中有name,sex,account,password,address字段。A表中有 name,phone,account,password,createdate字段。 要将2个表的字段写入一个 user bean 中,查找account和password进行登陆,在user中查,最后用一个 boolean 判断是 A表还是B表的用户,若是从A中查的 那么user就填充A的信息,若是B 就填充B的信息。
写到 user中
package com.ecg.bean;
import java.io.*;
public class 11user implements Serializable {
/* 私有字段 */
private String name;
private String sex;
private String phone;
private String address;
private String Createdate;
//common params
private String account;
private String password;
//other params
private boolean isEcgUser ;
public String getAccount() {
return account;
}
public void setAccount(String account) {
this.account = account;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
………………………………………………………………………………
public boolean isEcgUser() {
return isEcgUser;
}
public void setEcgUser(boolean isEcgUser) {
this.isEcgUser = isEcgUser;
}
}
我使用的是struts模式
写了这个user类后 该如何在 loginform和loginaction中实现登陆并且把页面发送到A,B表中用户对应的页面去呢?
public boolean validatePsd(LoginForm forms)
{
String username=CharFilter.filterChar(CharFilter.toChinese(forms.getUsername()));
String psd=CharFilter.filterChar(CharFilter.toChinese(forms.getPassword()));
boolean exist=false;
sql = "select * from ecguser where account='" + username + "' and password='" + psd + "'";
try
{ conn.setAutoCommit(true);
stmt=conn.createStatement();
ResultSet rs=stmt.executeQuery(sql);
//如果存在
if (rs.next())
{
exist=true ;
this.setUser(user) ;
}
}
catch(SQLException e)
{
e.printStackTrace();
throw new RuntimeException("查找发生错误!");
}
finally
{
try
{
if (stmt!=null)
stmt.close();
if (rs!=null)
rs.close();
}
catch(Exception e)
{
e.printStackTrace();
throw new RuntimeException("运行发生错误!");
}
}
return exist;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
}
上面这段程序如何改写一下,才能够实现在A,B表中都进行了查找呢?