URL传中文乱码

jsp页面:
<%@ page language="java" import="java.net.*" pageEncoding="UTF-8"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="Sun, 6 Mar 2005 01:00:00 GMT" />
<title>测试</title>

<script type="text/javascript">
function encode(Str){
alert(Str);
//alert("http://127.0.0.1:9080/magicMMS/servlet/QmessageServlet?content="+encodeURIComponent("中文*&^$#@!汉%字"));
window.open("http://127.0.0.1:9080/magicMMS/servlet/QmessageServlet?content="+encodeURIComponent("中文*&^$#@!汉%字"));
}
</script>
</head>
<body>
<p/>
本地测试:
<p/>
<a href=http://127.0.0.1:8080/magicMMS/servlet/QmessageServlet?content=<%=java.net.URLEncoder.encode("中文*&^$#@!)(汉%字","UTF-8") %> target="_blank">中文本地测试</a>
<p/>
本地js编码测试:
<p/>
<button onclick="javascript:encode('中文*&^$#@!)(汉%字');">中文测试</button>
<p/>
</body>
</html>


servlet:

public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String message = "";
message = new String(request.getParameter("content").getBytes("ISO8859-1"),"UTF-8");
}


这种写法可以解决2个问题:
1.中文乱码
2.%这个字符使用request.getParameter方法获取时报异常
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值