tomcat's work directory

1 When using tomcat as a web server, the deployed programs are under webApps, and these programs are compiled programs (classes contained in projects published to tomcat will be compiled into .classes before they are published, and the source files are not published. come, but the jsp here is not compiled) . Tomcat has a work directory, which stores the cache of the page, and the accessed jsp will be compiled (such as the project under the localhost site folder after entering Catalina from the work, we can see that those jsp pages will be compiled into servlet files). , the next time you visit again, you can directly run the servlet class to respond to the page to the client, so some blogs say that the first visit will be slower because the newly published page is accessed by the first person. , it will be compiled into a servlet file first, so it is slow. Once compiled, unless the jsp page is modified, the servlet will be able to respond to the user next time when it is accessed directly, so it is fast) , and the compiled files will be stored in the work directory. The directory displayed by tomcat will find the class file corresponding to the compiled jsp from this cache. So when the work directory is emptied, the process will start all over again.     
    Sometimes a problem will be encountered, that is, the modified page cannot display the modified traces when tomcat is running. At this time, delete the corresponding project folder in the work directory and restart tomcat.

2 After the Host name is configured in the server.xml file under the conf configuration folder of tomcat, a folder with the site name will be created under the Catalina folder under conf and the Catalina file under work. It will also be recorded in the configuration file of the Catalina folder under conf.

 Recently, I found that many netizens like to call the things in the work directory of tomcat as cache. In fact, it is not very appropriate. The work directory is only the working directory of tomcat, that is, the working directory of tomcat converts jsp into class files. This is why it The reason for calling the work directory instead of the cache directory. 
  The working principle of jsp and tomcat is that when a browser accesses a jsp page, tomcat will convert the jsp page into a .java file in the work directory, for example, convert index.jsp into an index_jsp.java file, and then compile it into index_jsp. class file, and finally the tomcat container loads the index_jsp.class class into the memory through the ClassLoader class to respond to the client.

  Tomcat will periodically scan the jsp files in the container, read the attributes of each file, and when it finds that a jsp file has changed (the last modification time of the file is different from the last scan), tomcat will re-convert, Compile this jsp file. But tomcat's brief description is timed and not real-time, which is why it takes a few minutes for the modified jsp to take effect after the jsp file is modified. Of course, in order to take effect immediately, many seniors will suggest to clear the files in the work directory immediately after modifying the jsp page.

  In addition, in the tomcat container, the compilation of the converted java files (for example: index_jsp.java) only supports a maximum of 64k, so when the jsp in other containers is transplanted to the tomcat container, it will encounter large jsp files and will fail to compile. Therefore, it is recommended to write the business logic in the jsp into a separate class, execute it in the jsp by calling the static method of this class, and extract the js in the jsp page and put it in a separate js file.


Problem domain: 
    How to let Tomcat update the class automatically. 
Solution: 
1. 
Create a separate configuration file under the installed tomcat path. 
For example: 
Create a file: D:\Tomcat5.5\conf\Catalina\localhost\testapp.xml with 

the content: 
<Context docBase="D:\Tomcat5.5\webapps\testapp" reloadable="true" path="/ testapp" workDir="work\Catalina\localhost\testapp"> 
</Context> 

Restart Tomcat 

Second, 
directly add the following content to the tomcat configuration file conf/server.xml: 
<Context docBase="D:\Tomcat5.5\ webapps\testapp" reloadable="true" path="/testapp" workDir="work\Catalina\localhost\testapp"> 
</Context> 
Note that it is added under the <Engine name="Catalina" defaultHost="localhost"> tag ; 
restart Tomcat

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325806798&siteId=291194637