三度网教程:是一个免费提供流行视频软件教程、在线学习分享的学习平台!

半翻译半整理的一些struts的东东,很浅显的,欢迎指正(3)

时间:2022-8-5作者:未知来源:三度网教程人气:


4.RequestProcessor:
有关的ActionServlet的实际处理都是在RequestProcessor类中完成的。我们也可以创建我们自己的RequestProcessor类,这需要继承RequestProcessor类。并且要有一个缺省的空的构造器。在这个自定义的RequestProcessor类中重写相关的方法,一般都是重写processXXX()方法。
◆扩展RequestProcessor类
扩展Processor类按下面的步骤完成:
① 创建一个继承于org.apache.struts.action.RequestProcessor的类
② 添加一个缺省的空的构造器
③ 实现想要重写的方法
例子:
package wiley;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServlet;
import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import java.io.IOException;
import java.util.Enumeration;
import org.apache.struts.action.RequestProcessor;
public class WileyRequestProcessor extends RequestProcessor {
public WileyRequestProcessor() {
}
public boolean processPreprocess(HttpServletRequest request, HttpServletResponse response) {
log("----------processPreprocess Logging--------------");
log("Request URI = " + request.getRequestURI());
log("Context Path = " + request.getContextPath());
Cookie cookies[] = request.getCookies();
if (cookies != null) {
for (int i = 0; i < cookies.length; i++) {
 log("Cookie = " + cookies[i].getName() + " = " +
 cookies[i].getValue());
}
}
Enumeration headerNames = request.getHeaderNames();
while (headerNames.hasMoreElements()) {
String headerName =(String) headerNames.nextElement();
Enumeration headerValues =request.getHeaders(headerName);
while (headerValues.hasMoreElements()) {
String headerValue =(String) headerValues.nextElement();
log("Header = " + headerName + " = " + headerValue);
}
}
log("Locale = " + request.getLocale());
log("Method = " + request.getMethod());
log("Path Info = " + request.getPathInfo());
log("Protocol = " + request.getProtocol());
log("Remote Address = " + request.getRemoteAddr());
log("Remote Host = " + request.getRemoteHost());
log("Remote User = " + request.getRemoteUser());
log("Requested Session Id = " + request.getRequestedSessionId());
log("Scheme = " + request.getScheme());
log("Server Name = " + request.getServerName());
log("Server Port = " + request.getServerPort());
log("Servlet Path = " + request.getServletPath());
log("Secure = " + request.isSecure());
log("-------------------------------------------------");
return true;
}
}
◆配置RequestProcessor:
在struts-config.xml文件中配置<controller/>元素。如下:
<controller processorClass=”wiley.WileyRequestProcessor” />
详细配置信息见”struts-config.xml配置文件讲解”。

关键词:  半翻译半整理的一些struts的东东  很浅显的  欢迎指正(3)





Copyright © 2012-2018 三度网教程(http://www.3du8.cn) .All Rights Reserved 网站地图 友情链接

免责声明:本站资源均来自互联网收集 如有侵犯到您利益的地方请及时联系管理删除,敬请见谅!

QQ:1006262270   邮箱:kfyvi376850063@126.com   手机版