<< DWR version 1.0 released | Home | Ajax Architecture >>

Idea for new Servlet spec

Some weeks ago Greg Murray wanted ideas for the next version of the servlet spec. I had an idea that would really help with working with many frameworks.

Originally J2EE was designed with componentization at a WAR and EJB-JAR file level. I think the idea was that you'd get a set of WAR and EJB-JAR files bundle them up in an EAR and poof! Radical new web-app. I'm sure someone will correct me and tell me that wasn't the plan, but that's certainly the way is looks to me right now.

What has happened is that things have been componentized at a more granular level. For example Spring contributes an OpenSessionInViewFilter, DWR contributes an Ajax servlet, Struts, Webwork, etc contribute controller servlets. All of these come with instructions about a whole set of incantations to put into your WEB-INF/web.xml file.

So the solution is simple - We need a new element like this:

<include src="WEB-INF/lib/dwr.jar!ajax.xml"/>

This would allow web frameworks and libraries to export a set of web.xml insert files. And you could make use of some functionality with a single line.

It might be a good idea to have a <param...> mechanism to allow you to customize the action of the web.xml insert file.

Benefits

  • Less typing, and less cut and paste errors.
  • Clearer demarcation about what does what in your web.xml file.
  • Much simpler web.xml files, you only need to define what you have written, and just link to the stuff you are re-using.
  • The ability to have several different configs and switch between them without getting lost in comments. This is particularly good for altering security settings.

What do you think?

Technorati tags:

Tags :


Re: Idea for new Servlet spec

This is a *great* idea! One area in which webapps are abysmal is extensibility support. The current syntax is great if you want to have end-user apps, but horrific when it comes to supporting frameworks or extending existing apps.

Re: Idea for new Servlet spec

Or even a new directory under /WEB-INF (something like /WEB-INF/ext for extension) which could hold jar files with META-INF/web-ext.xml files which define these parts to be added... The big problem with all of these is that Filters need to be customized for order.

Re: Idea for new Servlet spec

I also think this is a great idea. In its current state, web.xml is a monolithic beast that only applies for end-user webapps. I like Jason's idea of defining an extension directory. I would also add some dependency management, so that extension1.jar declares that it needs extension2.jar to be loaded first.

That way, you wouldn't need any ordering mechanism.

Re: Idea for new Servlet spec

The reason I originally went for the <include ...> option was, firstly it retained the concept of ordering, and secondly a framework as large as Spring could easily become a sea of extension jars and the install instructions could be as much of a nightmare as there would be shared dependencies between the extension jar files.

Re: Idea for new Servlet spec

Good idea. If only you'd get one for how to explicitly define which classes the servlet container is allowed to export into the WAR classloader...

Re: Idea for new Servlet spec


Sorry - I didn't mean to stuff up your comments ! 

The first preview showed without html encoding.. not much of a preview ! Here it is again in plain text :

Bugger it.. i'm not having much luck.

4rd time lucky ?


Actually, another way to achieve this terseness could be to 

*depreciate the /web-app/servlet element
*allow the web-app/servlet-mapping/servlet-name element to contain a class name
*support multiple url-pattern elements under /web-app/servlet-mapping
*and for simplicity sake rename servlet-mapping to servlet, and add an id attribute


<servlet>
  <servlet-name>dwr-invoker</servlet-name>
  <display-name>DWR Servlet</display-name>
  <servlet-class>uk.ltd.getahead.dwr.DWRServlet</servlet-class>
  <init-param>
     <param-name>debug</param-name>
     <param-value>true</param-value>
  </init-param>
</servlet>

<servlet-mapping>
  <servlet-name>dwr-invoker</servlet-name>
  <url-pattern>/dwr/*</url-pattern>
</servlet-mapping>

would become :

<servlet id='dwr-invoker' class='uk.ltd.getahead.dwr.DWRServlet'>
  <init-param>
     <param-name>debug</param-name>
     <param-value>true</param-value>
  </init-param>
  <url-pattern>/dwr/*</url-pattern>
</servlet>
  

Re: Idea for new Servlet spec

Your version is a lot terser than the full version. My alternative of the above would be:
<include src="WEB-INF/lib/dwr.jar!ajax.xml">
  <param name="url" value="/dwr/*"/>
  <param name="debug" value="true"/>
</include>