Maven: Customize web.xml of web-app project

is there a way to have two web.xml files and select the appropriate one depending on the profile? Yes, within each profile you can add a configuration of the maven-war-plugin and configure each to point at a different web.xml. <profiles> <profile> <id>profile1</id> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <configuration> <webXml>/path/to/webXml1</webXml> </configuration> </plugin> … As an alternative … Read more

Why do we use web.xml? [closed]

Generally speaking, this is the configuration file of web applications in java. It instructs the servlet container (tomcat for ex.) which classes to load, what parameters to set in the context, and how to intercept requests coming from browsers. There you specify: what servlets (and filters) you want to use and what URLs you want … Read more

Moving resources under WEB-INF

What is the easiest method for me to safely move all html/js/images folders under the WEB-INF without breaking all links/forwarding to resources in these folders and make sure these resources are not directly accessible? You’re making a thiniking mistake here. HTML/JS/image (and CSS) resources need to be directly accessible anyway. For JSPs the story is … Read more

Is security-constraint configuration for Tomcat mandatory?

No, it’s not necessary. It means that your web application only available through HTTPS (and not available through HTTP). If you omit the <transport-guarantee>CONFIDENTIAL</transport-guarantee> tag (or the whole <security-constraint>) your application will be available through both HTTP and HTTPS. If your web.xml contains <transport-guarantee>CONFIDENTIAL</transport-guarantee> Tomcat automatically redirects the requests to the SSL port if you … Read more

Overview of all JSF-related web.xml context parameter names and values [closed]

First of all, those starting with facelets. are not JSF context parameters, but Facelets 1.x context parameters. Previously, during JSF 1.x era, Facelets was not integrated as part of JSF. However, since JSF 2.0, Facelets is integrated as part of JSF, replacing legacy JSP as the default view technology, and most of the Facelets 1.x … Read more

Referencing Environment Variables in web.xml

You can use Ant-style variable substitution in any of the tomcat xml config files, such as: <servlet-mapping> <servlet-name>mvc-dispatcher</servlet-name> <url-pattern>${foo}</url-pattern> </servlet-mapping> Where foo is a Java System Property (sysprop). You can’t use OS Environment Variables (envvars) directly, I think… To use envvars, you can put set “CATALINA_OPTS=-DsomeJavaSysProp=%SOME_OS_ENVVAR%” in bin/setenv.bat (or similarly in bin/setenv.sh for *nix). You … Read more

Do I really need web.xml for a Servlet based Java web application?

You don’t need a web.xml file if you have a container that supports the latest j2ee specs. Here is a link to an simple servlet example that use an annotation and here you can find the same for Spring MVC; I post the example here for you convenience public class MyWebApplicationInitializer implements WebApplicationInitializer { @Override … Read more

Whitelist security constraint in web.xml

I would try the following: <security-constraint> <web-resource-collection> <url-pattern>/*</url-pattern> <http-method>GET</http-method> <http-method>POST</http-method> </web-resource-collection> <!– no auth-constraint tag here –> </security-constraint> <security-constraint> <web-resource-collection> <web-resource-name>restricted methods</web-resource-name> <url-pattern>/*</url-pattern> </web-resource-collection> <auth-constraint/> </security-constraint> The first security-constraint does not have any auth-constraint, so the GET and POST methods are available to anyone without login. The second restricts other http methods for everybody. (I … Read more

AngularJS HTML5 Mode – How do direct links work without server specific changes?

The AngularJS documentation does in fact mention this Server side Using this mode requires URL rewriting on server side, basically you have to rewrite all your links to entry point of your application (e.g. index.html) In this case, one Java-based solution is to tell the server “map all urls to index.html.” This can be done … Read more