用js如何将url带的特殊字符传到后台???急!急!急!在线等!请高手指教!
解决方案 »
- 怎么打开windows图片查看器
- 聊天室的困惑
- ■■■■■■■路径修改后,页面显示不出来
- 求教el表达式的多层取值问题,求围观........
- jsp在处理mysql字段中字串截取问题
- 请帮忙推荐一本关于JSP的书
- dom,或者sax解析器在解析验证引用了dtd文档的xml文件时候,一定需要先访问其中地址所指向的dtd文档吗?虚心请教大家
- 各位大哥这个是什么错误啊Exception starting filter SetCharsetEncodingFilter?
- jsp中怎么表示相对路径啊,,小问题,,在线等,马上给分
- ORACLE的JDBC是哪一个?
- 请教关于applet
- 哪位高手帮帮忙? JSP+TOMCAT 报错HTTP Status 500
这段代码假设是在index.jsp这个页面里面的,在输出这段话的时候就要做编码处理了(即在index.jsp里面处理)。如下
<%
String urlNotEncoded="/dosomething.jsp?par=abc&abc";
String urlEncoded=java.net.URLEncoder.encode(urlNotEncoded);
out.println("window.location="+urlEncoded);
%>
function fun(){
window.location = "a.action?title='我我我'";
}
title属性在后台得到的是乱码 如何才能在前台就给它做处理从而在后台能得到“我我我”。
急急急!!!
前台 JS:userName = encodeURIComponent(userName);
var url = "xxxAction.do?userName=" + userName;
后台:
1、Action 代码public ActionForward excute(ActionMapping mapping,
ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws IOException {
response.setCharacterEncoding("UTF-8"); String userName = request.getParameter("userName"); // 转换编码
userName = EncodeUtil.changeCharacterEncode(userName, "ISO8859-1",
"utf-8"); PrintWriter pw = response.getWriter(); for (String name : nameArray) {
if (name.equalsIgnoreCase(userName)) {
pw.write("用户名已注册!");
return null;
}
} pw.write("用户名可用!"); return null;
} 2、EncodeUtil(转码类)import java.io.UnsupportedEncodingException;public class EncodeUtil { /**
* 转换编码
*
* @param srcString
* 待转码的字符串(源字符串)
* @param srcEncode
* 源字符串的编码
* @param targetEncode
* 目标编码
* @param defaultValue
* 如果待转码字符串为 null 则返回的默认值
*
* @return 编码后的字符串
*
*/
public static String changeCharacterEncode(String srcString,
String srcEncode, String targetEncode, String defaultValue) {
if (srcString == null) {
return defaultValue;
} try {
return new String(srcString.getBytes(srcEncode), targetEncode);
} catch (UnsupportedEncodingException e) {
throw new EncodeException(e);
}
} /**
* 转换编码
*
* @param srcString
* 待转码的字符串(源字符串)
* @param srcEncode
* 源字符串的编码
* @param targetEncode
* 目标编码
*
* @return 编码后的字符串
*
*/
public static String changeCharacterEncode(String srcString,
String srcEncode, String targetEncode) {
return changeCharacterEncode(srcString, srcEncode, targetEncode, "");
}
}
试试。
window.location.href = "a.action?title="+encodeURIComponent('我我我');
}
如下: <Connector port="8088" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" URIEncoding=“UTF-8” />