태터데스크 관리자

도움말
닫기
적용하기   첫페이지 만들기

태터데스크 메시지

저장하였습니다.


2008/01/20 22:20

[Moneyplanner] request 한글 깨짐 현상 해결(reeust encoding)

<ServiceFilter.java>
/**
  * initialize filterConfig( which has init-parameter)
  */
 public void init(FilterConfig filterConfig) throws ServletException {
  this.filterConfig = filterConfig;
  log.debug("ServiceFilter is initialized.");
  // extract encoding
  Config config = ConfigFactory.getConfig();
  if (config.containsKey("system/page/encoding")) {
   encoding = config.get("system/page/encoding");
   log.debug(" - encoding( " + encoding + ") will be applied to request");
  } else {
   log.debug(" - encoding is not defined.");
  }
 }

public void doFilter(ServletRequest servletRequest,
   ServletResponse servletResponse, FilterChain filterChain)
   throws IOException, ServletException {
  // request 변경
  HttpServletRequest request = (HttpServletRequest) servletRequest;
  // set encoding
  if (!isMultiPart(request)) {
   // ajax 인경우, utf-8을 설정하고 그이외의 것은 config 정보 활용
   String ajaxValue = request.getHeader("ajax");
   if (StringUtils.isNotEmpty(ajaxValue)
     && ajaxValue.equalsIgnoreCase("true")) {
    setCharacterEncoding(request, "utf-8");
   } else if (StringUtils.isNotEmpty(encoding)) {
    setCharacterEncoding(request, encoding);
   }
  }
  // initialize ClinetObjectMap/ ServiceContext
  ServiceContext.init((HttpServletRequest) servletRequest,
    (HttpServletResponse) servletResponse);
  // chain to next filter
  filterChain.doFilter(servletRequest, servletResponse);
  // destory ServietContext and ClientObjectMap
  ServiceContext.destory();
  ContextHolder.clear();
 }



<configuration.xml>
<system>
  <native>
   <encoding>MS949</encoding>
   <locale>
    <language>ko</language>
    <country>KR</country>
   </locale>
  </native>
  <http>
   <encoding>ISO-8859-1</encoding>
  </http>
  <page>
   <encoding>MS949</encoding>
  </page>
  <file>
   <encoding>utf-8</encoding>
  </file>
 </system>



config객체는 configuration.xml을 자동으로 읽어오게 셋팅이 되어 있다.
config객체를 통하여 system/page/encoding값(MS949)을 불러와 request를 인코딩해준다.

requst 한글 깨지는 현상 해결...
Trackback 0 Comment 0