请教各位以下代码
以下是我的过滤器代码:
package untitled1;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
public class Filter2 extends HttpServlet implements Filter {
private FilterConfig filterConfig;
//Handle the passed-in FilterConfig
public void init(FilterConfig filterConfig) throws ServletException {
this.filterConfig = filterConfig;
}
//Process the request/response pair
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain filterChain) {
try {
//是一个.do的请求
String url = ((HttpServletRequest) request).getRequestURI();
System.out.print("url=" + url);
String name = "/index.wml"; // 这是生成的wml文件名
String pName = "e:\\index.wml"; // 生成html的完整路径
String realPath = "";
try {
java.io.File file = new java.io.File(request.getRealPath(url));
realPath = "F:/Temp/untitled1/WebModule1/"; // file.getParent();
} catch (Exception e) {
}
final ByteArrayOutputStream os = new ByteArrayOutputStream();
final ServletOutputStream stream = new ServletOutputStream() {
public void write(byte[] data, int offset, int length) {
os.write(data, offset, length);
}
public void write(int b) throws IOException {
os.write(b);
}
};
final PrintWriter pw = new PrintWriter(new OutputStreamWriter(os));
HttpServletResponse rep = new HttpServletResponseWrapper((
HttpServletResponse) response) {
public ServletOutputStream getOutputStream() {
return stream;
}
public PrintWriter getWriter() {
return pw;
}
};
//将请求拦截后,把请求的响应保存到rep对象中
filterChain.doFilter(request, rep);
pw.flush();
FileOutputStream fos = new FileOutputStream(realPath + name); // 把jsp输出的内容写到指定路径的htm文件中
os.writeTo(fos);
fos.close();
//原请求响应保到到文件中
//此处需要重定向到被保存下来的文件,但不知如何操作(注意:此过滤器设定为对Action对象进行过滤)???????????????????????
} catch (Exception sx) {
filterConfig.getServletContext().log(sx.getMessage());
}
}
//Clean up resources
public void destroy() {
}
}
以下是Action:
public class Test extends Action {
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response) {
return mapping.findForward("index");
}
}