struts로 검색한 결과 :: 시소커뮤니티[SSISO Community]
 
SSISO 카페 SSISO Source SSISO 구직 SSISO 쇼핑몰 SSISO 맛집
추천검색어 : JUnit   Log4j   ajax   spring   struts   struts-config.xml   Synchronized   책정보   Ajax 마스터하기   우측부분

회원가입 I 비밀번호 찾기


SSISO Community검색
SSISO Community메뉴
[카페목록보기]
[블로그등록하기]  
[블로그리스트]  
SSISO Community카페
블로그 카테고리
정치 경제
문화 칼럼
비디오게임 스포츠
핫이슈 TV
포토 온라인게임
PC게임 에뮬게임
라이프 사람들
유머 만화애니
방송 1
1 1
1 1
1 1
1 1
1

struts로 검색한 결과
등록일:2008-03-16 12:10:00
작성자:
제목:STRUTS2 의 한글 처리문제


기존에 한글처리는 Encoding Filter 를 써서 request의 캐릭터셋을 euc-kr로 변경하였었다.

public void doFilter(ServletRequest request, ServletResponse response,
           FilterChain chain) throws IOException, ServletException {

       if (request.getCharacterEncoding() == null) {
           if (encoding != null) {
               request.setCharacterEncoding(encoding);
               response.setContentType("text/html;charset=" + encoding);
           }
       }
      
       if (chain != null) {
           chain.doFilter(request, response);
       }
   }

struts2를 이용하면서도 이 필터는 잘 되었다.

허나 문제는 Ajax를 이용하여 서버측 액션을 한번 갔다오기만 하면 인코딩 방식이 변경이 된다.

그래서 다음의 필터에 Ajax를 이용하여 액션을 콜하면 위의 필터를 통하지 않겠금 하였다.

한번은 되는데 두번째 부터는 안된다.

위의 chain.doFilter(request, response); 이 부분만 지나면  euc-kr 에서 UTF-8 로 변경이 된다.

한참을 찾아보다 아래의 내용을 적용하고 위의 Encoding Filter를 빼버렸다.

<web-app id="WebApp_9" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

<filter>
    <filter-name>struts</filter-name>        
    <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
    <init-param>
        <param-name>struts.i18n.encoding</param-name>  
        <param-value>euc-kr</param-value>
    </init-param>
    <init-param>
        <param-name>struts.devMode</param-name>
        <param-value>true</param-value>
    </init-param>
</filter>
</web-app>

바로 한글문제가 해결되었다..ㅠㅠ

몇 시간을 허비했는징..ㅠㅠ

출처 : http://struts.apache.org/2.x/docs/constant-configuration.html