项目中使用spring sturts action 传值 出现乱码 而且google浏览器中没乱码 ie下传值乱码
在jsp中使用getJson传值
$.getJSON("<%=basePath%>/query/searchCompareTable?geneName="+geneName+"&fieldName="+fieldName+"&minValue="+minValue+"&maxValue="+maxValue,function(datatable) {
java中 action接收为set接收
private String geneName; private String fieldName; private double minValue; private double maxValue; public void setGeneName(String geneName) { this.geneName = geneName; } public void setFieldName(String fieldName) { this.fieldName = fieldName; } public void setMinValue(double minValue) { this.minValue = minValue; } public void setMaxValue(double maxValue) { this.maxValue = maxValue; }
这个时候服务器的tomcat的server.xml配置 已经设置成 utf-8
jsp页面头部为
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/"; %> <%@taglib prefix="s" uri="/struts-tags"%> <!DOCTYPE html> <html> <head> <base href="<%=basePath%>"> <meta charset="UTF-8"> <title>gseInfo</title> <link type="text/css" rel="stylesheet" href="css/skin.css" /> <link type="text/css" rel="stylesheet" href="css/genesboxUI.css" /> <script type="text/javascript" src="js/jquery-1.10.2.min.js"></script> <script src="js/controls.js"></script> <script> document.createElement('header'); document.createElement('nav'); document.createElement('aside'); document.createElement('section'); </script>
这个时候发现 中文参数 乱码
解法一
解决办法
jsp中 getJson 中英文参数加上一次转码
encodeURI(geneName)
$.getJSON("<%=basePath%>/query/searchCompareTable?geneName="+encodeURI(geneName)+"&fieldName="+encodeURI(fieldName)+"&minValue="+minValue+"&maxValue="+maxValue,function(datatable) {
action中不解码
解法二
解决办法
jsp中 getJson 中英文参数加上两次转码
encodeURI(encodeURI(geneName))
encodeURI(encodeURI(fieldName))
如下:
$.getJSON("<%=basePath%>/query/searchCompareTable?geneName="+encodeURI(encodeURI(geneName))+"&fieldName="+encodeURI(encodeURI(fieldName))+"&minValue="+minValue+"&maxValue="+maxValue,function(datatable) {
action中解码
compareResultHtml=""; try { geneName=URLDecoder.decode(geneName,"utf-8"); fieldName=URLDecoder.decode(fieldName,"utf-8"); } catch (UnsupportedEncodingException e1) { e1.printStackTrace(); }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。