Steps to use JavaStack in your computer:
Create a folder with permission to write (in your user folder or in C:\Temp). For example: C:\temp\Tomcat
Copy the following folders from C:\Programs\JavaStack\apache-tomcat-9.0.89 to C:\temp\Tomcat
Note: to reduce space, you can delete the folders docs and examples from webapps.
Define:
set CATALINA_HOME=C:\Programs\JavaStack\apache-tomcat-9.0.89
set CATALINA_BASE=C:\Users\name\Documents\Tomcat
set JAVA_HOME=C:\Programs\JavaStack\jdk1.8.0_131
Or you can create the file sj.bat in C:\temp\Tomcat:
To start Tomcat type:
startup
To test Tomcat, write in the browser
http://localhost:8082/
To stop Tomcat type:
shutdown
To try other apps, download CS repository from https://github.com/nicolasserrano/CS and copy some webapps to your webapps
To compile:
set CLASSPATH=%CLASSPATH%;.;%CATALINA_HOME%\lib\servlet-api.jar;
Summary of steps to create a servlet and start it in Tomcat:
Start Tomcat
Follow the steps to use JavaStack in your computer
Go to your Tomcat folder: >C:\temp\Tomcat
Execute the sj.bat file: >sj
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