Set CORS header in Tomcat

If it’s a static site, then starting with Tomcat 7.0.41, you can easily control CORS behavior via a built-in filter. References: Tomcat 7 Tomcat 9 Pretty much the only thing you have to do is edit the global web.xml in CATALINA_HOME/conf and add the filter definition: <!– ================== Built In Filter Definitions ===================== –> … … Read more

deploying multiple applications to Tomcat

If you want Tomcat to listen to multiple ports, you need to setup a connector for each port. To get each port mapped to a different application, you need need to wrap each connector in a service and create a host with it’s own appBase. Example of service definition in server.xml: <Service name=”foo”> <Connector port=”80″ … Read more

How to avoid storing passwords in the clear for tomcat’s server.xml Resource definition of a DataSource?

As said before encrypting passwords is just moving the problem somewhere else. Anyway, it’s quite simple. Just write a class with static fields for your secret key and so on, and static methods to encrypt, decrypt your passwords. Encrypt your password in Tomcat’s configuration file (server.xml or yourapp.xml…) using this class. And to decrypt the … Read more

java.lang.IllegalArgumentException: Invalid in servlet mapping

<url-pattern>*NEXTEVENT*</url-pattern> The URL pattern is not valid. It can either end in an asterisk or start with one (to denote a file extension mapping). The url-pattern specification: A string beginning with a ‘/’ character and ending with a ‘/*’ suffix is used for path mapping. A string beginning with a ‘*.’ prefix is used as … Read more

Add JVM options in Tomcat

As Bhavik Shah says, you can do it in JAVA_OPTS, but the recommended way (as per catalina.sh) is to use CATALINA_OPTS: # CATALINA_OPTS (Optional) Java runtime options used when the “start”, # “run” or “debug” command is executed. # Include here and not in JAVA_OPTS all options, that should # only be used by Tomcat … Read more

How does Tomcat locate the webapps directory?

It can be changed in the $CATALINA_BASE/conf/server.xml in the <Host />. See the Tomcat documentation, specifically the section in regards to the Host container: Tomcat 6 Configuration Tomcat 7 Configuration The default is webapps relative to the $CATALINA_BASE. An absolute pathname can be used.

Tomcat support for HTTP/2.0?

I’m the HTTP/2 implementer in Jetty, and I watch out other projects implementing HTTP/2. Tomcat’s Mark Thomas has outlined support for HTTP/2 for Tomcat 9. Update Jan 2017: Tomcat 8.5 supports HTTP/2 see @joe-aldrich answer https://stackoverflow.com/a/37889873/2027465 Considering that Servlet 4.0 is going to have as a target HTTP/2 support, and that HTTP/2 support requires ALPN … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)