250x250
Notice
Recent Posts
Recent Comments
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
Tags
- Exception
- oracle
- git
- Source
- Open Source
- IntelliJ
- spring
- error
- SpringBoot
- PostgreSQL
- Tomcat
- ubuntu
- STS
- jpa
- Core Java
- 문서
- Docker
- 오픈소스
- MSSQL
- JavaScript
- MySQL
- 설정
- AJAX
- maven
- Eclipse
- myBatis
- Python
- Spring Boot
- JDBC
- Thymeleaf
Archives
- Today
- Total
헤르메스 LIFE
[Spring] 스프링에서 현재 HttpServletRequest 가져오는 방법 본문
728x90
원문 :
http://holecjh.tistory.com/entry/%EC%8A%A4%ED%94%84%EB%A7%81%EC%97%90%EC%84%9C-%ED%98%84%EC%9E%AC-HttpServletRequest-%EA%B0%80%EC%A0%B8%EC%98%A4%EB%8A%94-%EB%B0%A9%EB%B2%95
* RequestContextListener 설정하기
web.xml 파일에 아래와 같이 리스너를 설정 합니다.
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
* 현재 HttpServletRequest 객체 가져오는 함수 만들기
public static HttpServletRequest getCurrentRequest() {
ServletRequestAttributes sra = (ServletRequestAttributes) RequestContextHolder
.currentRequestAttributes();
HttpServletRequest hsr = sra.getRequest();
return hsr;
}
web.xml 파일에 아래와 같이 리스너를 설정 합니다.
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
* 현재 HttpServletRequest 객체 가져오는 함수 만들기
public static HttpServletRequest getCurrentRequest() {
ServletRequestAttributes sra = (ServletRequestAttributes) RequestContextHolder
.currentRequestAttributes();
HttpServletRequest hsr = sra.getRequest();
return hsr;
}
728x90
'Spring Framework' 카테고리의 다른 글
| [Spring] ApplicationContext의 초기화 과정 (1) | 2012.05.22 |
|---|---|
| [Spring] Spring + MyBatis 에서 여러 개의 Datasource Routing 하는 방법 (0) | 2012.05.21 |
| [Spring] 스프링 restfull 정적파일 (0) | 2012.04.12 |
| [Spring] DispatcherServlet 란...?? (0) | 2012.04.06 |
| [JUnit] @DirtiesContext 사용의 주의점 (0) | 2012.04.06 |