1 31 32 package org.apache.commons.httpclient; 33 34 import java.io.IOException ; 35 36 import javax.servlet.ServletException ; 37 import javax.servlet.http.HttpServletRequest ; 38 import javax.servlet.http.HttpServletResponse ; 39 40 public class RedirectServlet extends MultiMethodServlet { 41 protected void genericService(HttpServletRequest request, HttpServletResponse response) throws IOException , ServletException { 42 String to = null; 43 if(null != request.getParameter("loop")) { 44 to = request.getRequestURL().append("?").append(request.getQueryString()).toString(); 45 } else { 46 to = request.getParameter("to"); 47 } 48 if(null == to) { 49 to = "/"; 50 } 51 response.setHeader("Location",to); 52 53 try { 54 int status = Integer.parseInt(request.getParameter("code")); 55 response.setStatus(status); 56 } catch (Exception e) { 57 response.setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY); 58 } 59 60 } 61 } 62 63 | Popular Tags |