2012-01-23 4 views
2

Tomcat 7 &과 함께 스프링 프레임 워크를 사용하고 있습니다. UTF-8 인코딩을 사용하여 로컬 언어 용 양식 데이터를 제출하고 있습니다. 이것은 JSP를 통한 게시물을 사용하여 잘 작동합니다. 그러나 Ajax 기반 폼 제출을 사용하면 서버에 요청 매개 변수로 쓰레기 문자가 표시됩니다.Ajax를 사용하여 현지화 된 양식 제출

난 아무것도 놓치고 있으면 알려 주시기 바랍니다 .. 브라우저에 표시 할 데이터를 표현하기 위해 유니 코드를 사용하는 컨텐츠 인코딩 HTTP 헤더를 추가

** My Ajax Code** 

    xmlHttp.open("POST", "viewTeluguScript.htm", true); 
    //xmlHttp.setRequestHeader("Content-type", "multipart/form-data;charset=UTF-8"); 
    xmlHttp.setRequestHeader("Content-length", parameters.length); 
    // xmlHttp.setRequestHeader("Content-Type", "text/html;charset=UTF-8"); 
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded;charset=UTF-8"); 
    //xmlHttp.setRequestHeader("pageEncoding","UTF-8"); 
    //xmlHttp.setRequestHeader("accept-charset","UTF-8"); 
    xmlHttp.setRequestHeader("content-language","tel"); 
    xmlHttp.setRequestHeader("Connection", "close"); 
    xmlHttp.send(parameters); 


    **My Controller code** 

    public ModelAndView viewTeluguScript(HttpServletRequest request, HttpServletResponse response) throws SQLException, CannotGetJdbcConnectionException, Exception { 

    //textInfo = java.net.URLDecoder.decode(request.getParameter("teluguText"), "UTF-8"); 
    textInfo = request.getParameter("teluguText"); 
    /* StringBuffer jb = new StringBuffer(); 
    String line = null; 
    try { 
    BufferedReader reader = request.getReader(); 
    while ((line = reader.readLine()) != null) 
    jb.append(line); 
    } catch (Exception e) { 


    } 

    System.out.println("request is :::: "+jb.toString());*/ 


    ModelAndView mv = new ModelAndView("viewQuestions"); 
    //request.getSession().setAttribute("workingModule", "questions"); 
    return mv; 
    } 


     enter code here 

    **My web.xml** 
    <?xml version="1.0" encoding="UTF-8"?> 
    <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> 


     <context-param> 
      <param-name>contextConfigLocation</param-name> 
      <param-value> 

       /WEB-INF/applicationContext-security.xml 
       classpath:applicationContext-common-business.xml 
       classpath:applicationContext-common-authorization.xml 
      </param-value> 
     </context-param> 

     <filter> 
      <filter-name>encodingFilter</filter-name> 
      <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> 
      <init-param> 
       <param-name>encoding</param-name> 
       <param-value>UTF-8</param-value> 
      </init-param> 
      <init-param> 
       <param-name>forceEncoding</param-name> 
       <param-value>true</param-value> 
      </init-param> 
     </filter> 

     <locale-encoding-mapping-list> 
      <locale-encoding-mapping> 
       <locale>en</locale> 
       <encoding>UTF-8</encoding> 
      </locale-encoding-mapping> 
      <locale-encoding-mapping> 
       <locale>tel</locale> 
       <encoding>UTF-8</encoding> 
      </locale-encoding-mapping> 

     </locale-encoding-mapping-list> 


     <filter-mapping> 
      <filter-name>encodingFilter</filter-name> 
      <url-pattern>/*</url-pattern> 
     </filter-mapping> 

     <filter> 
      <filter-name>springSecurityFilterChain</filter-name> 
      <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class> 
     </filter> 
     <filter-mapping> 
      <filter-name>springSecurityFilterChain</filter-name> 
      <url-pattern>/*</url-pattern> 
     </filter-mapping> 
     <listener> 
      <listener-class>org.springframework.security.web.session.HttpSessionEventPublisher</listener-class> 
     </listener> 
     <listener> 
      <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
     </listener> 
     <servlet> 
      <servlet-name>g2l</servlet-name> 
      <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
      <!--<load-on-startup>2</load-on-startup>--> 
     </servlet> 
     <servlet-mapping> 
      <servlet-name>g2l</servlet-name> 
      <url-pattern>*.htm</url-pattern> 
     </servlet-mapping> 
     <!-- <session-config> 
      <session-timeout> 
       30 
      </session-timeout> 
     </session-config> 
     <welcome-file-list> 
      <welcome-file>redirect.jsp</welcome-file> 
     </welcome-file-list>--> 
    </web-app> 

답변

0

시도. 웹 서버에서 오는 리소스에는 http 헤더에 첨부 된 인코딩 정보가 선택적으로있을 수 있습니다. 콘텐츠 인코딩 헤더가있는 경우 브라우저는 응답 헤더의 인코딩을 사용하여 리소스를 내부 유니 코드 표현으로 변환합니다. 콘텐츠 인코딩 헤더가없는 경우 브라우저는 파일 인코딩이 리소스를 요청한 페이지와 동일하다고 간주합니다.

+0

시도한 xmlHttp.setRequestHeader ("콘텐츠 인코딩", "UTF-8"); 그러나 그것의 작동하지 않습니다. 귀하의 의견에 감사드립니다. – shravan

관련 문제