package poster.model;
public class Userinfo {
private Integer userid;
public Integer getUserid() {
return userid;
}
public void setUserid(Integer userid) {
this.userid = userid;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getUserpwd() {
return userpwd;
}
public void setUserpwd(String userpwd) {
this.userpwd = userpwd;
}
public String getUsertime() {
return usertime;
}
public void setUsertime(String usertime) {
this.usertime = usertime;
}
private String username;
private String userpwd;
private String usertime;
private String userquan;
public String getUserquan() {
return userquan;
}
public void setUserquan(String userquan) {
this.userquan = userquan;
}
}
package poster_dao.imp;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import poster1_dao.IDaoBBs;
import poster_model.*;
import poster_util.DBHelper;
public class UserInfoDao implements IDaoBBs {
@Override
public int addItem(Userinfo t) throws SQLException {
String sql="Insert into userinfo(userid,userquan,username,userpwd,usertime)values(sequence1.nextval,?,?,?,?)";
return DBHelper.executeNonQuery(sql,t.getUserquan(), t.getUsername(),t.getUserpwd(),t.getUsertime());
}
@Override
public int removeItem(Object object) throws SQLException {
String sql="Delete from userinfo where userid=?";
return DBHelper.executeNonQuery(sql, object);
}
@Override
public int updateInem(Userinfo t) throws SQLException {
String sql="Update userinfo set userquan=?, username=?,userpwd=?,usertime=? Where userid=?";
return DBHelper.executeNonQuery(sql, t.getUserquan(), t.getUsername(),t.getUserpwd(),t.getUsertime());
}
@Override
public Userinfo getModel(Object object) throws SQLException {
String sql="Select *From userInfo where userid=?";
ResultSet resultset=DBHelper.executeQuery(sql, object);
Userinfo u=new Userinfo();
while(resultset.next()){
u.setUserid(resultset.getInt("userid"));
u.setUserquan(resultset.getString("userquan"));
u.setUsername(resultset.getString("username"));
u.setUserpwd(resultset.getString("userpwd"));
u.setUsertime(resultset.getString("usertime"));
}
resultset.close();
DBHelper.closeConnection();
return u;
}
@Override
public List getList(Userinfo t) throws SQLException {
StringBuffer sbsql=new StringBuffer("Select * From userInfo where 1=1");
if(t!=null){
if(t.getUserid()!=null){
sbsql.append(" And userid ="+t.getUserid()+"");
}
if(t.getUserquan()!=null){
sbsql.append(" And userquan like '"+t.getUserquan()+"'");
}
if(t.getUsername()!=null){
sbsql.append(" And username like '"+t.getUsername()+"'");
}
if(t.getUserpwd()!=null){
sbsql.append(" And userpwd like '"+t.getUserpwd()+"'");
}
if(t.getUsertime()!=null){
sbsql.append(" Add userpwd like '"+t.getUsertime()+"'");
}
}
ResultSet resultset=DBHelper.executeQuery(sbsql.toString());
List list=new ArrayList();
while(resultset.next()){
Userinfo u=new Userinfo();
u.setUserid(resultset.getInt("userid"));
u.setUserquan(resultset.getString("userquan"));
u.setUsername(resultset.getString("username"));
u.setUserpwd(resultset.getString("userpwd"));
u.setUsertime(resultset.getString("usertime"));
list.add(u);
}
resultset.close();
DBHelper.closeConnection();
return list;
}
}
package poster_service;
import java.sql.SQLException;
import java.util.List;
import poster_dao.imp.UserInfoDao;
import poster_model.Userinfo;
public class UserInfoService {
UserInfoDao uw=new UserInfoDao();
/**
* 登录业务处理
* @param username
* @param userPwd
* @return
* @throws SQLException
*/
public Userinfo userLogin(String username,String userPwd) throws SQLException{
Userinfo u1=new Userinfo();
u1.setUsername(username);
u1.setUserpwd(userPwd);
List list=uw.getList(u1);
Userinfo tmp=null;
if(list.size()>0){
tmp=list.get(0);
}
return tmp;
}
/**
*用户注册的业务
* @param u
* @return
* @throws SQLException
*/
public boolean userReg(Userinfo u) throws SQLException{
if(uw.addItem(u)>0){
return true;
}else{
return false;
}
}
}
package poster_action;
import java.io.IOException;
import java.sql.SQLException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import poster_model.Userinfo;
import poster_service.UserInfoService;
@WebServlet(name="loginaction",urlPatterns="/loginaction.do")
public class userrk extends HttpServlet{
private static final long seriaVersionUID=1L;
UserInfoService user=new UserInfoService();
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
req.setCharacterEncoding("utf-8");
String username=req.getParameter("username");
String userPwd=req.getParameter("userpwd");
try {
Userinfo u=user.userLogin(username, userPwd);
if(u==null){
req.setAttribute("Userinfo", "登陆失败,用户名和密码输入错误!");
resp.sendRedirect("sics.jsp");
}else{
HttpSession session=req.getSession();
session.setAttribute("user", u);
req.getRequestDispatcher("zuye.jsp").forward(req, resp);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
doGet(req, resp);
}
}
package poster_action;
import java.io.IOException;
import java.sql.SQLException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import poster_model.Userinfo;
import poster_service.UserInfoService;
import poster_util.CommonHelp;
import poster_util.DBHelper;
@WebServlet(name="reging",urlPatterns="/reg1.do")
public class debark extends HttpServlet {
UserInfoService user=new UserInfoService();
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
req.setCharacterEncoding("utf-8");
String userquan=req.getParameter("userquan");
String username=req.getParameter("username");
String userpwd=null;
String userpwd1=req.getParameter("userpwd");
String userpwd2=req.getParameter("userpwd1");
String usertime=DBHelper.Csss();
if(userpwd1.equals(userpwd2)){
userpwd=req.getParameter("userpwd");
Userinfo u=new Userinfo();
u.setUserquan(userquan);
u.setUsername(username);
u.setUserpwd(userpwd);
u.setUsertime(usertime);
try {
boolean u1=user.userReg(u);
if(u1){
resp.sendRedirect("zuye.jsp");
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}else{
resp.sendRedirect("zucc.jsp");
}
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
doGet(req, resp);
}
}