-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy pathMyServletDemo.java
37 lines (30 loc) · 904 Bytes
/
MyServletDemo.java
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
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
// Extend HttpServlet class to create Http Servlet
public class MyServletDemo extends HttpServlet {
/**
*
*/
private static final long serialVersionUID = 1L;
private String mymsg;
public void init() throws ServletException {
mymsg = "Hello World!";
}
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
// Setting up the content type of webpage
response.setContentType("text/html");
// Writing message to the web page
PrintWriter out = response.getWriter();
out.println("<h1>" + mymsg + "</h1>");
}
public void destroy() {
/*
* leaving empty for now this can be
* used when we want to do something at the end
* of Servlet life cycle
*/
}
}