JSP之中文亂碼解決方法實例代碼如下:
<%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
<%
!String getString(String param) {
String tmp;
try {
byte[] strBytes = param.getBytes("ISO8859-1");
tmp = new String(strBytes, "GBK");
return tmp;
} catch (Exception e) {
return null;
}
}
%>
<%
String uname = getString(request.getParameter("uname"));
%>
<html>
<head><title>樣本</title></head>
<body>
姓名:<%=uname %>
</body>
</html>