1 16 17 package org.springframework.web.filter; 18 19 import java.io.IOException ; 20 21 import javax.servlet.FilterChain ; 22 import javax.servlet.ServletException ; 23 import javax.servlet.http.HttpServletRequest ; 24 import javax.servlet.http.HttpServletResponse ; 25 26 39 public class CharacterEncodingFilter extends OncePerRequestFilter { 40 41 private String encoding; 42 43 private boolean forceEncoding; 44 45 46 54 public void setEncoding(String encoding) { 55 this.encoding = encoding; 56 } 57 58 65 public void setForceEncoding(boolean forceEncoding) { 66 this.forceEncoding = forceEncoding; 67 } 68 69 70 protected void doFilterInternal( 71 HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) 72 throws ServletException , IOException { 73 74 if (this.encoding != null && (this.forceEncoding || request.getCharacterEncoding() == null)) { 75 request.setCharacterEncoding(this.encoding); 76 } 77 filterChain.doFilter(request, response); 78 } 79 80 } 81 | Popular Tags |