在編寫JSP程序時
<%!
public String codeToString(String str)
{
String s=str;
try
{
byte temp[]=s
s=new String(temp);
return s;
}
catch(Exception e)
{
return s;
}
}
%>
要轉換時只需
package filters;
import java
import javax
import javax
import javax
import javax
import javax
import javax
import javax
import javax
public class TomcatFormFilter implements Filter {
/**
* Request
* 對 HttpServletRequestWrapper 進行擴充
有的 HttpServletRequest
* 接口中的功能
需要用新的 Request 對象替換頁面中的
* request 對象即可
*/
class Request extends HttpServletRequestWrapper
{
public Request(HttpServletRequest request) {
super(request);
}
/**
* 轉換由表單讀取的數據的內碼
* 從 ISO 字符轉到 GBK
*/
public String toChi(String input) {
try {
byte[] bytes = input
return new String(bytes
}
catch (Exception ex) {
}
return null;
}
/**
* Return the HttpServletRequest holded by this object
*/
private HttpServletRequest getHttpServletRequest()
{
return (HttpServletRequest)super
}
/**
* 讀取參數
*/
public String getParameter(String name)
{
return
toChi(getHttpServletRequest()
}
/**
* 讀取參數列表
*/
public String[] getParameterValues(String name)
{
String values[] =
getHttpServletRequest()
if (values != null) {
for (int i =
values[i] = toChi(values[i]);
}
}
return values;
}
}
public void destroy() {
}
public void doFilter(ServletRequest request
response
FilterChain chain) throws IOException
HttpServletRequest httpreq = (HttpServletRequest)request;
if()
request
} else {
request = new Request(httpreq);
}
chain
}
public void init(FilterConfig filterConfig) throws
ServletException {
}
}
當然要記得改下web
<filter>
<filter
<filter
</filter>
<filter
<filter
<url
</filter
上面兩種方法都測試過了
From:http://tw.wingwit.com/Article/program/Java/JSP/201311/20505.html