Steps to create a servlet and start it in Tomcat:
Note: instructions with jdk1.8.0_131, instructions with jdk1.7.0_80 in Tomcat_jdk1_7
Start Tomcat
Copy the folder Java8 to a local folder
Go to the Java8 folder: >cd path/Java8
Execute the sp.bat file: >sp
startup
Start the browser and write the address:
http://localhost:8082
shutdown
Create a Web page on the server
Steps 1 to 3 of Start Tomcat (done)
Create a folder called ‘firstWeb’ in the webapps folder of the Tomcat.
Create the index.html file in the webapps\firstWeb folder with some html content
Start the Tomcat server as in step 4 of Start Tomcat:
startup
Start the browser and write the address:
http://localhost:8082/firstWeb
Create a Servlet
Steps 1 to 3 of Start Tomcat (done)
apache-tomcat-8.5.24
└── webapps
└── Servlet1
└── WEB-INF
└── web.xml
└── classes
Create the HelloWorld.java file in the webapps\Servlet1\WEB-INF\classes folder. HelloWorld.java
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class HelloWorld extends HttpServlet{
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
PrintWriter out = response.getWriter();
out.println("Hello World");
}
}
javac HelloWorld.java
Create the web.xml file in P:\apache-tomcat-8.5.24\webapps\Servlet1\WEB-INF folder:
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app>
<servlet>
<servlet-name>primer</servlet-name>
<servlet-class>HelloWorld</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>primer</servlet-name>
<url-pattern>/start</url-pattern>
</servlet-mapping>
</web-app>
Start the Tomcat server as in step 4 of Start Tomcat:
startup
With variables for Java, Derby, Squirrel and Apache Tomca
To execute the Java programs from a pendrive follow the next steps: