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: servlet
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
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>