Filter 웹에서.xml config를 읽을 때 중국어 인코딩 문제
4719 단어 web.xml
그러나 하나의 축적으로 간단하게 예를 들면 다음과 같다. 그 핵심 코드는 바로 new String(String.getBytes(charset 1),charset 이다.2)
1 public class SimpleFilter implements Filter {
2
3 private boolean enable = false;
4
5 public void init(FilterConfig config)
6 throws ServletException{
7 String enableString = config.getInitParameter("enable");
8 if (enableString != null && enableString.equalsIgnoreCase("true")) {
9 this.enable = true;
10 }
11 // xml ,
12 // , xml , iso-8859-1 ?
13 String initParam = config.getInitParameter("ref");
14 try {
15 initParam = new String(initParam.getBytes("iso-8859-1"), "UTF-8");
16 } catch (UnsupportedEncodingException e) {
17 e.printStackTrace();
18 }
19
20 System.out.println(this + ": init(), init-param = " + initParam);
21 }
22 public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
23 throws IOException, ServletException{
24 if (this.enable)
25 System.out.println(this + ": doFilter()") ;
26 chain.doFilter(request, response);
27 }
28 public void destroy(){
29 // clean up
30 }
31
32 }
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Browser handling mime-mappingmime-mapping is a node in web.xml, which is used to specify the browser processing method of the corresponding format. T...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.