zoukankan      html  css  js  c++  java
  • 2021.4.7jsp第六周作业

    1.安装MySQL数据库,建立用户表 uid uname upwd 并插入3条数据

    2.制作jsp登录页面 login.jsp 提交到dologin.jsp,使用jdbc连数据库,判断输入的用户名密码是否存在

    3.如果存在,把用户名保存在SESSION中,跳转到welcome.jsp,welcome.jsp中读取session中的用户名,显示欢迎你xxx

    4.若不存在,跳到登录页面。

    <%@ page contentType="text/html;charset=UTF-8" language="java" %>
    <html>
      <head>
        <title>$Title$</title>
      </head>
    
      <body>
      <form action="doLogin.jsp" method="post" >
        用户名:<input type="text" name="username"/>
        <br>
        密码:<input type="password"  name="password"/>
        <br>
        <input type="submit" value="登录">
      </form>
      </body>
    </html>
    <%@ page contentType="text/html;charset=UTF-8" language="java" %>
    <html>
    <head>
     
    </head>
    <body>
     
    <%
        String name = (String) request.getSession().getAttribute("uname");
    %>
    
    <body  style="background:url(images/1.jpg)">
      <div class="contentArea">
       <h1 style="color: red">欢迎登录<%=name%>登陆!</h1>
    </html>
    <%
        JDBCKu jdbcKu = new JDBCKu();
        String username = request.getParameter("username");
        String password = request.getParameter("password");
    
        Connection conn = jdbcKu.getConnection();
        String sql = "select * from user where uname = ? and upassword = ?";
        PreparedStatement ps = conn.prepareStatement(sql);
        ps.setNString(1,username);
        ps.setNString(2,password);
    
        ResultSet rs = ps.executeQuery();
    
        if (rs.next() == true) {
            request.getSession().setAttribute("username",username);
            request.getRequestDispatcher("welcome.jsp").forward(request,response);
        }else{
            response.sendRedirect("index.jsp");
        }
    
        jdbcKu.closeAll(conn, ps, rs);
    %>
    @WebServlet(name = "CreateCodeController",value = "/createCode")
    public class CreateCodeController extends HttpServlet {
        protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            ValidateCode code = new ValidateCode(200,30,4,20);
            String codes = code.getCode();
            HttpSession session = request.getSession();
            session.setAttribute("codes",codes);
            code.write(response.getOutputStream());
        }
    
        protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            doPost(request,response);
        }
    }
  • 相关阅读:
    SSRS Fields cannot be used in page headers or footers
    mac os x 触摸板点击无效
    Android内核sysfs中switch类使用实例
    hdu1827之强联通
    解决Gradle执行命令时报Could not determine the dependencies of task &#39;:compileReleaseJava&#39;.
    我对Lamport Logical Clock的理解
    側滑删除进阶(七、八)
    管理之路(成长之路--五)
    Qt跨平台的一个例程
    IOS 开发推荐经常使用lib
  • 原文地址:https://www.cnblogs.com/megumin/p/14647448.html
Copyright © 2011-2022 走看看