01: package com.mockrunner.example.servlet;
02:
03: import java.io.IOException;
04:
05: import javax.servlet.ServletException;
06: import javax.servlet.http.HttpServlet;
07: import javax.servlet.http.HttpServletRequest;
08: import javax.servlet.http.HttpServletResponse;
09:
10: /**
11: * This example servlet creates an html page thats
12: * redirects to a specified URL. You can specify
13: * the URl with the request parameter <i>redirecturl</i>.
14: * Check out {@link RedirectServletTest}
15: * to see how to test this simple servlet.
16: */
17: public class RedirectServlet extends HttpServlet {
18: public void doGet(HttpServletRequest request,
19: HttpServletResponse response) throws ServletException,
20: IOException {
21: doPost(request, response);
22: }
23:
24: public void doPost(HttpServletRequest request,
25: HttpServletResponse response) throws ServletException,
26: IOException {
27: String redirectUrl = request.getParameter("redirecturl");
28: StringBuffer output = new StringBuffer();
29: output.append("<html>\n");
30: output.append("<head>\n");
31: output.append("<meta http-equiv=\"refresh\" content=\"");
32: output.append("0;URL=" + redirectUrl + "\">\n");
33: output.append("</head>\n");
34: output.append("<body>\n");
35: output.append("<h3>");
36: output.append("You will be redirected to ");
37: output.append("<a href=\"" + redirectUrl + "\">");
38: output.append(redirectUrl + "</a>");
39: output.append("</h3>\n");
40: output.append("</body>\n");
41: output.append("</html>\n");
42: response.getWriter().write(output.toString());
43: }
44: }
|