• jsp第六周作业


    <%@ 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); } }
  • 相关阅读:
    有趣的放大镜
    特效代码
    向数据库添加学生信息。存放在REQUEST对象里
    机房servlet过滤器
    冒泡排序法
    验证码 随机生成器 详解
    生成器 种子
    生日
    在字符串里寻找某字符出现的个数
    课堂随笔
  • 原文地址:https://www.cnblogs.com/575757ljp--/p/14649653.html
Copyright © 2020-2023  润新知