Response获取用户名密码

1.建一个类,获取用

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package com.yin;
 
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
 
public class RequestTest extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //System.out.println("进入这个请求");
        //处理请求
        String  username=req.getParameter("username");
        String  password=req.getParameter("password");
        System.out.println(username+":"+password);
        resp.sendRedirect("/response1_war/success.jsp");
    }
 
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doGet(req, resp);
    }
}

  2.修改INDEX.JSP用它来录入用户名密码。

1
2
3
4
5
6
7
8
9
10
11
12
<%@ page contentType="text/html;charset=UTF-8" language="java" %><br><html>
<body>
<h2>Servlet Demo!</h2>
<%--这里提交的路径,需要寻找到项目路径--%>
<%--${pageContext.request.contextPath}代表当前项目--%>
<form action="${pageContext.request.contextPath}/login" method="get">
    用户名:<input type="text" name="username"><br>
    密码:<input type="password"  name="password"><br>
    <input type="submit">
</form>
</body>
</html>

  3. .web.xml里面加入加入 

1
2
3
4
5
6
7
8
<servlet>
    <servlet-name>request</servlet-name>
    <servlet-class>com.yin.RequestTest</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>request</servlet-name>
    <url-pattern>/login</url-pattern>
</servlet-mapping>

  4.sucess网页用来验证

1
2
3
4
5
6
<html>
<body>
<h2>Success!</h2>
 
</body>
</html>

  

 

posted @   壹贰叁肆伍陆  阅读(39)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 上周热点回顾(3.3-3.9)
· AI 智能体引爆开源社区「GitHub 热点速览」
点击右上角即可分享
微信分享提示