STEPS:
1. CREATE THE FOLDER (Ex: Introduction)
2. WRITE HTML PROGRAM (EX: index.html)
3. write the servlet program (Ex: FirstServlet.java)
4. set the classpath for Tomcat Server
5. compile the servlet program to get class files
6. create WEB-INF folder
7. under WEB-INF folder
8. write web.xml file
9. create classes folder
10. create lib folder
11. prepare the WAR file (optional)
12. deploy the application(war file) into the server
13 Run the server
14. execute in the browser
//index.html
<html>
<head>
<title>time and date</title>
</head>
<body>
<form action="ExServlet" method="get">
<input type="submit" value="click here"/>
</form>
</body>
</html>
//FirstServlet.java
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.Date;
public class FirstServlet extends HttpServlet
{
public void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException
{
response.setContentType("text/html");
PrintWriter out=response.getWriter();
out.write("<html>");
out.write("<head>");
out.write("<title>First jsp page</title>");
out.write("</head>");
out.write("<body>");
out.write(new Date().toString());
out.write("<br/>Hello World! <br/>");
out.write("</body>");
out.write("</html>");
out.close();
}
}
/*
D:\webtechnologies\jsp\prog\Introduction\fistServletApp>javac FirstServlet.java
D:\webtechnologies\jsp\prog\Introduction\fistServletApp>
*/
web.xml
<web-app>
<servlet>
<servlet-name>serv</servlet-name>
<servlet-class>FirstServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>serv</servlet-name>
<url-pattern>/ExServlet</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>
Now we will do the same program in JSP
Steps:
1. create any folder (Ex: firstJsp)
2. write the jsp program
3. deploy the folder (firstJsp)
4. start server
5. deploy our application
6. run the jsp program
2. write the jsp program
<%@ page import="java.util.Date;"%>
<html>
<head>
<title>First JSP Page</title>
</head>
<body>
<%
out.println(new Date().toString());
%>
<br>Hello World! </br>
</body>
</html>
3. deploy the folder (firstJsp) into webapps folder of Tomcat server
4. start the server
5. go to any browser,
6. type http://localhost:8888/
click on Tomcat Manager
7. type username and password
8. select firstJspApp folder from the list
9. type firstpage.jsp at the end of the url ie. http://localhost:8888/firstJspApp/firstpage.jsp