fork download
  1. package jp.co.insightech;
  2.  
  3. import java.io.IOException;
  4.  
  5. import javax.servlet.Filter;
  6. import javax.servlet.FilterChain;
  7. import javax.servlet.FilterConfig;
  8. import javax.servlet.ServletException;
  9. import javax.servlet.ServletRequest;
  10. import javax.servlet.ServletResponse;
  11.  
  12.  
  13. public class CharacterEncodingFilter implements Filter {
  14.  
  15. private static final String INIT_PARAMETER_ENCODING = "encoding";
  16.  
  17. private static final String DEFAULT_ENCODING = "MS932";
  18.  
  19. private String encoding;
  20.  
  21. public void init(FilterConfig config) throws ServletException {
  22. this.encoding = config.getInitParameter(INIT_PARAMETER_ENCODING);
  23. if (this.encoding == null) {
  24. this.encoding = DEFAULT_ENCODING;
  25. }
  26. }
  27.  
  28. public void destroy() {
  29. this.encoding = null;
  30. }
  31.  
  32. /**
  33.   * リクエストのエンコーディングがセットされていない場合、
  34.   * 初期化パラメータ encoding で指定されたエンコーディングを
  35.   * リクエストにセットします。
  36.   *
  37.   * @param servletRequest
  38.   * ServletRequest
  39. * @param servletResponse
  40.   * ServletResponse
  41.   * @param chain
  42.   * FilterChain
  43.   * @throws IOException
  44.   * @throws ServletException
  45.   */
  46. public void doFilter(ServletRequest servletRequest,
  47. ServletResponse servletResponse, FilterChain chain)
  48. throws IOException, ServletException {
  49.  
  50. if (servletRequest.getCharacterEncoding() == null) {
  51. servletRequest.setCharacterEncoding(encoding);
  52. }
  53. chain.doFilter(servletRequest, servletResponse);
  54. }
  55. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:13: error: class CharacterEncodingFilter is public, should be declared in a file named CharacterEncodingFilter.java
public class CharacterEncodingFilter implements Filter {
       ^
Main.java:5: error: package javax.servlet does not exist
import javax.servlet.Filter;
                    ^
Main.java:6: error: package javax.servlet does not exist
import javax.servlet.FilterChain;
                    ^
Main.java:7: error: package javax.servlet does not exist
import javax.servlet.FilterConfig;
                    ^
Main.java:8: error: package javax.servlet does not exist
import javax.servlet.ServletException;
                    ^
Main.java:9: error: package javax.servlet does not exist
import javax.servlet.ServletRequest;
                    ^
Main.java:10: error: package javax.servlet does not exist
import javax.servlet.ServletResponse;
                    ^
Main.java:13: error: cannot find symbol
public class CharacterEncodingFilter implements Filter {
                                                ^
  symbol: class Filter
Main.java:21: error: cannot find symbol
        public void init(FilterConfig config) throws ServletException {
                         ^
  symbol:   class FilterConfig
  location: class CharacterEncodingFilter
Main.java:21: error: cannot find symbol
        public void init(FilterConfig config) throws ServletException {
                                                     ^
  symbol:   class ServletException
  location: class CharacterEncodingFilter
Main.java:46: error: cannot find symbol
        public void doFilter(ServletRequest servletRequest,
                             ^
  symbol:   class ServletRequest
  location: class CharacterEncodingFilter
Main.java:47: error: cannot find symbol
                        ServletResponse servletResponse, FilterChain chain)
                        ^
  symbol:   class ServletResponse
  location: class CharacterEncodingFilter
Main.java:47: error: cannot find symbol
                        ServletResponse servletResponse, FilterChain chain)
                                                         ^
  symbol:   class FilterChain
  location: class CharacterEncodingFilter
Main.java:48: error: cannot find symbol
                        throws IOException, ServletException {
                                            ^
  symbol:   class ServletException
  location: class CharacterEncodingFilter
14 errors
stdout
Standard output is empty