• 课本在servlet中检索参数并验证,最后向用户发送验证消息


     

     

     

     

     

     

     

     

     

     

     

     

     

     

    这网页代码是我直接审查网页源代码后照抄的

    1. <!DOCTYPE html>
    2. <html>
    3. <head>
    4. <meta charset="UTF-8">
    5. <title>登录页面</title></head>
    6. <body>
    7. <form action="user-login" method="get">
    8. <fieldset>
    9. <legend>用户登录</legend>
    10. <p>
    11. <label>用户名: <input type="text" name="username"/>
    12. </label>
    13. </p>
    14. <p>
    15. <label>&nbsp;&nbsp;码:<input type="password" name="password"/>
    16. </label>
    17. </p>
    18. <p>
    19. <label><input type="submit" value="登录"/>
    20. <input type="reset" value="取消"/>
    21. </label>
    22. </p>
    23. </fieldset>
    24. </form>
    25. </body>
    26. </html>
    1. package com.demo;
    2. import java.io.IOException;
    3. import java.io.PrintWriter;
    4. import javax.servlet.ServletException;
    5. import javax.servlet.annotation.WebServlet;
    6. import javax.servlet.http.HttpServlet;
    7. import javax.servlet.http.HttpServletRequest;
    8. import javax.servlet.http.HttpServletResponse;
    9. /**
    10. * Servlet implementation class LoginServlet
    11. */
    12. @WebServlet("/user-login")
    13. public class LoginServlet extends HttpServlet {
    14. private static final long serialVersionUID = 1L;
    15. /**
    16. * @see HttpServlet#HttpServlet()
    17. */
    18. public LoginServlet() {
    19. super();
    20. // TODO Auto-generated constructor stub
    21. }
    22. /**
    23. * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
    24. */
    25. protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    26. String username=request.getParameter("username");
    27. String password = request.getParameter("password");
    28. response.setContentType("text/html;charset=UTF-8");
    29. PrintWriter out=response.getWriter();
    30. out.println("");
    31. out.println("\r\n"
    32. + "\r\n"
    33. + "登录页面");
    34. out.println("");
    35. if("admin".equals(username)&&"12345".equals(password)) {
    36. out.println("许嘉茵成为我妻子"+username);
    37. }else {
    38. out.println("李梓健是她老公");
    39. }
    40. out.println("");
    41. }
    42. protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    43. doPost(request,response);
    44. }
    45. }

    只用这两个

     

     

     

     

    我先关掉tomcat,,然后先点击,运行hello.html,输入密码进去,然后再运行Loginservlet.java,就跳转405

     增加方法后

     保存代码,然后页面刷新

     

     

  • 相关阅读:
    Spring Cloud 网关的配置示例
    PyTorch 中张量运算广播
    springboot+vue实现excel的导出
    <unordered_set、unordered_map的模拟实现>——《C++高阶》
    Unity 生命周期(笔记)
    Git分布式版本控制工具(一)
    强化学习环境 - robogym - 学习 - 2
    简单实用的数据可视化案例
    Rust所有权机制
    生成式AI:未来的发展方向是什么?
  • 原文地址:https://blog.csdn.net/weixin_52634719/article/details/126727432