url或get中文参数传递取值

这几天做项目时遇到了个问题就是我想通过<a href="XX/XX.do?name="中文" ">XX </a> 这个时候不会报错也不显示name。于是寻求解决方案:
用js创建一个post form 在jsp页面上把参数传进来
dynamicform.js
function openHref(myAction, paramName, paramValue) {
	var submitForm = getNewSubmitForm();
	createNewFormElement(submitForm, paramName, paramValue);
	//up to 4 parameters
	for (var i = 3; i < 11; i = i + 2) {
		if ((arguments[i] != undefined) && (arguments[i + 1] != undefined)) {
			createNewFormElement(submitForm, arguments[i], arguments[i + 1]);
		}
	}
	submitForm.action = myAction;
	submitForm.submit();
}

  //helper function to create the form
function getNewSubmitForm() {
	var submitForm = document.createElement("FORM");
	document.body.appendChild(submitForm);
	submitForm.method = "POST";
	return submitForm;
}

  //helper function to add elements to the form
function createNewFormElement(inputForm, elementName, elementValue) {
	var newElement = document.createElement("input");
	newElement.setAttribute("name", elementName);
	newElement.setAttribute("type", "hidden");
	newElement.setAttribute("value", elementValue);
	inputForm.appendChild(newElement);
	return newElement;
}

导入js
<script type="text/javascript" src="${pageScope.path}/common/js/dynamicform.js"></script>	

调用如下:

 <a href="javascript:openHref('${pageScope.path}/searchScripts.do?param=searchScriptByName','script_name','${scripts.script_name}','tenant_id','${scripts.tenant_id}');">${scripts.script_name}</a>

你可能感兴趣的:(html,jsp,UP)