Struts登陆

JSP1:

<h1>
Struts框架的登陆
</h1><br />
<form method="post" action="untitled1Action.do">
<br><br>
<input type="text" name="userid" /><br />
<input type="password" name="password"  /><br />
<input type="submit" name="Submit" value="提交">
<input type="reset" value="重置"> 

JSP2:

<center>

<h1>
恭喜登陆成功!
</h1><br />
<a href="jsp1.jsp">返回</a>
</center>

JSP3:

<center>

<h1>
登陆失败!
</h1><br />
<a href="jsp1.jsp">返回</a>
</center>

Conclass:

package untitled4;
import java.sql.*;
public class Conclass {
    Connection con;
    public Conclass() {
        Connection con;
    }
    public boolean s(String userid,String password){
        boolean k=false;
        //String userId=userid;
        //String passWord=password;
        try {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            con = DriverManager.getConnection("jdbc:odbc:li");
            Statement st = con.createStatement();
            String sql = "select * from userId where userid='" + userid +
                         "' and password='" + password+"'";
            ResultSet rs = st.executeQuery(sql);
            if (rs.next()) {
                k = true;
            } else {
                k = false;
            }
        } catch (SQLException ex) {
        } catch (ClassNotFoundException ex) {
        }
        return k;
    }
}

Untitled1Action:

Untitled1ActionForm f = (Untitled1ActionForm) form;
        Conclass ccs=new Conclass();
        String userid=f.getUserid();
        String password=f.getPassword();
        boolean a=ccs.s(userid,password);
        if(a){
            System.out.println("chengong");
            return mapping.findForward("jsp2");
        }
        else{
            System.out.println("shibai");
            return mapping.findForward("jsp3");
        }
       

注意:在JSP里action="untitled1Action.do"提交的时候默认是action="/untitled1Action.do"形式,要把"/"去掉,不然untitled1Action.do页面白屏,不生成提交.还有sql语句的时候

正确:

String sql = "select * from userId where userid='" + userid +
                         "' and password='" + password+"'";

错误:

String sql = "select * from userId where userid=" + userid +
                         "'and password=" + password;


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值