code019.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>中文乱码问题</title>
<script>
function linkClick(linkObject) {
var formObject = document.createElement('form');
document.body.appendChild(formObject);
formObject.setAttribute('method', 'post');
var url = linkObject.href;
var uri = '';
var i = url.indexOf('?');
if(i == -1) {
formObject.action = url;
} else {
formObject.action = url.substring(0, i);
}
if( i >= 0 && url.length >= i + 1) {
uri = url.substring(i + 1, url.length);
}
var sa = uri.split('&');
for(var i = 0; i < sa.length; i++) {
var isa = sa[i].split('=');
var inputObject = document.createElement('input');
inputObject.setAttribute('type', 'hidden');
inputObject.setAttribute('name', isa[0]);
inputObject.setAttribute('value', isa[1]);
formObject.appendChild(inputObject);
}
formObject.submit();
return false;
}
</script>
</head>
<body>
<a href="code020.jsp?name=虾米大王&sex=男" onclick="return linkClick(this)">中文乱码问题</a>
</body>
</html>