1 /* |
|
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 package com.nokia.mj.impl.installer.testserver; |
|
19 |
|
20 import java.io.IOException; |
|
21 import javax.servlet.ServletException; |
|
22 import javax.servlet.http.HttpServlet; |
|
23 import javax.servlet.http.HttpServletRequest; |
|
24 import javax.servlet.http.HttpServletResponse; |
|
25 |
|
26 /** |
|
27 * Servlet implementation class RedirectServlet |
|
28 */ |
|
29 public class RedirectServlet extends HttpServlet |
|
30 { |
|
31 private static final long serialVersionUID = 1L; |
|
32 |
|
33 protected void processRequest(HttpServletRequest request, |
|
34 HttpServletResponse response) |
|
35 throws ServletException, IOException |
|
36 { |
|
37 int redirectCount = 1; |
|
38 String redirectUrl = "http://" + request.getServerName() + ":" |
|
39 + request.getServerPort() |
|
40 + request.getContextPath(); |
|
41 |
|
42 String countParam = request.getParameter("count"); |
|
43 String nameParam = request.getParameter("name"); |
|
44 |
|
45 if (countParam != null) |
|
46 { |
|
47 try |
|
48 { |
|
49 redirectCount = Integer.parseInt(countParam); |
|
50 } |
|
51 catch (NumberFormatException nfe) |
|
52 { |
|
53 } |
|
54 } |
|
55 |
|
56 if (redirectCount > 1) |
|
57 { |
|
58 redirectUrl += request.getServletPath() + "?count=" |
|
59 + (redirectCount - 1) + "&name="; |
|
60 } |
|
61 else |
|
62 { |
|
63 redirectUrl += "/"; |
|
64 } |
|
65 |
|
66 redirectUrl += nameParam; |
|
67 response.sendRedirect(redirectUrl); |
|
68 } |
|
69 |
|
70 protected void doGet(HttpServletRequest request, |
|
71 HttpServletResponse response) |
|
72 throws ServletException, IOException |
|
73 { |
|
74 processRequest(request, response); |
|
75 } |
|
76 |
|
77 protected void doPost(HttpServletRequest request, |
|
78 HttpServletResponse response) |
|
79 throws ServletException, IOException |
|
80 { |
|
81 processRequest(request, response); |
|
82 } |
|
83 |
|
84 } |
|