struts简单登陆跟删除

判断登陆的类:

public boolean index1(String userid,String password){
        DBcon dbcon=new DBcon();
        String sql="select * from yhid where yhid='"+userid+"' and yhpassword='"+password+"'";
        try {
            Statement stmt = dbcon.getcon().createStatement();
            ResultSet rs = stmt.executeQuery(sql);
            if (rs.next()) {
                System.out.println("访问数据库成功");
                return true;
            } else {
                System.out.println("访问数据库失败");
                return false;
            }
        } catch (Exception ex) {
            System.out.println("出现SELECTCLASS里异常");
            return false;
        }

   } 

进行删除的类

public boolean del(String userid){
        DBcon dbcon=new DBcon();
        String sql="delete from yhid where yhid='"+userid+"'";
      
            try {
                Statement stmt = dbcon.getcon().createStatement();
                int i = stmt.executeUpdate(sql);
                if (i > 0) {
                    System.out.println("DELETECLASS删除成功");
                    return true;
                } else {
                    System.out.println("DELETECLASS删除失败");
                    return false;
                }
            } catch (SQLException ex) {
                System.out.println("DELETECLASS删除出现异常");
                return false;
            }
    }

判断登陆的ACTION

public class Untitled1Action extends Action {
    public ActionForward execute(ActionMapping mapping, ActionForm form,
                                 HttpServletRequest request,
                                 HttpServletResponse response) {
        HttpSession session=request.getSession();
        Untitled1ActionForm f = (Untitled1ActionForm) form;
        String userid=f.getUserid();
        String password=f.getPassword();
        SelectClass sc=new SelectClass();
        boolean i=sc.index1(userid,password);
        if(i){
            System.out.println("I为真");
            session.setAttribute("userid",userid);
            return mapping.findForward("welcome");
        }
        else{
            System.out.println("I为假");
            return mapping.findForward("error");
        }
    }

输出的ACTION

 public ActionForward execute(ActionMapping mapping, ActionForm form,
                                 HttpServletRequest request,
                                 HttpServletResponse response) {
        Untitled2ActionForm f= (Untitled2ActionForm) form;
        String userid=f.getUserid();
        DeleteClass dc=new DeleteClass();
        boolean i=dc.del(userid);
        if(i){
            System.out.println("成功删除");
            return mapping.findForward("delok");
        }
        else{
            System.out.println("删除失败");
            return mapping.findForward("error1");
        }
用两个ACTIONFORM分别加ACTION做的,注意的是删除的判断是用一个整数来表示所改变的行数来判断.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值