jsp URL 传参数 服务端接收后乱码的问题
jsp页面:
View Code
1 //查询
2 function search() {
3 var projectId = $("#projIDSort").val();
4
5 var voltageLevel = $("#voltageSort").val();
6 var equipCate = $("#equCateSort").val();
7
8 var url = "$(ctx)/projectDataQueryAction!searchProjectEquInfo.action?projectId="
9 + encodeURIComponent(projectId);
10 if (voltageLevel != "-1") {
11 url += "&voltageLevel=" + encodeURIComponent(voltageLevel);
12 if (equipCate != "-1") {
13 url += "&equipCate=" + encodeURIComponent(equipCate);
14 }
15 else{
16 url += "&equipCate=-1";
17 }
18 } else {
19 url += "&voltageLevel=-1";
20 if (equipCate != "-1") {
21 url += "&equipCate=" + encodeURIComponent(equipCate);
22 }
23 else{
24 url += "&equipCate=-1";
25 }
26 }
27 $('#datagrid').datagrid('options').url = encodeURI(url);
28 $('#datagrid').datagrid('reload');
29
30 }
2 function search() {
3 var projectId = $("#projIDSort").val();
4
5 var voltageLevel = $("#voltageSort").val();
6 var equipCate = $("#equCateSort").val();
7
8 var url = "$(ctx)/projectDataQueryAction!searchProjectEquInfo.action?projectId="
9 + encodeURIComponent(projectId);
10 if (voltageLevel != "-1") {
11 url += "&voltageLevel=" + encodeURIComponent(voltageLevel);
12 if (equipCate != "-1") {
13 url += "&equipCate=" + encodeURIComponent(equipCate);
14 }
15 else{
16 url += "&equipCate=-1";
17 }
18 } else {
19 url += "&voltageLevel=-1";
20 if (equipCate != "-1") {
21 url += "&equipCate=" + encodeURIComponent(equipCate);
22 }
23 else{
24 url += "&equipCate=-1";
25 }
26 }
27 $('#datagrid').datagrid('options').url = encodeURI(url);
28 $('#datagrid').datagrid('reload');
29
30 }
服务端:
View Code
1 public String searchProjectEquInfo() throws IOException {
2 //@SuppressWarnings("unused")
3 String equipcate = java.net.URLDecoder.decode(equipCate, "utf-8");
4 List list = projectDataQueryService.getProjectEquInfoByList(projectId,
5 voltageLevel,equipcate );
6
7 int count = list.size();
8 List tempList = new ArrayList();
9 HttpServletRequest request = ServletActionContext.getRequest();
10 HttpServletResponse response = ServletActionContext.getResponse();
11 response.setHeader("charset", "UTF-8");
12 response.setCharacterEncoding("UTF-8");
13 response.setContentType("text/xml;charset=UTF-8");
14 PrintWriter out = response.getWriter();
15 String page = request.getParameter("page");// 当前页
16 String rows = request.getParameter("rows");// 每页显示记录数
17 if (rows != null) {
18 pageSize = Integer.parseInt(rows);
19 } else {
20 pageSize = 10;
21 }
22 if (page != null) {
23 pageNum = Integer.parseInt(page);
24 } else {
25 pageNum = 1;
26 }
27 int pagenum = pageNum.intValue();
28 int pagesize = pageSize.intValue();
29 Object[] arr = list.toArray();
30 int pageNum = pagenum;
31 int pageSize = pagesize;
32 for (int i = (pageNum - 1) * pagesize; i < (pageNum - 1) * pagesize
33 + pageSize; i++) {
34 int totalNum = arr.length;
35 if (i < totalNum) {
36 tempList.add((EquipInfo) arr[i]);
37 } else {
38 break;
39 }
40 }
41 result.setPageNo(pagenum);
42 result.setPageSize(pagesize);
43 result.setRowCount(count);
44 result.setResult(tempList);
45 String json = JsonUtil.toJSON(result);
46 out.write(json);
47 out.flush();
48 out.close();
49 return null;
50 }
2 //@SuppressWarnings("unused")
3 String equipcate = java.net.URLDecoder.decode(equipCate, "utf-8");
4 List list = projectDataQueryService.getProjectEquInfoByList(projectId,
5 voltageLevel,equipcate );
6
7 int count = list.size();
8 List tempList = new ArrayList();
9 HttpServletRequest request = ServletActionContext.getRequest();
10 HttpServletResponse response = ServletActionContext.getResponse();
11 response.setHeader("charset", "UTF-8");
12 response.setCharacterEncoding("UTF-8");
13 response.setContentType("text/xml;charset=UTF-8");
14 PrintWriter out = response.getWriter();
15 String page = request.getParameter("page");// 当前页
16 String rows = request.getParameter("rows");// 每页显示记录数
17 if (rows != null) {
18 pageSize = Integer.parseInt(rows);
19 } else {
20 pageSize = 10;
21 }
22 if (page != null) {
23 pageNum = Integer.parseInt(page);
24 } else {
25 pageNum = 1;
26 }
27 int pagenum = pageNum.intValue();
28 int pagesize = pageSize.intValue();
29 Object[] arr = list.toArray();
30 int pageNum = pagenum;
31 int pageSize = pagesize;
32 for (int i = (pageNum - 1) * pagesize; i < (pageNum - 1) * pagesize
33 + pageSize; i++) {
34 int totalNum = arr.length;
35 if (i < totalNum) {
36 tempList.add((EquipInfo) arr[i]);
37 } else {
38 break;
39 }
40 }
41 result.setPageNo(pagenum);
42 result.setPageSize(pagesize);
43 result.setRowCount(count);
44 result.setResult(tempList);
45 String json = JsonUtil.toJSON(result);
46 out.write(json);
47 out.flush();
48 out.close();
49 return null;
50 }