foreword
After we complete a Web file, we have to package or publish the application. Today, let's sort out how to package or publish Web files.
Packaging and Publishing of Java Web
When we package a Java file, we package it into a jar
file, but not for Java Web files.
Because there are not only Java files but also HTML, JSP and other files in the Web files, we need to package them together. So jar
files can't.
The final form we package the web application into is a war
file (war package).
(1) Right-click the project in eclipse , then
Export
selectWAR file
, generate the WAR file of the project.(2) Put the generated WAR file in the
webapps
folder after tomcat decompression.(3) Start tomcat, double-click the
bin
directory in the tomcat decompressed filestartup.bat
.(4) Enter the file URL (eg: ) in the browser
http://localhost:8080/FirstServlet/anno
.
Optimize URLs
But the file paths we have entered so far all contain the port number (8080) and Contextpath (file path). When we generally enter the URL, such as: www.baidu.com. They are all very short without the so-called port number and the file path of the corresponding page.
Then let's simplify the URL to the degree we want.
- First find your tomcat installation location on your computer
- Open tomcat to find
conf
- Open conf to find the tomcat core configuration file
serve.xml
- Open this file, find it about line 62
<Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443" URIEncoding = "UTF-8" />
, and then change the hereport="8080"
toport="80"
.
- Continue to find at the end of the servlet.xml file
<Context docBase="D:\java_app\apache-tomcat-10.0.12\webapps\FirstServlet" path="/FirstServlet" reloadable="true" source="org.eclipse.jst.jee.server:FirstServlet"/>
, and then change the herepath="/FirstServlet"
topath="/"
.
- After we moved tomcat, entering the original path has failed to load the page successfully.
Then we simply modify the URL, remove the port number and the file path of the page, and we will find that the page is successfully output. It means that we have successfully optimized the URL.
Epilogue
So far, the tutorial is relatively simple, and it is too lazy to package and publish without diagrams. But it is very easy to complete by following the steps.
This column is continuously updated…