1 28 29 package com.caucho.server.dispatch; 30 31 import javax.servlet.FilterChain ; 32 import javax.servlet.ServletException ; 33 import javax.servlet.ServletRequest ; 34 import javax.servlet.ServletResponse ; 35 import javax.servlet.http.HttpServletRequest ; 36 import javax.servlet.http.HttpServletResponse ; 37 import java.io.IOException ; 38 import java.io.PrintWriter ; 39 40 43 public class MovedFilterChain implements FilterChain { 44 private int _code; 45 private String _url; 46 private String _queryString; 47 48 53 public MovedFilterChain(int code, String url) 54 { 55 _code = code; 56 _url = url; 57 } 58 59 64 public MovedFilterChain(int code, String url, String queryString) 65 { 66 _code = code; 67 _url = url; 68 _queryString = queryString; 69 } 70 71 79 public void doFilter(ServletRequest request, 80 ServletResponse response) 81 throws ServletException , IOException 82 { 83 HttpServletRequest req = (HttpServletRequest ) request; 84 HttpServletResponse res = (HttpServletResponse ) response; 85 86 String queryString = _queryString; 87 88 if (queryString == null) 89 queryString = req.getQueryString(); 90 91 String url; 92 93 if (queryString != null && _url.indexOf('?') < 0) 94 url = res.encodeURL(_url + '?' + queryString); 95 else 96 url = res.encodeURL(_url); 97 98 res.setHeader("Location", url); 99 100 res.setStatus(_code); 101 102 PrintWriter out = response.getWriter(); 103 104 out.println("The URL has moved to <a HREF=\"" + url + "\">" + url + "</a>"); 105 } 106 } 107 | Popular Tags |