This article mainly introduces the introduction of tomcat, and introduces tomcat and the basic configuration of Tomcat in detail. It has certain reference value. Those who are interested can learn about it
tomcat introduction:
The web server can only complete requests for static resources;
The web container can request dynamic resources;
tomcat is the simplest web container and is a sub-project of Apache's jarkata project.
tomcat 7.0.X supports the Servlet 3.0 specification, so it is recommended to use 7.0.X;
tomcat has two versions:
(1) Binary version: Environment variables need to be configured after decompression. It is recommended to use this version.
(2) Service version: executable file, the service will be registered in the system after installation.
tomcat directory introduction:
tomcat has Several folders:
(1)bin: stores executable commands, such as opening and closing tomcat: startup.bat;
(2)conf: configuration file.
(3)webapps: Publish web applications.
(4)lib: library file, which can be expanded through this directory, such as placing the database driver in this file.
(5)work: Temporary Java or class file.
Tomcat basic configuration
Note: Do not place Tomcat in a Chinese directory or a directory with spaces;
1. Configure environment variables
1. Configure JAVA_HOME: C:\Java\jdk1.6.0_27
2. Configure CATALINA_HOME: C:\ apache-tomcat-7.0.6 (This environment variable does not need to be configured)
Take my configuration as an example and adjust it according to your own installation location;
catalina_home is configured In the future, when the situation as shown in the figure appears:
When you click C:\tomcat\bin\startup.bat, D:\tomcat
##2. Configure the port
The default is 8080, which can be configured in tomcat/conf/server.xml.
<Connector port="8888" protocol="HTTP/1.1" //此处可以把8888换成任意端口. connectionTimeout="20000" redirectPort="8443" />
Port Occupied problem:
Solution:
3. Configure user roles
<role rolename="manager-gui"/> <user username="admin" password="12345" roles="manager-gui"/> //用户名为admin,密码为12345
4. Configure and deploy web application path
1. You can deploy it in the webapps directory, that is, copy the entire web application directly to webapps.<?xml version="1.0" encoding="GBK"?> <Context docBase="F:/publish" debug="0" privileged="true"> //docBase是路径,可以自己调整 </Context>
Common points to note:
##
<param-name>listings</param-name> <param-value>false</param-value>改成true
in conf/web.xml
<welcome-file>index.html</welcome-file>
说明默认为index.html,因此如果输入http://localhost:8080/test则会自动调用index.html.
4.每个web应用中都需要WEB-INF和web.xml文件,最简单的办法就是去tomcat主目录下的webapps/ROOT/的WEB-INF拷贝到你所需要的web应用文件夹下。
5.第一次用户请求某个JSP会比较慢。
原因:JSP首先会转换成JAVA文件,然后再编译成class文件,最后才执行,这些java和class的文件都在tomcat主目录的work文件夹下。
HTTP常见状态:
(1)404错误:客户路径不正确造成。
(2)500错误:服务器内部错误。
因此总的来说:
(1)2##:请求成功。
(2)4##:客户端错误。
(3)5##:服务器错误。
JSP文件简介:HTML+JAVA代码。
<%。。。%>中嵌入java代码。
在html中