KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mortbay > servlet > SendRedirect


1 // ========================================================================
2
// $Id: SendRedirect.java,v 1.6 2005/08/13 00:01:28 gregwilkins Exp $
3
// Copyright 1996-2004 Mort Bay Consulting Pty. Ltd.
4
// ------------------------------------------------------------------------
5
// Licensed under the Apache License, Version 2.0 (the "License");
6
// you may not use this file except in compliance with the License.
7
// You may obtain a copy of the License at
8
// http://www.apache.org/licenses/LICENSE-2.0
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
// ========================================================================
15

16 package org.mortbay.servlet;
17 import java.io.IOException JavaDoc;
18 import java.io.PrintWriter JavaDoc;
19
20 import javax.servlet.ServletException JavaDoc;
21 import javax.servlet.http.HttpServlet JavaDoc;
22 import javax.servlet.http.HttpServletRequest JavaDoc;
23 import javax.servlet.http.HttpServletResponse JavaDoc;
24
25 import org.apache.commons.logging.Log;
26 import org.mortbay.log.LogFactory;
27 import org.mortbay.html.Heading;
28 import org.mortbay.html.Page;
29 import org.mortbay.html.TableForm;
30 import org.mortbay.util.LogSupport;
31 import org.mortbay.util.URI;
32
33 /* ------------------------------------------------------------ */
34 /** Dump Servlet Request.
35  *
36  */

37 public class SendRedirect extends HttpServlet JavaDoc
38 {
39     private static Log log = LogFactory.getLog(SendRedirect.class);
40
41     /* ------------------------------------------------------------ */
42     public void doGet(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
43         throws ServletException JavaDoc, IOException JavaDoc
44     {
45         response.setContentType("text/html");
46         response.setHeader("Pragma", "no-cache");
47         response.setHeader("Cache-Control", "no-cache,no-store");
48
49         String JavaDoc url=request.getParameter("URL");
50         if (url!=null && url.length()>0)
51         {
52             response.sendRedirect(url);
53         }
54         else
55         {
56             PrintWriter JavaDoc pout = response.getWriter();
57             Page page=null;
58             
59             try{
60                 page = new Page();
61                 page.title("SendRedirect Servlet");
62                 
63                 page.add(new Heading(1,"SendRedirect Servlet"));
64                 
65                 page.add(new Heading(1,"Form to generate Dump content"));
66                 TableForm tf = new TableForm
67                     (response.encodeURL(URI.addPaths(request.getContextPath(),
68                                                      request.getServletPath())+
69                                         "/action"));
70                 tf.method("GET");
71                 tf.addTextField("URL","URL",40,request.getContextPath()+"/dump");
72                 tf.addButton("Redirect","Redirect");
73                 page.add(tf);
74                 page.write(pout);
75                 pout.close();
76             }
77             catch (Exception JavaDoc e)
78             {
79                 log.warn(LogSupport.EXCEPTION,e);
80             }
81         }
82     }
83
84 }
85
Popular Tags