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); } }

 

posted @ 2021-04-12 19:36  Demens  阅读(42)  评论(0编辑  收藏  举报