() 重写所需的方法加入我们的功能
具体代码如下所示
package servlets;
import javaioUnsupportedEncodingException;
import javaxservlethttpHttpServletRequest;
import javaxservlethttpHttpServletResponse;
import orgapachestrutsactionRequestProcessor;
public class EncodingHandler extends RequestProcessor {
public boolean processPreprocess(HttpServletRequest servletRequest
HttpServletResponse serveltResponse) {
try {
servletRequestsetCharacterEncoding(GBK);
Systemoutprintln(请求被处理);
} catch (UnsupportedEncodingException ex) {
exprintStackTrace();
}
return true;
}
}
() 修改配置文件sturtsconfigxml在其中加入一个名为的元素用以指定我们定制的RequestProcessor类
<?xml version= encoding=UTF?>
<!DOCTYPE strutsconfig PUBLIC //Apache Software Foundation//DTD Struts Configuration //EN http://jakartaapacheorg/struts/dtds/strutsconfig__dtd>
<strutsconfig>
<formbeans>
<formbean name=loginActionForm type=formbeansLoginActionForm />
</formbeans>
<actionmappings>
<action
path=/login
name=loginActionForm
scope=request
type=actionsLoginAction>
[] [] [] [] []