How to change the port of Tomcat from 8080 to 80?

1) Go to conf folder in tomcat installation directory e.g. C:\Tomcat 6.0\conf\ 2) Edit following tag in server.xml file <Connector connectionTimeout=”20000″ port=”8080″ protocol=”HTTP/1.1″ redirectPort=”8443″/> 3) Change the port=8080 value to port=80 4) Save file. 5) Stop your Tomcat and restart it.

How to change the ROOT application?

There are three methods: First shutdown your Tomcat from the its bin directory (sh shutdown.sh). Then delete all the content of your Tomcat webapps folder (rm -fr *). Then rename your WAR file to ROOT.war, and finally start your Tomcat from the bin directory (sh startup.sh). Leave your war file in $CATALINA_BASE/webapps under its original … Read more

Tomcat 10.0.4 doesn’t load servlets (@WebServlet classes) with 404 error [duplicate]

For copyright reasons the Servlet 5.0 API (implemented by Tomcat 10) and the Servlet 4.0 API (implemented by Tomcat 9) are incompatible: the API namespace changed from javax.* to jakarta.*. This can manifest in many ways: Software written for Servlet 4.0 does not compile against the API jars from Tomcat 10: cf. Servlet 5.0 JAR … Read more

Deploying my application at the root in Tomcat

You have a couple of options: Remove the out-of-the-box ROOT/ directory from tomcat and rename your war file to ROOT.war before deploying it. Deploy your war as (from your example) war_name.war and configure the context root in conf/server.xml to use your war file : <Context path=”” docBase=”war_name” debug=”0″ reloadable=”true”></Context> The first one is easier, but … Read more

Servlet 5.0 JAR throws compile error on javax.servlet.* but Servlet 4.0 JAR does not

When I place the .class file in the corresponding Tomcat directory, start the server and try to interact with the app, I get the following exception: java.lang.ClassNotFoundException: javax.servlet.http.HttpServlet I tried placing the javax.servlet-api-4.0.1 in the Tomcat/lib directory, but then I get: java.lang.ClassCastException: class com.example.controllers.BeerSelect cannot be cast to class jakarta.servlet.Servlet The jakarta.servlet.Servlet is part of … Read more

CORS issue – No ‘Access-Control-Allow-Origin’ header is present on the requested resource

CORS’ preflight request uses HTTP OPTIONS without credentials, see Cross-Origin Resource Sharing: Otherwise, make a preflight request. Fetch the request URL from origin source origin using referrer source as override referrer source with the manual redirect flag and the block cookies flag set, using the method OPTIONS, and with the following additional constraints: Include an … Read more

java.lang.IllegalArgumentException: The servlets named [X] and [Y] are both mapped to the url-pattern [/url] which is not permitted

Caused by: java.lang.IllegalArgumentException: The servlets named [ControllerServlet] and [com.classmgt.servlet.ControllerServlet] are both mapped to the url-pattern [/ControllerServlet] which is not permitted It seems that you have mixed @WebServlet annotation based and web.xml based configuration. I doubt that you created a Servlet using the “Create Servlet” wizard which creates web.xml entry with url-pattern and then , added … Read more

How should I connect to JDBC database / datasource in a servlet based application?

A common practice is to configure this as a DataSource in the servlet container in question. It will provide you connection pooling facilities which will greatly improve performance. Also a common practice is to externalize the raw settings in some configuration file which is been placed in the classpath. In case you’re using Tomcat as … Read more