电子通讯薄(MVC) :此示例基于MVC模式,包含四个界面:登入、添加数据、查询数据和显示所有数据,通过这个示例将会对Struts构架有进一步的了解

源代码在线查看: userbean.java

软件大小: 1498 K
上传用户: xof1234
关键词: MVC Struts 数据 电子通讯
下载地址: 免注册下载 普通下载 VIP

相关代码

				package addressbook.model;
				
				import java.util.*;
				import java.sql.*;
				import javax.servlet.http.HttpServletRequest;
				import javax.servlet.http.HttpSession;
				
				public final class UserBean{
				
				  private String password = null;
				  private String userName = null;
				  private Connection con;
				  private String isLog="0";
				
				  // Getter/Setter methods for all defined properties
				
				  public String getPassword() {
				    return (password);
				  }
				
				  public String getUserName() {
				    return (userName);
				  }
				
				  public void setPassword(String password) {
				    this.password = password;
				  }
				
				  public void setUserName(String userName) {
				    this.userName = userName;
				  }
				
				  public UserBean() {
				    try {
				      this.con = DbUtil.getConnection();
				    }
				    catch (Exception e) {
				      System.out.println("e" + e.getMessage());
				    }
				  }
				
				  public String Check(String userName,String password)throws Exception{
				      Statement stmt=null;
				      ResultSet rs=null;
				      try
				      {
				        //String userName=user.getUserName();
				        //String password=user.getPassword();
				        stmt=con.createStatement();
				        rs=stmt.executeQuery("select * from user where username='"+userName+"' and password='"+password+"'");
				        if(rs.next())
				           {
				             isLog="1";
				             System.out.println("fsadff"+isLog);
				           }
				      }
				      catch(Exception e)
				      {
				        e.printStackTrace();
				      }
				      finally
				      {
				          try
				          {
				            rs.close();
				            stmt.close();
				            con.close();
				          }
				          catch(Exception ex)
				          {ex.printStackTrace();}
				      }
				      return isLog;
				  }
				
				//  public String toString() {
				//    StringBuffer sb = new StringBuffer("User[username=" + userName + "]");
				//    return (sb.toString());
				//  }
				}
							

相关资源