js:
var namepass = document.getElementById("btn").name;
//var namepass =escape(namepasss) 此處用escape的話,後台頁面接收為null,是為什麼?
f1.action = "<%=request.getContextPath()%>/noticeController.do?cmd=jump&stamp=1&name="+namepass;
f1.submit();
}
Java
String name=request.getParameter("name");
此處NAME就變成亂碼了。。如果在js頁面中用escape的話此處Name的值就變成了null。。我該怎麼讓中文不亂碼的傳送過來?
前台:
namepass = encodeURI(encodeURI(namepass));
f1.action = "<%=request.getContextPath()%>/noticeController.do?cmd=jump&stamp=1&name="+namepass;
f1.submit();
}
後台:
需要引入import java.net.URLDecoder;
String name = request.getParameter("name");
name = URLDecoder.decode(name, "UTF-8");