Steps:
Maintain Folder Structure
GoTo your folder DisplayDate
under src folder
create java file DisplayingDate.java
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class DisplayingDate extends HttpServlet
{
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
PrintWriter pw=response.getWriter();
Date today=new Date();
pw.println("<html>"+<body><h1>Today Date is</h1>");
pw.println("<b>"+today+"</b></body>"+"</html>");
}
}
Compile this program.
javac DisplayingDate.java
type user name and password; (at the time of installing tomcat server we should set the username and password.)
here my username is: root
password is root.
Maintain Folder Structure
GoTo your folder DisplayDate
under src folder
create java file DisplayingDate.java
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class DisplayingDate extends HttpServlet
{
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
PrintWriter pw=response.getWriter();
Date today=new Date();
pw.println("<html>"+<body><h1>Today Date is</h1>");
pw.println("<b>"+today+"</b></body>"+"</html>");
}
}
Compile this program.
javac DisplayingDate.java
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class DisplayingDate extends HttpServlet
{
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
PrintWriter pw=response.getWriter();
Date today=new Date();
pw.println("<html>"+"<body><h1>Today Date is</h1>");
pw.println("<b>"+today+"</b></body>"+"</html>");
}
}
Again compile:
javac DisplayingDate.java
We got errors that packages does not exist
package javax.servlet.
package javax.servlet.http.
Because we have not set the class path.
So set the class path
E:/DisplayDate/src>set classpath=C:\Program Files\Apache Software Foundation\Tomcat 8.0\lib\servlet-api.jar;
now compile the program
javac DisplayingDate.java
Now ok.
Go to WEB-INF folder
open web.xml file
<web-app>
<servlet>
<servlet-name>Hello</servlet-name>
<servlet-class>DisplayDate</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Hello</servlet-name>
<url-pattern>/DateDisplay</url-pattern>
</servlet-mapping>
</web-app>
-->Save the file
Deploy your project (folder) DisplayDate into Servler
Go to apache tomcat server folder
Start the server:
Go to any browser:
and type your local host with port no
http://localhost:8080/
here my username is: root
password is root.