티스토리 뷰
CORSFilter.class
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 | package com.boya.filter; import java.io.IOException; import javax.servlet.Filter; import javax.servlet.FilterChain; import javax.servlet.FilterConfig; import javax.servlet.ServletException; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; import javax.servlet.http.HttpServletResponse; public class CORSFilter implements Filter { public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { HttpServletResponse hsr = (HttpServletResponse) res; hsr.setHeader("Access-Control-Allow-Origin", "*"); hsr.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS"); hsr.setHeader("Access-Control-Max-Age", "3600"); hsr.setHeader("Access-Control-Allow-Headers", "x-requested-with, origin, content-type, accept"); chain.doFilter(req, res); } public void init(FilterConfig filterConfig) throws ServletException{/**/} public void destroy() {/**/} } | cs |
web.xml
1 2 3 4 5 6 7 8 | <filter> <filter-name>corsFilter</filter-name> <filter-class>com.boya.filter.CORSFilter</filter-class> </filter> <filter-mapping> <filter-name>corsFilter</filter-name> <url-pattern>/*</url-pattern> <filter-mapping> | cs |
'IT > JAVA' 카테고리의 다른 글
JDBC SID, Service Name 설정 차이 (0) | 2018.08.10 |
---|---|
자바 현재 화면 캡쳐 (2) | 2018.04.23 |
java.security.InvalidKeyException: Illegal key size (0) | 2017.10.11 |
Unsupported major.minor version (0) | 2017.09.20 |
자바 메소드명, 클래스명, 줄번호, 파일명 가져오기 (0) | 2017.09.14 |
댓글