EX No:1 DISPLAY A WELCOME MESSAGE USING SERVLET
AIM:
To display a welcome message using Servlet.
ALGORITHM:
1. Start the process
2. Set Up the HTML Page as MyServlet.html
3. Set Up the Servlet Class as MyServlet.java
4. Create the MyServlet Class
5. Implement the doGet() Method
6. Start a servlet to a Java EE-compatible web server
7. Test the Servlet using localhost
8. stop the process
CODING:
MyServlet.html
<html>
<head>My First Servlet</head>
<body>
<center><h2>WELCOME</h2></center>
</body>
</html>
MyServlet.java
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
@WebServlet("/MyServlet")
public class MyServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
public MyServlet() {
super();
}
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out=response.getWriter();
out.print("<html><head>My First Servlet</head><body>");
out.print("<center><h2>");
out.print("WELCOME</h2></center>");
out.print("<p>doGet() Method is executing....</p>");
out.print("</body></html>");
}
}
OUTPUT:
RESULT
Thus, the above program was successfully executed.