... ... <filter> <filter-name>HeaderFiler</filter-name> <filter-class>com.blogspot.na5cent.filter.HeaderFiler</filter-class> </filter> <filter-mapping> <filter-name>HeaderFiler</filter-name> <url-pattern>/*</url-pattern> <!-- /* คือ ทุก request ผ่าน filter นี้ --> </filter-mapping> ... ...java code
package com.blogspot.na5cent.filter; import java.io.IOException; import java.util.Locale; 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; /** * * @author redcrow */ public class HeaderFiler implements Filter { @Override public void init(FilterConfig filterConfig) throws ServletException { // } @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { response.setCharacterEncoding("UTF-8"); response.setLocale(new Locale("th", "TH")); HttpServletResponse httpResp = (HttpServletResponse) response; httpResp.setHeader("Server", "na5cent server"); httpResp.setHeader("X-Powered-By", "blogspot 9.9"); chain.doFilter(request, response); } @Override public void destroy() { // } }ในตอนแรกจะเป็น
หลังจากทำ filter
หลังจากทำ filter
good blog
ตอบลบBy the way, any thoughts on writing about best data rooms ? This topic is very burning now and many people are interested in it.
ตอบลบ