2008/01/20 22:20
[Moneyplanner] request 한글 깨짐 현상 해결(reeust encoding)
2008/01/20 22:20 in Portfolio/MoneyPlanner

<ServiceFilter.java>
/**
* initialize filterConfig( which has init-parameter)
*/
public void init(FilterConfig filterConfig) throws ServletException {
this.filterConfig = filterConfig;
log.debug("ServiceFilter is initialized.");
/**
* 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 {
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;
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);
}
}
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);
ServiceContext.init((HttpServletRequest) servletRequest,
(HttpServletResponse) servletResponse);
// chain to next filter
filterChain.doFilter(servletRequest, servletResponse);
filterChain.doFilter(servletRequest, servletResponse);
// destory ServietContext and ClientObjectMap
ServiceContext.destory();
ContextHolder.clear();
}
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>
<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 한글 깨지는 현상 해결...
'Portfolio > MoneyPlanner' 카테고리의 다른 글
| 고민 고민... Service Layer와 DAO들의 상호 관계? (0) | 2008/02/05 |
|---|---|
| [MoneyPlanner] Ajax로 분류선택 구현 - dwr실패... (1) | 2008/01/23 |
| [Moneyplanner] request 한글 깨짐 현상 해결(reeust encoding) (0) | 2008/01/20 |
| [MoneyPlanner] sitemesh 첫적용 - 계좌관리 (0) | 2008/01/18 |
| threadLocal이라는 개념... (0) | 2008/01/11 |
| [MoneyPlanner] 지출분류 선택 Ajax로 재구현 (0) | 2007/11/19 |


Prev
Rss Feed