tags:

views:

71

answers:

3

I've recently run into a snag that will probably keep me from being able to follow through with plans to package a single WAR with two servlets. The work-around is to create an extra Maven WAR module.

Besides the extra hassle for me and for customers, is there any other real drawback? are there advantages?

@Edit

The "snag" I have run into is that I want two different authentication mechanisms for each servlet. One to use Spring Security and the other either a different authentication provider or possibly Basic authentication. See here:

http://stackoverflow.com/questions/3766004/is-it-possible-to-use-a-different-spring-security-authenticationprovider-in-diffe

A: 

A WAR can contain any number of servlets. You should really not be having issues with more than one servlet per WAR.

Maybe you could elaborate on your problem with more than one servlet.

Steven
+3  A: 

The main drawback is that the web application container keeps the separate applications completely apart from each-other. So if they use a common set of jar files (for example), they will each have to load their own version, which takes up a lot of memory. Also, they cannot really communicate with each-other via Session or ServletContext, or request forwarding.

The advantage only comes from situations where you really think of the two WAR as independent applications.

If the two servlets belong together you should put them into the same WAR.

Thilo
+1  A: 

If you are using container based authentication, that is done per webapp I presume. However, if authentication is done in the servlet or through filters, there is no problem having 2 servlets with different authentication mechanisms in the same webapp.

For Spring, it will layer authentication on top off the dispatchservlet mapping. If you are using a filter, make sure it matches the path for each servlet to only auth for that servlet.

<filter>
  <filter-name>auth1</filter-name>
  <filter-class>...</filter-class>
</filter>
<filter>
  <filter-name>auth2</filter-name>
  <filter-class>...</filter-class>
</filter>

<filter-mapping>
  <filter-name>auth1</filter-name>
  <url-pattern>auth1/*</url-pattern>
</filter-mapping>
<filter-mapping>
  <filter-name>auth2</filter-name>
  <url-pattern>auth2/*</url-pattern>
</filter-mapping>
Staale
Holy cow, is that simple. I'll look into this and possibly post an answer in the other question. This is perfect if we go with two flavors of Spring Security authentication. How about if you want "/auth2" to be basic authentication?
HDave