VSCode To Create A Maven Web APP Integrating Tomcat7 For Development. && Customizing Customised Archetype && Deployment Tomcat

Watching a movie and wanted to explore java web project creation with custom filter, recently met with an error running a java web project, tomcat6 seems to be quite different from other versions of tomcat, since using default tomcat6 can't run the app, but tomcat7 plugin launches the demo project successfully.

So, creating it, 

1. mvn archetype:generate, choose 10 and created an empty app

2. in src/main folder, add java dir, and write AppFilter, add maven dependency javax.servlet.*, the AppFilter implements IFilter in the package, add init method to override abstract method, and in doFilter method, to process normal text display, (I used https://mvnrepository.com/ this maven repository to search for maven packages and pasted to pom.xml),

public void doFilter(ServletRequest arg0, ServletResponse arg1, FilterChain arg2)
throwsIOException, ServletException {
arg2.doFilter(arg0, arg1);
3. in web-inf/web.xml, add filter section:

in the <webapp> tags, add maven tomcat7 plugin section to build section in pom.xml:


<!-- Tomcat plugin-->
<port>9000</port> //配置Tomcat的访问端口
<path>/jwebapp</path> //配置Web的上下文路径
4. launch with: mvn tomcat7:run
5. visit localhost:9000/jwebapp, see the normal Chinese characters displayed,
, just made a mistake, thought about this error and suddenly realized, tomcat6? my jdk version is openjdk11, of course, tomcat6 can load the project!!!
Tomcat version and project JDK version must match or be compatible,
in my case: the project tomcat6+java1.8, my local catalina: 9.0, +openjdk11, I was trying to launch the java1.8 project in catalina9, and met with error,
But after Tomcat9, Filter class is now HttpFilter, no wonder all the routes did not take effect,
Since tomcat6 is not updating, tomcat9 is not compatible, using tomcat embeded can be a choice, 
trying to run tomcat6 under java11 environment yields, can't create Java virtual machine, JVM,
Or use jetty or other servers,
use java1.8 and tomcat6, for newer versions of java, choose wise, 
How to deploy a war:
I used mvn tomcat7:deploy, but always failed, after investigation, configured pom.xml
<port>8080</port> //配置Tomcat的访问端口
<path>/jwebapp</path> //配置Web的上下文路径
then tomcat9 catalina, server.xml, it actually requires roles to perform the deploy action,
<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<role rolename="admin-script"/>
<user password="tomcat" roles="manager-script,admin-script,manager-gui" username="tomcat"/>
the manager script role is required, this is the correct way to deploy the app that worked for me!
failed to deploy with the admin gui specifying path for war, it might still also for this reason, lacking server.xml role privilege, since the tomcat-user I created only had manager-gui role, all apps are launched successfully,
and the final deployment path is:
, war in the webapps root directory, and pages in separate folders,
Mark this process:
It takes me 2 or 3 days from downloading a javaweb project source code, wanted to deploy, knowing javaweb, trying customizing different jdks and tomcats, privileges, filters, experiment, run, finally got everything up running. When at certain time, I suddenly think of deploying and exploring javaweb project type, if you don't think of the problems, you will never explore, and when you explore and fail, if you stop trying, the answers will never come out, so I made it to the bottom most level to this issue, and having these running knowing the tomcat user privileges, what a painful lesson and so rock hard experience!
Actually I became arrogant in the middle, since I was totally unfamiliar with all these, everything first time think of digging so deep, but I knew it felt it was just I got bored or tired getting stuck no progress, there were more versions to download and try, but it really takes time! Answers keep floating up when more versions are tried,,,, and I have turned myself over many times. Like I thought it was tomcat and jdk version not match, blabla, errors and assumptions or allegations not verified...
And I need to watch my animes now :)
Config remote deploy and yum tomcat:
remote is a Centos linux server using yum package manager,
yum install -y tomcat tomcat-examples tomcat-admin-webapps, service tomcat restart, config tomcat admin and users;
in pom.xml, after setting up database: mysql -h {server} -uroot -p {database} <db.sql
the tomcat maven plugin is now with:
<!-- <port>8080</port> //配置Tomcat的访问端口 -->
<path>/yourapp</path> //配置Web的上下文路径
<update>false</update>// if already exists
mvn tomcat7:deploy,
to redeploy: mvn tomcat7:redeploy
to undeploy: mvn tomcat7:undeploy
Deploy with mvn cargo plugin,
Leave your comment
6/1/2023 8:40 AM
webpage tells https page references http source,
need to add to location /{
add_header Content_Security_Policy upgrade_insecure_requests;
6/1/2023 12:59 PM
nginx, https, tomcat:
should be both https:
tomcat: server.xml->connector 8080 add attribute scheme="https",