控制器代码:
package com.Keafmd.controller; import com.Keafmd.domain.Account; import com.Keafmd.domain.User; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; /** * Keafmd * * @ClassName: ParamController * @Description: * @author: 牛哄哄的柯南 * @date: 2021-01-24 15:57 */ @Controller @RequestMapping("/param") public class ParamController { /** * 原生的API * @return */ @RequestMapping("/testServlet") public String testParam(HttpServletRequest request, HttpServletResponse response){ System.out.println("执行了testServlet"); System.out.println("request:"+request); HttpSession session =request.getSession(); System.out.println("session:"+session); ServletContext servletContext = session.getServletContext(); System.out.println("servletContext:"+servletContext); System.out.println("response:"+response); return "success"; } }
jsp代码:
<%-- Created by IntelliJ IDEA. User: keafmd Date: 2021/1/24 Time: 15:55 To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>请求参数绑定</title> </head> <body> <a href="param/testServlet">servlet原生的API</a> </body> </html>
运行结果:
执行了testServlet request:org.apache.catalina.connector.RequestFacade@49c42855 session:org.apache.catalina.session.StandardSessionFacade@d52f38e servletContext:org.apache.catalina.core.ApplicationContextFacade@74dcdc30 response:org.apache.catalina.connector.ResponseFacade@395b82b4
以上就是SpringMVC中获取Servlet原生的API的全部内容。