Created
January 24, 2016 16:24
-
-
Save hugoangeles0810/b9754dde7a00f6f484bb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* To change this license header, choose License Headers in Project Properties. | |
* To change this template file, choose Tools | Templates | |
* and open the template in the editor. | |
*/ | |
package com.dev2012.noticiasunp.util; | |
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; | |
/** | |
* | |
* @author Hugo | |
*/ | |
public class EncodingFilter implements Filter { | |
private String encoding = "utf-8"; | |
@Override | |
public void doFilter(ServletRequest request, | |
ServletResponse response, FilterChain filterChain) throws IOException, ServletException { | |
request.setCharacterEncoding(encoding); | |
filterChain.doFilter(request, response); | |
} | |
@Override | |
public void init(FilterConfig filterConfig) throws ServletException { | |
String encodingParam = filterConfig.getInitParameter("encoding"); | |
if (encodingParam != null) { | |
encoding = encodingParam; | |
} | |
} | |
@Override | |
public void destroy() { | |
// nothing todo | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Agrega esto a tu web.xml --> | |
<filter> | |
<filter-name>EncodingFilter</filter-name> | |
<filter-class> | |
com.dev2012.noticiasunp.util.EncodingFilter | |
</filter-class> | |
<init-param> | |
<param-name>encoding</param-name> | |
<param-value>UTF-8</param-value> | |
</init-param> | |
</filter> | |
<filter-mapping> | |
<filter-name>EncodingFilter</filter-name> | |
<url-pattern>/*</url-pattern> | |
</filter-mapping> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment