首页 > 代码库 > About Tomcat!
About Tomcat!
Tomcat is a free server.
The detail of Tomcat directory structure:
bin --> include some batch file and jar file. For example : the start and shutdown command settled in this folder
conf --> many configuration file located here such as server.xml and web.xml
lib --> the necessary jar files are included : servlet-api.jar, jsp-api.jar. So we can make the conclusion: Tomcat server support Servlet and JSP.
logs --> there‘re some log files
temp --> when you upload a picture or some other file , the file will be put in this folder
webapps --> this is the most important folder. We can see that all of our applications are put here and there are much information in its child folder:
WEB-INF --> the WEB-INF won‘t be modified because some key files are put here, if they can be changed easily , it‘s not a secure choice.
classes --> the classes file whilch related to the application are put here.
lib --> the jar file will be built path automatically in this folder
web.xml --> this is the key configuration file which could connect the class file with the server.In the main body part:
<servlet>
<servlet-name></servlet-name>
<servlet-class></servlet-class>
</servlet>
<servlet-mapping>
<servlet-name></servlet-name>
<url-pattern></url-pattern>
</servlet-mapping>
These two tags could be very useful.
work --> the app has runned before will be put here , if you find your server starts at a low speed , you can make a clearance of this folder.
Also , there is a very important method to create a war file:
Run the cmd and go to the app‘s directory via command.
Then you should input :
jar -cvf myapp.war .
to create the war file.
You‘ll find the war file in the webapp folder.But why should we create the war file?
You can assume the occasion, if you run your code at your customer, there maybe doesn‘t have myEclipse or IntelliJ. Once you have you war file in your
hand, you should only copy the file and the Tomcat will create the folder automatically which also will relate the class file . It‘s really convenient.
To use the Tomcat more flexible , we can use the virtual path:
Open the server.xml in the config folder.
Add the tag: <Context path="/appsw" docBase="e:/myapp"/> then save and close the server.xml.
The next step you should do is to execute the shutdown.bat and restart the Tomcat server.
You can use the url : http://localhost:8080/appsw/1.html
We can see that the appsw represent the path : e:/myapp
But there remains a disastrous problem: we can see that if we want to use the virual path , we must close the server and restart it.
If there‘re many users are using our application, this behavior will lead to break down.So use the external file to set the Context is very necessary.
So to slove it ,we can see the Tomcat‘s index.html:
Configuration --> Context --> Defining a context --> The second method
The context path is the file‘s name.And you only need to set the Context‘s docBase attribute : <Context docBase="e:/myapp"/>
About Tomcat!