Apache Tomcat
About Servlet
Can HiPerformance Processing for Application Logc Components(class)
Java Servlet - Basics
Basic
file:TestServlet01.java
import java.io.PrintWrite; import java.io.IOException; import jakarta.servlet.ServletException; import jakarta.servlet.http.HttpServlet; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; public class TestServlet01 extends HttpServlet { private static final long serialVersionUID = 1L; @Override public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { response.setContentType("text/html"); response.setCharacterEncoding("UTF-8"); PrintWriter out = response.getWriter(); out.println("TestServlet01"); } }
Compile
Example: Env(Windows10, jdk1.8) classes: %TOMCAT_HOME%\webapps\examples\WEB-INF\classes javac -classpath %classpath%;e:\Dev\java\tomcat10_0_14\lib\servelt-api.jar TestServlet01.java tomcatの構成はカスタマイズせずに、デフォルト構成のweb.xmlを利用する例 %TOMCAT_HOME%\webapps\examples\WEB-INF\web.xml を編集します
file:web.xml
<servlet> <servlet-name>TestServlet01</servlet-name> <servlet-class>TestServlet01</servlet-class> </servlet> <servlet-mapping> <servlet-name>TestServlet01</servlet-name> <url-pattern>/servlets/servlet/TestServlet01</url-pattern> </servlet-mapping> How to access: http://localhost:8080/examples/servlets/servlet/TestServlet01