Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Brief introduction of tomcat _ Power Node Java College arrangement

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Tomcat introduced:

Web servers can only fulfill requests for static resources;

Web containers can make requests for dynamic resources;

Tomcat is one of the simplest web containers, a subproject of apache's jarkata project.

tomcat 7.0.X supports Servlet 3.0 specification, so 7.0.X is recommended;

Tomcat comes in two versions:

(1)Binary version: After decompression, you need to configure environment variables. This version is recommended.

(2)Service version: executable file, installed in the system will register the service.

tomcat catalog introduction:

Tomcat has several folders:

(1)bin: stores executable commands, such as opening and closing tomcat: startup.bat;

(2)conf: configuration file.

Webapps: Publishing web applications.

(4)lib: library file, which can be extended through this directory, such as placing database drivers in this file.

(5)work: temporary Java or class files.

Tomcat Basic Configuration

Note: Tomcat should not be placed in Chinese directories or directories with spaces;

1. Configure environmental variables

1. Configure JAVA_HOME: C:\Java\jdk1.6.0_27

2. Configure CATALINA_HOME: C:\apache-tomcat-7.0.6 (this environment variable can be mismatched)

Take my configuration as an example, adjust according to your installation location;

After catalina_home is configured, when the following situation occurs:

When you click C: \tomcat\bin\startup.bat, you start D:\tomcat.

II. Configuration port

The default is 8080, which can be configured in tomcat/conf/server.xml.

After configuring these, you can use tomcat. Enter http://localhost:8888 in your browser and the following page pops up:

Port occupied problem:

If other software occupies this port, tomcat will not start;

Solution:

Use FPort and other software to check port usage, and then kill this process;

3. Configure user roles

In order to manage the deployment of web applications in a page, users are required, so new users and passwords (originally no users) need to be configured.

Add the following statement to tomcat/conf/tomcat-users.xml:

//username admin, password 12345

JAAS:Java Authentication Authority Service

You can log in using the username and password you set up earlier as shown below:

IV. Configure the deployment path of web applications

1. Deployment can be done in the webapps directory, i.e. copying the entire web application directly to webapps.

2. You can create a test.xml file in the conf/catalina/localhost directory and add:

//docBase is the path, you can adjust it yourself

This can be accessed by typing http://localhost:8080/test, note that this test is the name of the xml file.

For example, if the xml file name is x.xml, enter http://localhost:8888/x

You also need to create a WEB-INF folder in F:\publish, which is the directory of web applications. In this folder, create a web.xml. In order to be lazy, you can paste the tomcat/webapps/WEB-INF/web.xml file into F:\publish\WEB-INF.

3. It can be deployed in web pages, as shown in the figure below:

It can be deployed via a war package or a path, and war packages can be exported from Eclipse.

Common points of attention:

1. Set the port number: modify it in conf/server.xml.

2. Configure the virtual directory: Add it last in conf/server.xml.

For example, enter http://localhost:8080/test in the browser to run the contents of D:\test.

Note: After configuration, also in conf/web.xml

listingsfalse changed to true

3. Configuration default home page: Last in conf/web.xml

index.html

The description defaults to index.html, so if you type http://localhost:8080/test it will automatically call index.html.

4. WEB-INF and web.xml files are required in every web application. The easiest way to do this is to go to webapps/ROOT/in tomcat and copy WEB-INF to your desired web application folder.

5. The first time a user requests a JSP, it is slower.

Reason: JSP will first be converted into JAVA files, and then compiled into class files, and finally executed, these java and class files are in the tomcat home directory under the work folder.

HTTP Common Status:

(1)404 Error: The customer path is incorrect.

500 Error: An internal server error occurred.

Thus, in summary:

(1)2##: Request successful.

(2)4##: Client error.

(3)5##: Server error.

JSP file introduction: HTML+JAVA code.

Java code is embedded.

The action attribute in html can set the jsp file that the server processes the request, for example:

Next is the simplest application tomcat program, the user enters any string such as world, the server returns hello plus the string, such as hello,world.

Demo Input content:

jsp file:

Demo

Web app directory layout recommendations:

home directory | |-WEB-INF | |- web.xml | |- classes | | |-放置class文件 | |- lib | | |-放置第三方jar包 | |- src | | |-存放源文件 |- Store jsp, html | |-image | |-存放图片

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.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report