前段时间我在用window.open传递参数时老出现乱码,我整体都用的UTF-8编码
<td nowrap><a href="#" onclick="openScript('AudioShiTing.jsp?AudioPath='+encodeURIComponent('<%=str_4%>'),'pur',400,300)">试听</a></td>
然后一位高人说要用encodeURIComponent于是就用上面的方法解决了,现在用普通的页面传递时<a href="ImageShow.jsp?image_path=<%=imagePath%>" target="_blank";><img src=<%=imagePathsmall%> alt=""/>这里面的imagePath可能为中文字符串,有的字符能够解析,譬如说咖啡,但是如果咖啡后面再加个豆,咖啡能解析但是豆是乱码,所以我还想采用encodeURIComponent的方法,但是<a href="ImageShow.jsp?image_path=<%=imagePath%>" target="_blank";><img src=<%=imagePathsmall%> alt=""/>不知道怎么改了,关键是加上encodeURIComponent就不知道怎么写了,希望大家能够帮帮我,小弟在此先谢了
<td nowrap><a href="#" onclick="openScript('AudioShiTing.jsp?AudioPath='+encodeURIComponent('<%=str_4%>'),'pur',400,300)">试听</a></td>
然后一位高人说要用encodeURIComponent于是就用上面的方法解决了,现在用普通的页面传递时<a href="ImageShow.jsp?image_path=<%=imagePath%>" target="_blank";><img src=<%=imagePathsmall%> alt=""/>这里面的imagePath可能为中文字符串,有的字符能够解析,譬如说咖啡,但是如果咖啡后面再加个豆,咖啡能解析但是豆是乱码,所以我还想采用encodeURIComponent的方法,但是<a href="ImageShow.jsp?image_path=<%=imagePath%>" target="_blank";><img src=<%=imagePathsmall%> alt=""/>不知道怎么改了,关键是加上encodeURIComponent就不知道怎么写了,希望大家能够帮帮我,小弟在此先谢了
解决方案 »
- java如何操作shp文件
- 高手接分,大大的分---》java 手机
- 请教如何提取<a href=http://www.china.com/2003-10-28/113/314.html target=_blank>中href的值
- struts入门问题! 请教各位!
- smartupload有没有办法上传文件到其它服务器
- 我怎么感觉struts,非常难用呢!!! (降低了开发效绿.)
- struts hidden错误,,跪求达人帮忙解达,谢谢
- 如何在Jbuilder自带的Tomcat中配置JDBC,使WebApp工程中的jsp可以调用JDBC?
- 空指针问题,救命呀!
- 请教带有数字页码的分页问题
- 从页面修改数据库的功能 无法实现.求助
- javamail发送邮件的问题!
在web.xml中配置
<!-- codefilter -->
<filter>
<filter-name>EncodingFilter</filter-name>
<filter-class>org.apache.commons.filters.SetCharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>ignore</param-name>
<param-value>false</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>EncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- end codefilter --> 引入 commons-filters.jar
$(document).ready(function(){
var abc= encodeURIComponent(中文路径)
$("img").attr({
src: abc",
title: "jQuery",
alt: "jQuery Logo"
});
}
)
延缓了你的页面速度,不如写组件。
pageEncoding="UTF-8"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">加上过滤器基本就能解决显示问题。文件一概UTF-8处理。
在tomcat,conf文件里
server.xml里Connector标签下加上URIEncoding="UTF-8"也可以试试...
这个我目前做了的:在conf文件夹下修改server.xml的<Connector port="8080" protocol="HTTP/1.1" maxThreads="150" connectionTimeout="20000" redirectPort="8443" URIEncoding="utf-8">,在每个接受和发送页面都有<%@ page contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>并且还有 request.setCharacterEncoding("utf-8"); response.setCharacterEncoding("utf-8");还是解决不了问题的,我想要做的是保证<a href="ImageShow.jsp?image_path= <%=imagePath%>" target="_blank";> <img src= <%=imagePathsmall%> alt=""/>传递参数image_path没乱码imagePathsmall图片显示没乱码,还有保证window.open参数传递也没乱码,就这几个要求,后两个已经通过上面方法实现了,现在就剩下第一个解决不了
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.UnavailableException;/**
* @author Administrator
*
* TODO 要更改此生成的类型注释的模板,请转至
* 窗口 - 首选项 - Java - 代码样式 - 代码模板
*/
public class SetCharacterEncodingFilter implements Filter {
protected String encoding = null;
protected FilterConfig filterConfig = null;
protected boolean ignore = true; public void destroy() {
this.encoding = null;
this.filterConfig = null;
}public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain)
throws IOException, ServletException { // Conditionally select and set the character encoding to be used
if (ignore || (request.getCharacterEncoding() == null)) {
String encoding = selectEncoding(request);
if (encoding != null)
request.setCharacterEncoding(encoding);
} // Pass control on to the next filter
chain.doFilter(request, response);}public void init(FilterConfig filterConfig) throws ServletException { this.filterConfig = filterConfig;
this.encoding = filterConfig.getInitParameter("encoding");
String value = filterConfig.getInitParameter("ignore");
if (value == null)
this.ignore = true;
else if (value.equalsIgnoreCase("true"))
this.ignore = true;
else if (value.equalsIgnoreCase("yes"))
this.ignore = true;
else
this.ignore = false;}protected String selectEncoding(ServletRequest request) {
return (this.encoding);
}}
//配置web.xml<!-- Set Character Encoding-->
<filter>
<filter-name>Set Character Encoding</filter-name>
<filter-class>myAddrBook.SetCharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>GBK</param-value>
</init-param>
</filter><filter-mapping>
<filter-name>Set Character Encoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping> <!-- Set Character Encoding-->
加上这个貌似我以前的参数传递都会出问题,也不知道该怎么解决了,大家帮忙看看