SpringMVC中获取Servlet原生的API
【摘要】 控制器代码:
package com.Keafmd.controller;
import com.Keafmd.domain.Account;
import com.Keafmd.domain.User;
import org.springframework.stereotype.Controller;
import org.springframework.web....
控制器代码:
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"; }
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
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>
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
运行结果:
执行了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
- 1
- 2
- 3
- 4
- 5
以上就是SpringMVC中获取Servlet原生的API的全部内容。
看完如果对你有帮助,感谢点赞支持!
如果你是电脑端的话,看到右下角的 “一键三连” 了吗,没错点它[哈哈]
加油!
共同努力!
Keafmd
文章来源: keafmd.blog.csdn.net,作者:牛哄哄的柯南,版权归原作者所有,如需转载,请联系作者。
原文链接:keafmd.blog.csdn.net/article/details/113099637
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)