MyFacesExtensionsFilter javascript中文乱码
web.xml
<?xml version= "1.0 " encoding= "gb2312 "?>
<!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> faces </display-name>
<description> faces system </description>
<context-param>
<param-name> javax.faces.CONFIG_FILES </param-name>
<param-value> /WEB-INF/faces-config.xml </param-value>
</context-param>
<!-- MyFacesExtensionsFilter -->
<filter>
<filter-name> MyFacesExtensionsFilter </filter-name>
<filter-class>
org.apache.myfaces.webapp.filter.ExtensionsFilter
</filter-class>
<init-param>
<param-name> maxFileSize </param-name>
<param-value> 10m </param-value>
<description>
Set the size limit for uploaded files. Format: 10 - 10
bytes 10k - 10 KB 10m - 10 MB 1g - 1 GB
</description>
</init-param>
</filter>
<!-- extension mapping for adding <script/> , <link/> , and other resource tags to JSF-pages -->
<filter-mapping>
<filter-name> MyFacesExtensionsFilter </filter-name>
<!-- servlet-name must match the name of your javax.faces.webapp.FacesServlet entry -->
<servlet-name> Faces Servlet </servlet-name>
</filter-mapping>
<!-- extension mapping for serving page-independent resources (javascript, stylesheets, images, etc.) -->
<filter-mapping>
<filter-name> MyFacesExtensionsFilter </filter-name>
<url-pattern> /faces/myFacesExtensionResource/* </url-pattern>
</filter-mapping>
<!-- MyFacesExtensionsFilter -->
<servlet>
<servlet-name> Faces Servlet </servlet-name>
<servlet-class> javax.faces.webapp.FacesServlet </servlet-class>
<load-on-startup> 1 </load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name> Faces Servlet </servlet-name>
<url-pattern> *.faces </url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file> index.html </welcome-file>
</welcome-file-list>
</web-app>
测试页面test.jsp
<%@ page contentType= "text/html; charset=gb2312 "%>
<%@ taglib uri= "http://java.sun.com/jsf/html " prefix= "h "%>
<%@ taglib uri= "http://java.sun.com/jsf/core " prefix= "f "%>
<%@ taglib uri= "http://myfaces.apache.org/tomahawk " prefix= "t "%>
<html>
<head>
<title> MyJSF 程序 </title>
<!--
<link rel= "stylesheet " type= "text/css " href= "styles.css ">
-->
<%
request.setCharacterEncoding( "gb2312 ");
String id = request.getParameter( "id ");
%>
<script language= "javascript " type= "text/javascript " charset= "gb2312 ">
function test(){
alert( '你好!aaa ');
}
</script>
</head>
<body>
<f:view>
This is my JSF JSP page. <br>
id= <%=id%> <br>
<a href= "test.faces?id=中文 "> 111 </a>
<a href= "test.faces?id=english "> 112 </a>
<br/>
<input type= "button " value= "js " onclick= "test() "/>
</f:view>
</body>
</html>
测试页面test.jsp中点js按钮出现乱码,如附件
如果web.xml配置文件中,去掉 <!-- MyFacesExtensionsFilter --> 中间的代码,
点js按钮正常显示“你好!aaa”
请问各位高手如何解决这个问题,先谢谢了
[解决办法]
see see
[解决办法]
沒碰到進,頂一下
期待樓下的牛人
[解决办法]
没高手来定,我自己顶
[解决办法]
<filter>
<filter-name> MyFacesExtensionsFilter </filter-name>
<filter-class>
org.apache.myfaces.webapp.filter.ExtensionsFilter
</filter-class>
</filter>
应该是这个过滤器的问题,你把它去掉然后自己写一个过滤器用来过滤页面和servlet
[解决办法]
把“你好”2个字做成一个字符串传进去!
String nihao= "你好 ";
nihao=new String(nihao.getBytes( "ISO8859-1 "));
试试看行不行
[解决办法]
TO
zjf405(On№The①Road)
谢谢!
我知道是过滤起的原因,去掉 <!-- MyFacesExtensionsFilter --> 中间的代码就没问题了.
但是我要用myface的一些功能组件,如tree2等,而用myface tree2 组件的前提是一定要用哪个过滤起,myface官方网站apache 上有说明
所以自己写一个过滤器来替换该过滤器不可行.
TO tomiehu
谢谢!
你的方法我也试过上百回了,是不行的.