In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article introduces the relevant knowledge of "what are the basic knowledge points of Tomcat". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Background introduction
Apache Tomcat is an open source implementation of Java Servlet, JavaServer Pages (JSP), the Java expression language, and Java's WebSocket technology. Tomcat is usually referred to as a Web container or a Servlet container.
The mapping between the versions of tomcat and the corresponding specifications:
Download address
Download https://tomcat.apache.org/download-90.cgi locally and decompress:
Enter the home directory:
Introduction to tomcat catalogue
Bin
Start, close and other scripts. These .sh files (for Unix systems) are functional copies of these .bat files (for Windows systems). Because the Win32 command line lacks some functionality, some other files are included here.
For example, startup.bat is used to start tomcat under windows, and startup.sh is used in Linux environment. There is also a corresponding shutdown shutdown script.
Conf
The configuration file for tomcat and the associated DTD. The most important file here is server.xml. It is the main configuration file for the container.
Catalina.policy:tomcat: security policy file to control JVM-related permissions. For more information, please see java.security.Permission.
Catalina.properties:tomcat Catalina behavior controls configuration files, such as Common ClassLoader.
Logging.properties:tomcat log profile. The log in it uses JDK Logging.
The server.xml:tomcat server configuration file (which is very important to my developer).
Context.xml: a global context configuration file that monitors and loads resource files and loads automatically when the monitored file changes.
Tomcat-user.xml:tomcat role profile.
The web.xml deployment file of web.xml:Servlet standard is configured in part of the default implementation of tomcat:
Org.apache.catalina.servlets.DefaultServlet .
Org.apache.jasper.servlet.JspServlet
Logs
The log file is located here by default.
Localhost is useful. When your tomcat fails to start, read more about this file. For example:
NoClassDefFoundError
ClassNotFoundException
Access is the most useless.
Catalina. {date} is mainly the console output, where all the logs are stored.
Webapps
This is where your webapp is located. In fact, these are all the same projects.
Simplify the way web is deployed. Our applications will not be put here in the online environment. The best way is external.
Libtomcat stores shared class libraries. For example:
Ecj-4.17.jar: eclipse Java compiler
Jasper.jar:JSP compiler.
Work
Stores files compiled by the tomcat runtime, such as those compiled by JSP.
Temp
Stores temporary files generated at run time.
Start tomcat
Start tomcat
We launch startup.bat in the bin directory directly under windows, and we use startup.sh in the corresponding Linux environment.
Double-click to start. The console will lose port 8080, and then we will visit:
The http://localhost:8080/ page shows:
This means that our tomcat has been launched successfully.
At this point, http://localhost:8080/ requests the ROOT directory.
For example, we can also http://localhost:8080/manager
The Servlet project is deployed to tomcat
Create a web project
Create a web project using maven. Since tomcat is a Servlet container, create a Servlet class in the project, package it into a war package, and copy it to tomcat for deployment.
The project structure is as follows:
Add dependency
4.0.0 com.tian.maven my-web-maven war 1.0-SNAPSHOT my-web-maven Maven Webapp http://maven.apache.org junit junit 3.8.1 test javax.servlet javax.servlet-api 3.1.0 my-web-maven
Create DemoServlet
Package com.tian.maven; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; @ WebServlet (urlPatterns = "/ demo") public class DemoServlet extends HttpServlet {@ Override protected void doGet (HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {String msg = req.getParameter ("message") String contextPath= req.getServletContext () .getContextPath (); System.out.println ("contextPath=" + contextPath); resp.getWriter () .println (msg);}}
Web.xml has nothing, just to pack.
Archetype Created Web Application
Archetype Created Web Application
Index.jsp doesn't have much to say about that:
Hello World!
Use the mvn command to package war.
Copy the printed war package (in fact, the same is true for copying the my-web-maven folder) to the webapps directory in tomcat:
Then go to the bin directory and double-click
After the project is up and running, visit http://localhost:8080/
It proves that our project has been launched successfully.
Next, let's visit the Servlet we wrote:
Http://localhost:8080/demo?message=hello
Error, HTTP status 404-not found
Note: when visiting here, we need to treat the project name as contextPath, that is, the access method should be:
Output on http://localhost:8080/my-web-maven/demo?message=hello page
Hello
Easy to fix, so that our project can be successfully deployed to tomcat.
Projects in IDEA are deployed to tomcat
Create a servlet project with the name my-servlet.
Create a new class MyServlet
Go to the tomcat directory we just installed, go to the lib directory, and select servlet-api.jar.
Click ok.
Click Apply, and then click OK.
Modify MyServlet content:
Package com.tian.servlet; import javax.servlet.*; import java.io.IOException; import java.io.PrintWriter; / / to implement the interface Servlet, you must override the following methods public class MyServlet implements Servlet {private transient ServletConfig servletConfig; @ Override public void init (ServletConfig servletConfig) throws ServletException {this.servletConfig = servletConfig } @ Override public ServletConfig getServletConfig () {return servletConfig;} @ Override public void service (ServletRequest request, ServletResponse response) throws ServletException, IOException {String servletName = servletConfig.getServletName (); / / Web page response type, which is rendered by the browser as HTML format response.setContentType ("text/html") PrintWriter writer = response.getWriter (); writer.println ("" + "Hello this is" + servletName + ");} @ Override public String getServletInfo () {return" my first Servlet ";} @ Override public void destroy () {}}
Modify the contents of the web.xml file:
MyServlet com.tian.servlet.MyServlet myServlet / demo
In addition, we modify the index.jsp content, mainly for a better demonstration:
Hello world
IDEA integrated tomcat
Add our installed tomcat to our IDEA:
Go to the interface of tomcat configuration:
Configure tomcat:
Enter the installation directory:
Click OK
Then go to the deployment column:
Add the servlet project we created:
Automatically added our project.
Then click Apply, and then click OK.
IDEA integrates tomcat and correlates our project. Let's run it next:
Start tomcat
Click on the green triangle:
Prove that our project has been launched successfully in tomcat.
Visit our servlet
At this point, we can visit our servlet.
Visit: the http://localhost:8080/ page shows the contents of the index.jsp that we modified earlier.
Then visit our own Servlet:
Http://localhost:8080/demo
Successfully put our content out.
This is the end of the introduction to Tomcat. Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.