jsp学习----纯jsp页面

java ee开发的几种模式:model1模式,model2模式,mvc模式,SSH框架


一、model1模式


有三个jsp文件

(1)用于输入用户名和密码

(2)1 提交后进入用户处理页面

(3)如果登录成功,则进入用户登录成功页面

(1)用于输入用户名和密码

<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'login.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

  </head>
  
  <body> 
    用户登录 <br>
   <hr>
   <form action="loginCl.jsp" method="post">
   用户名:<input type="text" name="username"><br>
   密码:<input type="text" name = "passwd"><br>
 <input type="submit" value="登录">
 <input type="reset" value="重置">
 </form>
  </body>
</html>

(2)用于验证用户名和密码,如果成功,则跳转

用response.sendRedirect 来进行跳转

  <body>
    <%
    String u = request.getParameter("username");
    String p = request.getParameter("passwd");
    if(u.equals("wbx") && p.equals("wbx"))
    {
       response.sendRedirect("wel.jsp?user="+u);
     }
     else
     response.sendRedirect("login.jsp");
    %>
  </body>

(3)
  <body>
  <% 
   String username = request.getParameter("user");
  %>
  welcome wbx <%=username %><br>
  </body>


如何在jsp中数据库的操作:


<body>
    <%
    String u = request.getParameter("username");
    String p = request.getParameter("passwd");
    Connection cnn;
    String url = "jdbc:mysql://localhost:3306/wbx1?user=root&password=buptnic&useUnicode=true&characterEncoding=UTF8";
    Class.forName("com.mysql.jdbc.Driver");
    cnn = DriverManager.getConnection(url);
    
    Statement sm =  cnn.createStatement();
    ResultSet rs = sm.executeQuery("select password from user where name='"+u+"'");
    
    //根据结果做判断
    if(rs.next())
    {
       if(rs.getString(1).equals(p))
       {
          response.sendRedirect("wel.jsp?user="+u);
       }
    }
     else
     {
          response.sendRedirect("login.jsp");
     }
 //   if(u.equals("wbx") && p.equals("wbx"))
  //  {
  //     response.sendRedirect("wel.jsp?user="+u);
  //   }
  //   else
  //   response.sendRedirect("login.jsp");
    %>
  </body>






评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值