Web application package publishing and optimization project URL

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 jarfile, 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 jarfiles can't.

The final form we package the web application into is a warfile (war package).

(1) Right-click the project in eclipse , then Exportselect WAR file, generate the WAR file of the project.

(2) Put the generated WAR file in the webappsfolder after tomcat decompression.

(3) Start tomcat, double-click the bindirectory in the tomcat decompressed file startup.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.

  1. First find your tomcat installation location on your computer
    insert image description here
  2. Open tomcat to findconf
    insert image description here
  3. Open conf to find the tomcat core configuration fileserve.xml
    insert image description here
  4. 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 here port="8080"to port="80".
    insert image description here
    insert image description here
  5. 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 here path="/FirstServlet"to path="/".
    insert image description here
  6. After we moved tomcat, entering the original path has failed to load the page successfully.
    insert image description here
    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.
    insert image description here

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…

Guess you like

Origin blog.csdn.net/apple_51673523/article/details/123099497