forked from ramram43210/Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPageRedirectServlet.java
More file actions
41 lines (33 loc) · 1.12 KB
/
Copy pathPageRedirectServlet.java
File metadata and controls
41 lines (33 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class PageRedirectServlet extends HttpServlet
{
private static final long serialVersionUID = 1L;
public void init() throws ServletException
{
System.out.println("---------------------------");
System.out.println(" Init method is called in "
+ this.getClass().getName());
System.out.println("---------------------------");
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
// Set response content type
response.setContentType("text/html");
// New location to be redirected
String site = new String("http://www.google.com");
response.setStatus(response.SC_MOVED_TEMPORARILY);
response.setHeader("Location", site);
}
public void destroy()
{
System.out.println("---------------------------");
System.out.println(" destroy method is called in "
+ this.getClass().getName());
System.out.println("---------------------------");
}
}