1、下載tomcat
2、配置環境變量
在“我的電腦”(右鍵)->“屬性”->“高級屬性設置”->“環境變量”-“系統屬性”-“系統變量”中添加TOMCAT_HOME=D:\apache-tomcat-9.0.50(此路徑爲你解壓文件夾所在的絕對路徑)
在CLASSPATH中最後添加%TOMCAT_HOME%\lib\servlet-api.jar;
在Path中最前添加%TOMCAT_HOME%\bin;
具體配置詳情百度即可
3、修改conf路徑下server.xml配置文件
添加如下內容<!-- A "Service" is a collection of one or more "Connectors" that share a single "Container" Note: A "Service" is not itself a "Container", so you may not define subcomponents such as "Valves" at this level. Documentation at /docs/config/service.html --> <Service name="newtest"> <!--分配8089端口 --> <Connector port="8089" protocol="HTTP/1.1" connectionTimeout="20000" URIEncoding="UTF-8" redirectPort="8443" /> <Engine name="newtest" defaultHost="localhost"> <!--name爲項目訪問地址 此配置的訪問爲http://localhost:8089 appBase配置tomcat下wabapps下的路徑--> <Host name="localhost" appBase="D:\install\tomcat\apache-tomcat-10.0.21\webapps" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false"> <!--資源地址--> <!-- 就是訪問http://localhost:8089這個地址就是到E://TangRenFileServer//images這個目錄下 --> <Context path="" docBase="D:\files\expense" debug="0" reloadable="false"/> </Host> </Engine> </Service>
此時通過localhost:8089訪問的就是 本地的路徑 D:\files\expense
注意:cmd窗口中文亂碼解決
進入到tomcat的安裝目錄D:\install\works\apache-tomcat-8.5.70\conf,打開logging.properties文件,將UTF-8格式改成GBK即可。