Tomcat项目更新Tomcat版本,重新配置conf,并在Idea运行项目
1.下载Tomcat包
Tomcat 官网 - https://tomcat.apache.org/
jdk1.8.0_191 我选择的 Tomcat 8.5.16 ,后来更改为 8.5.58
2.Tomcat配置-ssi配置
说明:项目页面是.shtm结尾的文件
SSI(Server Side Includes)是在HTML静态页面中使用的指令,当页面在服务端执行的时候是可以进行服务端解析的。
如果发现Tomcat运行后,静态页面显示,动态页面不显示了,那可能是conf文件夹下的文件需要配置
① 打开 conf/web.xml
文件
1. Servlet配置,此处注释放开
<servlet>
<servlet-name>ssi</servlet-name>
<servlet-class>
org.apache.catalina.ssi.SSIServlet
</servlet-class>
<init-param>
<param-name>buffered</param-name>
<param-value>1</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>0</param-value>
</init-param>
<init-param>
<param-name>expires</param-name>
<param-value>666</param-value>
</init-param>
<init-param>
<param-name>isVirtualWebappRelative</param-name>
<param-value>false</param-value>
</init-param>
<load-on-startup>4</load-on-startup>
</servlet>
2.ServletMapping配置,此处注释放开,原本 *.shtml 因我的项目页面后缀是shtm结尾,更改为 *.shtm
<servlet-mapping>
<servlet-name>ssi</servlet-name>
<url-pattern>*.shtm</url-pattern>
</servlet-mapping>
3.Filter配置,注释放开
<filter>
<filter-name>ssi</filter-name>
<filter-class>
org.apache.catalina.ssi.SSIFilter
</filter-class>
<init-param>
<param-name>contentType</param-name>
<param-value>text/x-server-parsed-html(;.*)?</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>0</param-value>
</init-param>
<init-param>
<param-name>expires</param-name>
<param-value>666</param-value>
</init-param>
<init-param>
<param-name>isVirtualWebappRelative</param-name>
<param-value>false</param-value>
</init-param>
</filter>
4.FilterMapping配置,注释放开,注意我的是shtm,根据你们自己的情况,可能你们是shtml
<filter-mapping>
<filter-name>ssi</filter-name>
<url-pattern>*.shtm</url-pattern>
</filter-mapping>
5. mime-mapping 取消注释,注意是我的是shtm
<mime-mapping>
<extension>shtm</extension>
<mime-type>text/x-server-parsed-html</mime-type>
</mime-mapping>
再添加一个 mime-mapping
<mime-mapping>
<extension>shtm</extension>
<mime-type>text/html</mime-type>
</mime-mapping>
② 重启项目
可能会出现重启失败,报错如下,我运行时出现了
java.lang.SecurityException: Filter of class org.apache.catalina.ssi.SSIFilter(SSIServlet) is privilegedand cannot be loaded by this web application
解决方式:在 conf/context.xml
文件中为Context标签添加 privileged
属性
<Context privileged="true"> ... </Context>
③ 页面乱码与解决
修改conf/web.xml
中的 Servlet 配置
<servlet>
<servlet-name>ssi</servlet-name>
<servlet-class>
org.apache.catalina.ssi.SSIServlet
</servlet-class>
<init-param>
<param-name>buffered</param-name>
<param-value>1</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>0</param-value>
</init-param>
<init-param>
<param-name>expires</param-name>
<param-value>666</param-value>
</init-param>
<init-param>
<param-name>isVirtualWebappRelative</param-name>
<param-value>false</param-value>
</init-param>
<init-param>
<param-name>inputEncoding</param-name>
<param-value>utf-8</param-value>
</init-param>
<init-param>
<param-name>outputEncoding</param-name>
<param-value>utf-8</param-value>
</init-param>
<load-on-startup>4</load-on-startup>
</servlet>
此时发现,页面动态数据的地方恢复,静态部分还是乱码
学习链接:解决tomcat部署项目中静态页面(html)显示中文乱码
1. conf / server.xml 文件 ,为 Connector 标签添加 URLEncoding属性
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443"
URLEncoding="UTF-8" />
2. conf / web.xml 文件 ,添加 fileEncoding 配置
<servlet>
<servlet-name>default</servlet-name>
<servlet-class>org.apache.catalina.servlets.DefaultServlet</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>0</param-value>
</init-param>
<init-param>
<param-name>fileEncoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>listings</param-name>
<param-value>false</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
④ 再次重启项目,此时静态动态数据都正常了
3.Idea运行 Tomcat 项目
① 编辑配置
② 添加 Tomcat server,选择local,进行配置
配置好后,点击 apply 再 点击 ok
③ 选择 file → project settings
4.服务器Tomcat替换SSL证书
(1)进入Tomcat文件位置,查看server.xml 文件
cd /data/**/apache-tomcat-8.5.16/conf/
里面的 server.xml 设置了 keystoreFile="/data/tomcat.jks" keystorePass="**.gov2022"
(2)替换tomcat.jks文件
cd /data/tomcat.jks 替换掉
然后在 server.xml 文件修改 keystorePass 对应的密码
(3)tomcat重启
4. Tomcat 项目重启
进入bin文件夹 cd data/***/apache-tomcat-8.5.16/bin
查看运行的项目命令:ps aux|grep tomcat
停止项目:./shutdown.sh
查看运行的项目命令:ps aux|grep tomcats
运行项目:./startup.sh
查看运行的项目命令:ps aux|grep tomcat
重启完成