Tomcat 官网 - https://tomcat.apache.org/
jdk1.8.0_191 我选择的 Tomcat 8.5.16 ,后来更改为 8.5.58
说明:项目页面是.shtm结尾的文件
SSI(Server Side Includes)是在HTML静态页面中使用的指令,当页面在服务端执行的时候是可以进行服务端解析的。
学习链接 :Tomcat之——SSI的配置
如果发现Tomcat运行后,静态页面显示,动态页面不显示了,那可能是conf文件夹下的文件需要配置
① 打开 conf/web.xml
文件
1. Servlet配置,此处注释放开
<servlet>
<servlet-name>ssiservlet-name>
<servlet-class>
org.apache.catalina.ssi.SSIServlet
servlet-class>
<init-param>
<param-name>bufferedparam-name>
<param-value>1param-value>
init-param>
<init-param>
<param-name>debugparam-name>
<param-value>0param-value>
init-param>
<init-param>
<param-name>expiresparam-name>
<param-value>666param-value>
init-param>
<init-param>
<param-name>isVirtualWebappRelativeparam-name>
<param-value>falseparam-value>
init-param>
<load-on-startup>4load-on-startup>
servlet>
2.ServletMapping配置,此处注释放开,原本 *.shtml 因我的项目页面后缀是shtm结尾,更改为 *.shtm
<servlet-mapping>
<servlet-name>ssiservlet-name>
<url-pattern>*.shtmurl-pattern>
servlet-mapping>
3.Filter配置,注释放开
<filter>
<filter-name>ssifilter-name>
<filter-class>
org.apache.catalina.ssi.SSIFilter
filter-class>
<init-param>
<param-name>contentTypeparam-name>
<param-value>text/x-server-parsed-html(;.*)?param-value>
init-param>
<init-param>
<param-name>debugparam-name>
<param-value>0param-value>
init-param>
<init-param>
<param-name>expiresparam-name>
<param-value>666param-value>
init-param>
<init-param>
<param-name>isVirtualWebappRelativeparam-name>
<param-value>falseparam-value>
init-param>
filter>
4.FilterMapping配置,注释放开,注意我的是shtm,根据你们自己的情况,可能你们是shtml
<filter-mapping>
<filter-name>ssifilter-name>
<url-pattern>*.shtmurl-pattern>
filter-mapping>
5. mime-mapping 取消注释,注意是我的是shtm
<mime-mapping>
<extension>shtmextension>
<mime-type>text/x-server-parsed-htmlmime-type>
mime-mapping>
再添加一个 mime-mapping
<mime-mapping>
<extension>shtmextension>
<mime-type>text/htmlmime-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>ssiservlet-name>
<servlet-class>
org.apache.catalina.ssi.SSIServlet
servlet-class>
<init-param>
<param-name>bufferedparam-name>
<param-value>1param-value>
init-param>
<init-param>
<param-name>debugparam-name>
<param-value>0param-value>
init-param>
<init-param>
<param-name>expiresparam-name>
<param-value>666param-value>
init-param>
<init-param>
<param-name>isVirtualWebappRelativeparam-name>
<param-value>falseparam-value>
init-param>
<init-param>
<param-name>inputEncodingparam-name>
<param-value>utf-8param-value>
init-param>
<init-param>
<param-name>outputEncodingparam-name>
<param-value>utf-8param-value>
init-param>
<load-on-startup>4load-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>defaultservlet-name>
<servlet-class>org.apache.catalina.servlets.DefaultServletservlet-class>
<init-param>
<param-name>debugparam-name>
<param-value>0param-value>
init-param>
<init-param>
<param-name>fileEncodingparam-name>
<param-value>UTF-8param-value>
init-param>
<init-param>
<param-name>listingsparam-name>
<param-value>falseparam-value>
init-param>
<load-on-startup>1load-on-startup>
servlet>
④ 再次重启项目,此时静态动态数据都正常了
② 添加 Tomcat server,选择local,进行配置
配置好后,点击 apply 再 点击 ok
③ 选择 file → project settings
(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重启
进入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
重启完成