栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

P14 Request开始

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

P14 Request开始

项目结构: 

创建RequestTest。作用:获取表单的内容(从前端反馈到后端)

package com.Li.Servlet;

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("进入了RequestTest");

        String username = req.getParameter("username");
        String password = req.getParameter("password");
        System.out.println(username+" "+password);

        resp.sendRedirect("/r/Success.jsp");//获取完信息之后重定向,指向下一个jsp
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}

index.jsp(前端的内容)



Hello World!
<%--${pageContext.request.contextPath}代表当前项目--%>
username:
password:

重定向:

<%--
  Created by IntelliJ IDEA.
  User: Li
  Date: 2022/6/6
  Time: 19:09
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>


    Title


Success!


 

配置web忽略。太基础了。

效果: 

 

 

 

 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/959806.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号