easyui的datagrid表格reload屬性傳入中文引數亂碼問題
直接給你們上程式碼吧:
<%@ page language="java" import="java.util.*" pageEncoding="gbk"
isELIgnored="false" contentType="text/html; charset=gbk"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk" />
<title></title>
<base href="<%=basePath%>" />
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/easyui/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/easyui/themes/icon.css">
<script type="text/javascript" src="${pageContext.request.contextPath}/easyui/jquery.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/easyui/jquery.easyui.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/easyui/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/easyui/validator.js"></script>
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/css.css">
<script type="text/javascript" src="${pageContext.request.contextPath}/js/function.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/json2.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/work.js"></script>
</head>
<body class="easyui-layout" >
<div data-options="region:'center'" >
<div class="easyui-layout" data-options="border:true,fit:true">
<div class="easyui-panel" data-options="region:'north',title:'當前位置:泵站管理所 - 下月計劃列表',collapsible:true,border:true,collapsed:false" style="height:80px;overflow: hidden" >
<form id="frmQuery" action="" method="post" >
<table id="tableQuery" style="margin: 10px;text-align:right;overflow:hidden">
<tr>
<td nowrap="nowrap" ><div><label>標題:</label>
<input class="easyui-validatebox" type="text" name="title" style="width: 100px"></input>
</div></td>
<td nowrap="nowrap"> <div><label>開始時間:</label>
<input class="easyui-datetimebox" name="startTime" id="startTime" style="width: 140px" data-options="validType:'dateTime'"></input></div></td>
<td nowrap="nowrap"><div><label>結束時間:</label>
<input class="easyui-datetimebox" name="endTime" style="width: 140px" data-options="validType:'dateTime'"></input>
</div></td>
<td style="text-align:center;" nowrap="nowrap"><div style="width:100px">
<a href="javascript:queryByParams()"
</div></td>
</tr>
</table>
</form>
</div>
<div class="easyui-panel" data-options="region:'center'" >
<table id="table" >
</table>
</div>
</div>
</div>
</body>
<script type="text/javascript">
$(document).ready(function(){
$('#table').datagrid({
id: 'dg',
title: '下月計劃列表',
idField: 'id',
fit: true,
pagination: true,
rownumbers: true,
fitColumns: false,
singleSelect: true,
checkOnSelect: false,
selectOnCheck: false,
striped: true,
pageSize: 10,
pageList: [10,30,50],
url: 'bzgls/next_list.action',
columns: [[
{field:'ck', checkbox:true},
{field: 'title', title: '標題', width: 100},
{field: 'unit', title: '單位', width: 150 },
{field: 'plantime', title: '時間', width: 150,formatter: function(value, rec) {
return formatDate(turnServerDate(value));}}
]],
onBeforeLoad: function(param) {
param['page'] = $('#table').datagrid('getPager').pagination('options')['pageNumber'];
param['rows'] = $('#table').datagrid('getPager').pagination('options')['pageSize'];
}
});
var pager = $('#table').datagrid('getPager');
$(pager).pagination({
onSelectPage: function(pageNumber, pageSize) {
queryByParams();
}
});
});
function queryByParams() {
if (!$('#frmQuery').form('validate')) {
alert("查詢條件有誤,請重新輸入");
return;
}
var params = new Object();
$('#tableQuery').find('input,select').each(function(k, v) {
if ($(v).attr("name") != undefined) {
params[$(v).attr('name')] = $.trim($(v).val());
}
});
$('#table').datagrid('reload', {
orderBy: 'id',
json: encodeURI(JSON.stringify(params))
});
$('#table').datagrid('unselectAll');
$('#table').datagrid('uncheckAll');
}
</script>
</html>
重點是看紅色部分的內容
在js的方法queryByParams中
特別注意帶有下劃線的那一行,使用encodeURI進行編碼
在後臺的action中,
首先得有json這個變數,和它的get、set方法
在使用的時候需要進行處理一下
if(json != null && !"".equals(json)){
try {
json = URLDecoder.decode(json, "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
這樣得到的json格式的資料就不是亂碼了。
相關推薦
easyui的datagrid表格reload屬性傳入中文引數亂碼問題
直接給你們上程式碼吧: <%@ page language="java" import="java.util.*" pageEncoding="gbk" isELIgnored="false" contentType="text/html; charset=gbk"
js 連結傳入中文引數亂碼解決
傳入時,可能出現中文的引數用encodeURI進行兩次轉碼,如: lethref="http://www.zzdblog.cn?keyword='+encodeURI(encodeURI(keywordCH))'"; 接受時,使用decodeURI將引數進行解碼,如: l
Jsp頁面中位址列引數傳入中文的亂碼問題
最近寫一些東西,使用超連結在位址列裡傳入中文後,遇見了一些亂碼問題,查了一些資料,做一些總結。 一、Get提交方式產生的亂碼 原因:瀏覽器首先會將這些中文字元進行編碼然後再發送給伺服器,位址列中所輸入的URL包含中文字元時,瀏覽器會將它們轉 換為 application/x-www-form
h5傳中文引數亂碼問題
獲取url中引數函式,有可能會有中文引數,這時就需要用decodeURI解碼下 const getUrlParam = function (name) { var url = location.href; //獲取url中"?"符後的字串 if (url.inde
ajax get請求中文引數亂碼解決
問題描述:使用ajax向後臺傳中文引數時出現亂碼 解決方案: 第一種方法: 由於tomcat預設的字符集是ISO-8859-1,修改Tomcat中的server.xml,在port為8080(也可以是不同的埠)的Connector中加入屬性: URIEncoding="
location.href 傳中文引數亂碼問題
傳中文查詢亂碼問題 則需要對要傳的引數進行二次編碼 例如 window.location.href ="reg.html?mid="+mid+""; 這樣子則會亂碼 改成 window.location.href ="reg.html?mid="+
解決ajax get方式提交中文引數亂碼問題
https://blog.csdn.net/memoryzxj/article/details/50715633 一般情況下, 傳送 encodeURIComponent(parmeName)+"="+encodeURIComponent(parmeValue); 接收時, 直接 String
IE下get方式傳中文引數亂碼解決方法
亂碼原因:瀏覽器在傳遞url的時候,會使用自己的編碼格式對地址進行編碼,如果瀏覽器所使用編碼與伺服器採用編碼不一致,伺服器接收到的引數就會出現亂碼。在firefox,chrome下正常,ie下會出現亂碼。 解決方法:使用js encodeURI 對地址進行統一編碼, &n
jmeter--中文引數亂碼問題
中文引數亂碼問題,表現如下圖: 網上找了一些資料,最終在同事幫助下解決。 使用反編譯工具檢視並修改原始碼遇到的問題:依賴庫太多、反編譯出來有很多警告、甚至還有程式碼段直接顯示???,這樣就無法打包。
JavaWeb解決url中中文引數亂碼以及cookie中中文亂碼問題
今天來專門寫一篇博文記錄JavaSE中的URLEncoder類,因為已經兩次用這個類解決了自己遇到的棘手問題。第一次是之前做視訊網站的搜尋功能的時候,第二次是今天在做登入功能登入後錄入中文cookie時出現java.lang.IllegalArgumentEx
gdal for android 開發包,欄位屬性為中文出現亂碼
GDAL Android庫,建立shp,如果欄位屬性需要中文,網上的解決方法都是 gdal.SetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); gdal.SetConfigOption("SHAPE_ENCODING", "U
利用swagger-ui頁面傳送POST請求引數遇到的中文引數亂碼的問題
前端時間將同事開發的半成品專案介面做成視覺化介面,即swagger-ui,用於展示。這個如何配置我就不多說了,網上相關的教程應該也是一搜一大堆...... 本地測試了相關介面後,除了幾個介面返回: {"resultData":"","serviceTime":15172
java後臺解決get請求url中文引數亂碼
解決的程式碼如下 String keyword = request.getParameter("keyword"); keyword = new String(keyword.getBytes("iso-8859-1"), "utf-8"); get請求提交的引數是在位址列
jquery ajax傳遞中文引數亂碼問題及解決方案
jQuery傳遞中文引數亂碼,原因是預設的傳遞方式沒有采用UTF-8,所有我們可以在傳遞引數的時候對引數進行編碼,然後再操作,程式碼如下,紅色的程式碼為傳遞的引數,已標註 smsubmitclick = function(){ $(document).ready(func
springMVC重定向時引數傳遞及中文引數亂碼問題
springMVC重定向時,若需要帶引數,如果直接用return "redirect:/items?g="+group的話,一者跳轉時引數可見不安全,二者,中文引數可能會亂碼,此時可在當前方法入參中加入RedirectAttributes attr,然後在方法體中用attr
el表示式獲取url中文引數亂碼
1.解決方法:改變tomcat檔案server.xml標籤connector的編碼 <Connector URIEncoding="utf-8" connectionTimeout="20000" port="8089" protocol="HTTP/1.1" red
Spring MVC 自帶的字元編碼過濾器以及Tomcat字元編碼設定,徹底解決中文引數亂碼問題
一、Spring MVC字元編碼配置 java Web專案新增Spring支援後,可使用Spring自帶的字元編碼過濾器。原始碼在spring-web-4.1.0.RELEASE.jar包下的org.springframework.web.filter目錄的Characte
零xml配置Spring MVC過濾器解決中文引數亂碼
由於JSP預設的字元編碼為ISO-8859-1,如果request中有中文的話會出現亂碼,因此可以使用過濾器設定request的編碼 Spring MVC中提供了一個CharacterEncodingFilter,顧名思義就是用來做字元編碼的過濾器。因此可以自
servlet get請求中文引數亂碼
今天無意中突然對get請求時中文亂碼的解決方法有了興趣,以前只是會用,卻不知道其中的原理,於是自己研究了一番,先來看後臺程式碼 protected void doGet(HttpServletRequest request, HttpServletResponse resp
ASP.NET開發過程中遇到GET請求中文引數亂碼問題的解決辦法
直接上程式片碼 頁面請求部分 (使用 encodeURI方法轉換中文請求內容 ) : var URL = "http://localhost:8080/index.aspx?keyword=" + encodeURI($("#_keyword").val()); 後臺接