struts2乱码问题,纠结啊 求高手指点~~~~
今天小弟尝试搭建struts2环境,但是碰见了悲催的不算是乱码的乱码问题。
我只引入了struts2的相关包,struts2的配置文件struts.xml也设置了统一编码方式:
<constant name="struts.i18n.encoding" value="GBK" />
页面编码方式是GBK,java,jsp文件属性都是GBK。启动tomcat没报错,访问的时候页面也能显示中文,悲催的事情发生了,右键查看源文件出现这样的字符“中文”,ognl加上escape="false"属性后页面源文件显示正常,求高手解答这是为什么啊????难道是jar版本的问题?以前木有遇到过~~~
代码:
import com.opensymphony.xwork2.ActionSupport;
public class test extends ActionSupport {
private String fffd;
public String test(){
fffd = "中文";
return "success";
}
public String getFffd() {
return fffd;
}
public void setFffd(String fffd) {
this.fffd = fffd;
}
}
<%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
<%@taglib uri="/struts-tags" prefix="s" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<s:property value="fffd"/>
</body>
</html>
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<constant name="struts.i18n.encoding" value="GBK" />
<package name="protal" namespace="" extends="struts-default">
<action name="test" class="test">
<result name="success">/index.jsp</result>
</action>
</package>
</struts>
在然后把Runtime log file设为GBK
能解决你很多乱码问题。
试试吧
[其他解释]
有时候在JS里面引用struts标签时候,中文出现乱码,这个属性可以避免 同一个属性值被解析2次,所以可能会导致乱码
[其他解释]