浏览 6590 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2004-08-11
webwork.i18n.encoding=utf-8 web.xml <?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd"> <web-app> <display-name>WebWork 2.0 Example App</display-name> <!-- <filter>--> <!-- <filter-name>webwork</filter-name>--> <!-- <filter-class>com.opensymphony.webwork.dispatcher.FilterDispatcher</filter-class>--> <!-- </filter>--> <filter> <filter-name>container</filter-name> <filter-class>com.opensymphony.webwork.lifecycle.RequestLifecycleFilter</filter-class> </filter> <filter-mapping> <filter-name>container</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <!-- <filter-mapping> <filter-name>webwork</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> --> <listener> <listener-class>com.opensymphony.webwork.lifecycle.ApplicationLifecycleListener</listener-class> </listener> <listener> <listener-class>com.opensymphony.webwork.lifecycle.SessionLifecycleListener</listener-class> </listener> <servlet> <servlet-name>webwork</servlet-name> <servlet-class>com.opensymphony.webwork.dispatcher.ServletDispatcher</servlet-class> </servlet> <servlet> <servlet-name>freemarker</servlet-name> <servlet-class>com.opensymphony.webwork.views.freemarker.FreemarkerServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet> <servlet-name>velocity</servlet-name> <servlet-class>com.opensymphony.webwork.views.velocity.WebWorkVelocityServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>freemarker</servlet-name> <url-pattern>*.ftl</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>webwork</servlet-name> <url-pattern>*.action</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>velocity</servlet-name> <url-pattern>*.vm</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>index.jsp</welcome-file> <welcome-file>default.jsp</welcome-file> <welcome-file>index.html</welcome-file> </welcome-file-list> <taglib> <taglib-uri>webwork</taglib-uri> <taglib-location>/WEB-INF/webwork.tld</taglib-location> </taglib> <taglib> <taglib-uri>benchmark</taglib-uri> <taglib-location>/WEB-INF/taglibs-benchmark.tld</taglib-location> </taglib> <taglib> <taglib-uri>c</taglib-uri> <taglib-location>/WEB-INF/c.tld</taglib-location> </taglib> </web-app> xwork.xml <action name="register" class="test.Register"> <result name="licence" type="velocity"> <param name="location">/template/licence.vm</param> </result> </action> licence.vm 比较大不贴了,里面没有任何变量,只是一个有中文的纯html文件,存为utf-8格式。 通过webwork调用的时候中文全变为乱码。 增加velocity.properties # Velocity Macro libraries. velocimacro.library = webwork.vm, tigris-macros.vm, myapp # set encoding/charset to UTF-8 input.encoding=UTF-8 output.encoding=UTF-8 default.contentType=text/html; charset=utf-8 还是乱码。 尝试改 webwork.i18n.encoding=iso-8859-1 输出不再是乱码,但是浏览器需要手工置为utf-8 编码设为gb-2312,gbk都是满平问号 jsp就毫无问题 请问这个如何才能使velocity模板里的中文正常显示? 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
发表时间:2004-08-11
try:
5, 对velocity的处理: in velocity.properties: # set encoding/charset to UTF-8 input.encoding=UTF-8 output.encoding=UTF-8 default.contentType=text/html; charset=utf-8 同时,在java代码中进行template render时,指定utf-8: VelocityEngine ve = ....; Template outty = getTemplate( "templateName", "UTF-8" ); |
|
返回顶楼 | |
发表时间:2004-08-11
输出不再是乱码,但是浏览器需要手工置为utf-8
这个问题,你跟踪一下你收到的http header。80%是header里面的值的问题 |
|
返回顶楼 | |
发表时间:2004-08-11
曹晓钢 写道 同时,在java代码中进行template render时,指定utf-8:
VelocityEngine ve = ....; Template outty = getTemplate( "templateName", "UTF-8" ); 我用的webwork2,要是改wekwork代码就失去通用型了吧。 不能通过配置解决吗? 我把设置了 webwork.i18n.encoding=iso-8859-1 http头自然是8859-1的,当然不能自动正确识别, 我的意思是, webwork.i18n.encoding=utf-8的时候, webwork好像是转过梭了吧 是不是有配置能解决这个问题,这方面的资料实在是不多啊 |
|
返回顶楼 | |
发表时间:2004-08-11
这个问题就要具体问题具体分析拉~反正webwork有完整的代码,如果有时间的话,你可以仔细查看一下代码,我相信一定是可以解决的。
解决后,如果能整理个demo出来,以利后来者,善莫大焉? 加油! |
|
返回顶楼 | |
发表时间:2004-08-12
可以写一个EncoderFilter来解决,我就是这么做的了。
WebWork2 + Velocity |
|
返回顶楼 | |