jsp中的中文国际化问题 [英] Chinese internationalization issue in jsp

查看:122
本文介绍了jsp中的中文国际化问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在国际化的struts2.0应用程序中工作除了中文以外,它在其他语言中也能正常工作.

I am working in struts2.0 application with internationalization Apart from Chinese it working fine in other languages.

当我将中文字符放入jsp时,我在Action中没有得到相同的值.请同样帮我.

When I put Chinese character in jsp I am not getting same values in Action. Please help me for the same.

我还使用了UTF-8 pageEncoding

I have also used the UTF-8 pageEncoding

<%@page contentType="text/html" pageEncoding="UTF-8"%>

我在jsp中有一个文本框,在其中填充了一些汉字.

I have a text box in the jsp in which I'm filling some Chinese character.

但是在服务器端的Action类中,当我尝试检索文本框的值时,我得到的是垃圾字符.

But in the Action class on the server side when I try to retrieve the value of the text box,I'm getting junk characters.

我没有10个声望,因此无法添加屏幕截图.

I'm not able to add the screen shot as I don't have 10 reputations.

任何帮助将不胜感激.

推荐答案

在操作类中,在获取参数之前,将请求主体编码设置为与JSP的pageEncoding相同的编码.

In your action class before obtaining the parameters, set the request body encoding to the same encoding as the pageEncoding of the JSP.

request.setCharacterEncoding("UTF-8");

希望这会有所帮助!

P.S上述解决方案仅适用于POST请求.

P.S Above mentioned solution applies to POST request only.

编辑:

在操作类的调用方法中获取HttpServletRequest:

Get HttpServletRequest in calling method of your action class:

HttpServletRequest request = ServletActionContext.getRequest();

,然后如上所述设置request属性.

and then set request property as mentioned above.

EDIT2 :

将此行添加到您的JSP:

<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>

,并将此filter添加到您的web.xml中:

and add this filter in your web.xml:

<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>

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

这篇关于jsp中的中文国际化问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆