点击A页面中的按钮,弹出B页面,同时URL中带有参数,参数值有汉字,在B页面中如何正确获得汉字?
说明:
1、A页面中<%@ page contentType="text/html; charset=GBK" %>
2、B页面中<%@ page contentType="text/html; charset=UTF-8" %>
因为在B页面中主要调用一Ocx控件,要输入汉字只有用UTF-8;在弹出B页面中的URL里的参数中汉字还是正常显示的,只是在B页面中获得时就成了乱码,如下:
B页面URL:http://localhost/FireInfo/tree.jsp?type=1&value=7,1,罗湖1中队;8,1,罗湖2中队;9,2,福田1中队;10,2,福田2中队;11,2,福田3中队;12,3,南山1中队;1,0,罗湖大队;2,0,福田大队;3,0,南山大队;4,0,盐田大队;5,0,D005;6,0,D006;
JSTL获得的参数value的值为:7,1,ÂÞºþ1ÖжÓ;8,1,ÂÞºþ2ÖжÓ;9,2,¸£Ìï1ÖжÓ;10,2,¸£Ìï2ÖжÓ;11,2,¸£Ìï3ÖжÓ;12,3,ÄÏɽ1ÖжÓ;1,0,ÂÞºþ´ó¶Ó;2,0,¸£Ìï´ó¶Ó;3,0,ÄÏɽ´ó¶Ó;4,0,ÑÎÌï´ó¶Ó;5,0,D005;6,0,D006;(注:经过c:out输出得到的)
说明:
1、A页面中<%@ page contentType="text/html; charset=GBK" %>
2、B页面中<%@ page contentType="text/html; charset=UTF-8" %>
因为在B页面中主要调用一Ocx控件,要输入汉字只有用UTF-8;在弹出B页面中的URL里的参数中汉字还是正常显示的,只是在B页面中获得时就成了乱码,如下:
B页面URL:http://localhost/FireInfo/tree.jsp?type=1&value=7,1,罗湖1中队;8,1,罗湖2中队;9,2,福田1中队;10,2,福田2中队;11,2,福田3中队;12,3,南山1中队;1,0,罗湖大队;2,0,福田大队;3,0,南山大队;4,0,盐田大队;5,0,D005;6,0,D006;
JSTL获得的参数value的值为:7,1,ÂÞºþ1ÖжÓ;8,1,ÂÞºþ2ÖжÓ;9,2,¸£Ìï1ÖжÓ;10,2,¸£Ìï2ÖжÓ;11,2,¸£Ìï3ÖжÓ;12,3,ÄÏɽ1ÖжÓ;1,0,ÂÞºþ´ó¶Ó;2,0,¸£Ìï´ó¶Ó;3,0,ÄÏɽ´ó¶Ó;4,0,ÑÎÌï´ó¶Ó;5,0,D005;6,0,D006;(注:经过c:out输出得到的)
解决方案 »
- 连接MSSQL出错
- 谁有手机库存进销管理系统急
- 关于提取某字符串的问题!!!!!!!!!!!!!!
- JbuilerX运行Structs1.1出现问题,几天都没有解决!急!
- %%%% Error Creating SessionFactory %%%%
- 使用JAVAMAIL收邮件时的问题,望高手们赐教!!!(高分求教)
- 请问JSP里面有没有类似ASP的Application变量一样的对象
- MySQL数据库查询问题
- 想把显示出来的数据导出到EXCEL中能用script实现吗 需要详细代码谢谢
- 如何使JSP网页打开后停留几秒钟后,转向其他页?
- 请问大家都用什么JSP开发工具?
- 急啊``在线等``大家来看看
<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib uri="WEB-INF/c.tld" prefix="c" %>
<%@ taglib uri="WEB-INF/fmt.tld" prefix="fmt" %>
<c:set var="type" value="${param.type}"/>
<c:set var="strValue" value="${param.value}"/> *****获得带有汉字的参数值***
<c:out value="${type}"/>
<c:out value="${strValue}"/>
<c:choose>
<c:when test="${type eq '1'}">
<c:set var="strFirst" value="辖区单位"/>
</c:when>
</c:choose>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title><c:out value="${strFirst}"/></title>
<script language='javascript'>
<!--
function cmdOK()
{
if(uclTree.TreeNodeKey!="0000"){
window.opener.frm.plcStation.value=TreeView.TreeNodeKey;
window.opener.frm.plcStationText.value=TreeView.TreeNodeText;
window.close()
}
}
function cmdCancel()
{
window.opener.frm.plcStation.value="";
window.opener.frm.plcStationText.value="";
window.close();
}
//-->
</script>
<style type="text/css">
<!--
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
background-image: url(images/images/index_12.gif);
}
-->
</style>
<link href="css/css_new.css" rel="stylesheet" type="text/css">
</head><body>
<br>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="center">
<object classid="clsid:23DBA47C-1262-4001-8712-09E1FD3AD5A5" id="TreeView" width="201" height="257" align="middle">
<param name="TreeNodeKey" value="">
<param name="TreeNodeText" value="">
</object>
</td>
</tr>
<tr>
<td align="center" valign="bottom" height="25">
<input name="btnOk" type="button" class="inputarea" value=" 确 定 " onClick="javascript:cmdOK();">
<input name="btnCancel" type="button" class="inputarea" value=" 取 消 " onClick="javascript:cmdCancel();">
</td>
</tr>
</table>
<script language=javascript>
//调用控件方法,目前参数是手动填写的
TreeView.initTree("辖区单位", "1,,罗湖大队;2,,福田大队;3,,南山大队;4,1,罗湖1中队;5,1,罗湖2中队;6,2,福田1中队");
</script>
</body>
</html>
/a.jsp?value=<%=java.net.URLEncoder.encode("7,1,罗湖1中队") %>b.jsp:
<%
String value=request.getParameter("value");
value= java.net.URLDecoder.decode(value);
out.print(value);
%>
strKey=new String(strKey.getBytes("ISO-8859-1"),"UTF-8");//转换参数类型
2、B页面中<%@ page contentType="text/html; charset=UTF-8" %>B页向A页发送
response.sendRedirect("http://A页?参数="+java.net.URLEncoder.encode(cname,"GBK"));
A页向B页发送
response.sendRedirect("http://A页?参数="+java.net.URLEncoder.encode(cname,"UTF-8"));根据接收页面进行编码,无需进行任何任何处理即可正确获得参数
2、B页面中<%@ page contentType="text/html; charset=UTF-8" %>B页向A页发送
response.sendRedirect("http://A页?参数="+java.net.URLEncoder.encode("值","GBK"));
A页向B页发送
response.sendRedirect("http://B页?参数="+java.net.URLEncoder.encode("值","UTF-8"));根据接收页面进行编码,无需进行任何任何处理即可正确获得参数
<input type=button value="2" onClick="MM_openBrWindow('tree.jsp?type=1&value=<%=java.net.URLEncoder.encode("<c:out value="${strDept}"/>","UTF-8") %>','tree','top=250,left=520,scrollbars=no,resizable=no,width=215,height=330')">原来的是这样的:
<input type=button value="2" onClick="MM_openBrWindow('tree.jsp?type=1&value=<c:out value="${strDept}"/>")','tree','top=250,left=520,scrollbars=no,resizable=no,width=215,height=330')">是通过点击一按钮,弹出的页面。我机器出了问题,不能够编译,所以不能测试,正在处理中。
<%@ page contentType="text/html; charset=GBK" %>
<%@ page import="cn.com.iaspec.sz119.query.event.*" %>
<%@ page import="java.util.*" %>
...
...
...
<%
Object obj=request.getAttribute("resultQueryAlarm");
String strDept="";
if(obj!=null){
QueryAlarmAllListES qaAlist=(QueryAlarmAllListES)obj;
Vector vtDept=qaAlist.getQDictListES().getVtDept();
Iterator it=vtDept.iterator();
while(it.hasNext()){
QueryDictES qde=(QueryDictES)it.next();
strDept=strDept + qde.getSelfID() + "," + qde.getParentID() + "," + java.net.URLEncoder.encode(qde.getSelfName(),"UTF-8") + ";";
}
}
%>
<input name="plcStationText" type="text" size="30" value="" readonly><input type=button value="2" onClick="MM_openBrWindow('tree.jsp?type=1&value=<%=strDept%>','tree','top=250,left=520,scrollbars=no,resizable=no,width=215,height=330')">
<input name="plcStation" type="hidden" id="plcStation" value="">
...
...
...a.jsp至tree.jsp的URL:http://localhost:8080/FireInfo/tree.jsp?type=1&value=7,1,%E7%BD%97%E6%B9%961%E4%B8%AD%E9%98%9F;8,1,%E7%BD%97%E6%B9%962%E4%B8%AD%E9%98%9F;9,2,%E7%A6%8F%E7%94%B01%E4%B8%AD%E9%98%9F;10,2,%E7%A6%8F%E7%94%B02%E4%B8%AD%E9%98%9F;11,2,%E7%A6%8F%E7%94%B03%E4%B8%AD%E9%98%9F;12,3,%E5%8D%97%E5%B1%B11%E4%B8%AD%E9%98%9F;1,0,%E7%BD%97%E6%B9%96%E5%A4%A7%E9%98%9F;2,0,%E7%A6%8F%E7%94%B0%E5%A4%A7%E9%98%9F;3,0,%E5%8D%97%E5%B1%B1%E5%A4%A7%E9%98%9F;4,0,%E7%9B%90%E7%94%B0%E5%A4%A7%E9%98%9F;5,0,D005;6,0,D006;tree.jsp部分代码:
<%@ page contentType="text/html; charset=UTF-8" %>
<%
String type=request.getParameter("type");
String strDept=request.getParameter("value");
out.println(strDept);//在这里输出获得的参数值,得到的仍然是乱码
String strTitle="目录";
if(Integer.parseInt(type)==1)
strTitle="辖区单位";
else
strTitle="警情类别";
%>
...
...
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="center">
<object classid="clsid:23DBA47C-1262-4001-8712-09E1FD3AD5A5" id="TreeView" width="201" height="257" align="middle">
<param name="TreeNodeKey" value="">
<param name="TreeNodeText" value="">
</object>
</td>
</tr>
<tr>
<td align="center" valign="bottom" height="25">
<input name="btnOk" type="button" class="inputarea" value=" 确定 " onClick="javascript:cmdOK();">
<input name="btnCancel" type="button" class="inputarea" value=" 取消 " onClick="javascript:cmdCancel();">
</td>
</tr>
</table>
<script language=javascript>
TreeView.initTree("<%=strTitle%>", "<%=strDept%>");
</script>
...
乱码如下:
7,1,ç½—æ¹–1中队;8,1,ç½—æ¹–2中队;9,2,福田1中队;10,2,福田2中队;11,2,福田3中队;12,3,南山1中队;1,0,罗湖大队;2,0,福田大队;3,0,南山大队;4,0,盐田大队;5,0,D005;6,0,D006; 我真的不知道怎么解决了,这个问题有几天了,到现在没有解决,请各位帮帮忙,不胜感激!
--
要用java.net.URLDecoder.decode转。我上面已经给出来了做法了。我测试是通过的。
a.jsp
/a.jsp?value=<%=java.net.URLEncoder.encode("7,1,罗湖1中队") %>b.jsp:
<%
String value=request.getParameter("value");
value= java.net.URLDecoder.decode(value);
out.print(value);
%>说明一下我的测试环境,AppServer是jetty,a.jsp文件以GBK存储,b.jsp文件以UTF-8存储.如果你使用的是tomcat,注意是否设定了tomcat 的URIEncoding。
应是
/b.jsp?value=<%=java.net.URLEncoder.encode("7,1,罗湖1中队") %>
a.jsp部分代码如下:
<%@ page contentType="text/html; charset=GBK" %>
<%@ taglib uri="../WEB-INF/c.tld" prefix="c" %>
...
<c:set value="" var="strDept" scope="page"/>
<c:forEach items="${resultQueryAlarm.QDictListES.vtDept}" var="dept">
<c:set value="${strDept}${dept.selfID},${dept.parentID},${dept.selfName};" var="strDept"/>
</c:forEach>
<input name="departText" type="text" size="30" value="" readonly><input type=button value="2" onClick="MM_openBrWindow('tree.jsp?type=1&value=<c:out value="${strDept}"/>','tree','scrollbars=no,resizable=no,width=215,height=310')">
<input name="departID" type="hidden" value="">
...tree.jsp部分代码如下:
<%@ page contentType="text/html; charset=GBK" %>
<%
String type=request.getParameter("type");
String strDept=new String(request.getParameter("value").getBytes("ISO8859-1"),"gb2312");
String strTitle="目录";
if(Integer.parseInt(type)==1)
strTitle="辖区单位";
else if(Integer.parseInt(type)==2)
strTitle="警情类别";
%>
...
<script language=javascript>
TreeView.initTree("<%=strTitle%>", "<%=strDept%>");//TreeView为控件名
</script>
...多谢各位的提点和帮助,结帖了!