0% found this document useful (0 votes)
17 views2 pages

Program 1

The document outlines a procedure to display a welcome message using a Servlet in Java. It includes an algorithm for setting up an HTML page and a Servlet class, along with the necessary coding for both. The process concludes with a successful execution of the program, displaying the welcome message in a web browser.

Uploaded by

Vidhya Elango
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views2 pages

Program 1

The document outlines a procedure to display a welcome message using a Servlet in Java. It includes an algorithm for setting up an HTML page and a Servlet class, along with the necessary coding for both. The process concludes with a successful execution of the program, displaying the welcome message in a web browser.

Uploaded by

Vidhya Elango
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

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.

You might also like