First Servlet File under Class by extension FirstServlet.java
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*
public class FirstServlet extends HttpServlet{
public void doGet(HttpServletRequest req,HttpServletResponse res) throws ServletException , IOException{
res.setContentType("text/html");
PrintWriter out = res.getWriter();
out.println("<html>");
out.println("<head>");
out.println("<title>");
out.println("</title>");
out.println("</head>");
out.println("<body>");
out.println("</body>");
out.println("<h3>Welcome to First Servlet</h3>");
out.println("Time : "+(new Date()).toLocaleString());
out.println("</html>");
}
After Completing coding,Compile the Server
Drag and Drop the Source of folder at cmd
class path but we need to add library
Need library "servlet-api.jar"
api library
Copy lib path
Two Paths Below:-
Add more infront of path servlet-api.jar FirstServlet.java
cls in 2nd path
we got file class from compilation
Create web.xml
Write code in web.xml
<web-app>
<servlet>
<servlet-name>example</servlet-name>
<servlet-class>FirstServlet</servlet-class></servlet>
<servlet-mapping>
<servlet-name>example</servlet-name>
<url-pattern>/myfirstservlet</url-pattern>
</servlet-mapping>
</web-app>