springmvc之获取Servlet原生的API

jsp

<%--
  Created by IntelliJ IDEA.
  User: Mocar
  Date: 2019/9/11
  Time: 18:14
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>


    Title


    <%--相对路径--%>
    原声ServletAPI


ParamController
/**
 * @Date 2019/9/11 18:16
 * by mocar
 */
@Controller
@RequestMapping("/param")
public class ParamController {
        @RequestMapping(path = "testServlet")
    private String testServlet(HttpServletRequest servletRequest, HttpServletResponse servletResponse){
        System.out.println("执行....");
        String contextPath = servletRequest.getContextPath();
        System.out.println("contextPath:" +contextPath);

        String method = servletRequest.getMethod();
        System.out.println("method:" +method);

        String encoding = servletRequest.getCharacterEncoding();
        System.out.println("encoding:" +encoding);

        HttpSession session = servletRequest.getSession();
        System.out.println("session:" +session);

        ServletContext servletContext = session.getServletContext();
        System.out.println("servletContext:" +servletContext);

        System.out.println("servletResponse:" +servletResponse);
        return "success";

    }
}

springmvc之获取Servlet原生的API_第1张图片

 

springmvc之获取Servlet原生的API_第2张图片

 

就是这么简单,传入参数就行 

你可能感兴趣的:(springmvc)