반응형
Interceptor.java
public class Interceptor extends HandlerInterceptorAdapter{
private final static Logger LOGGER = LoggerFactory.getLogger(Interceptor.class);
@Autowired
AccessHistoryService accessHistoryService;
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
HttpSession session = request.getSession();
String ipAddress = Utils.getClientIp(request);
String prevURI = "";
if( request.getRequestURI() != null ) {
if( session != null && session.getAttribute("prevURI") != null ) {
LOGGER.debug("prev session:"+session.getAttribute("prevURI"));
prevURI = session.getAttribute("prevURI").toString();
if( request.getQueryString() != null ) prevURI += "?"+request.getQueryString();
session.setAttribute("prevPrevURI", prevURI);
}
prevURI = request.getRequestURI();
session.setAttribute("prevURI", prevURI);
LOGGER.debug("URI =========================="+prevURI);
}
LOGGER.debug("preHandle =prevURI:"+prevURI);
// 디바이스 종류
String dvcType = "Desktop";
if(request.getHeader("User-Agent") != null && request.getHeader("User-Agent").toUpperCase().indexOf("MOBILE") > 0 ) dvcType = "Mobile";
// 접속한 브라우저 종류 가져오기
String brwsType = Utils.getAccBrowserType(request);
HashMap <String,Object> accHisMap = new HashMap<String, Object>();
accHisMap.put("atryMbrId", ""); // 접속회원아이디
accHisMap.put("cntnIpAddr", ipAddress); // ip주소
accHisMap.put("accUrlAddr", prevURI); // uri 주소
accHisMap.put("accPrmt", request.getQueryString()); // 접근 파라미터
accHisMap.put("dvcType", dvcType); // 디바이스 종류
accHisMap.put("brwsType", brwsType); // 브라우저 종류
// 쿼리에 입력
int res = accessHistoryService.insertAccessHistory(accHisMap);
LOGGER.debug("acc history result:"+res);
return true;
}
@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
ModelAndView modelAndView) throws Exception {
// TODO Auto-generated method stub
super.postHandle(request, response, handler, modelAndView);
}
}
반응형
context-properties.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:security="http://www.springframework.org/schema/security"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.3.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.3.xsd">
<beans:bean name="propertiesService" class="egovframework.rte.fdl.property.impl.EgovPropertyServiceImpl" destroy-method="destroy">
<beans:property name="properties">
<beans:map>
<beans:entry key="pageUnit" value="10"/>
<beans:entry key="pageSize" value="10"/>
</beans:map>
</beans:property>
</beans:bean>
<!-- <util:properties id="server" location="/WEB-INF/properties/server.properties"/> -->
<beans:bean id="propertyPlaceholderConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<beans:property name="locations">
<beans:list>
<beans:value>/WEB-INF/properties/server.properties</beans:value>
</beans:list>
</beans:property>
</beans:bean>
<util:properties id="server" location="/WEB-INF/properties/server.properties"/>
<!-- interceptor 설정 부분 -->
<interceptors>
<interceptor>
<mapping path="/**"/>
<exclude-mapping path="/resources/**"/>
<beans:bean id="commonInterceptor" class="com.kyobo.kdkb.common.interceptor.Interceptor">
</beans:bean>
</interceptor>
</interceptors>
</beans:beans>
끄읏
반응형
'웹앱프로젝트 > Spring Boot' 카테고리의 다른 글
Mybatis 한글자 숫자로 인식 (Cause: java.lang.NumberFormatException: For input string: "Y") (1) | 2023.02.02 |
---|---|
[formData] 넘길 수 있는 타입 file, text뿐. formData에 담긴 Json controller에서 받는 방법 (AJAX 로 보냄, 전자정부프레임워크) (0) | 2022.10.28 |
spring messageSource 파라미터 받아서 처리 (0) | 2022.09.02 |
백엔드 Spring 과 프론트엔드 Vue.js 연동한 프로젝트 생성 (0) | 2022.08.01 |
Spring Security 403 CSRF 오류 (0) | 2022.07.22 |