tags:

views:

168

answers:

3

I want to write a JAR file that makes use of the javax servlet API. If I write against version 2.2, does that mean it will work on versions 2.3, 2.4 and 2.5?

Thanks

+3  A: 

Yes, they are backwards compatible.

McWafflestix
Great thank you very much!
Peter Sankauskas
Not nessecarily - some things have been deprecated. Also, some things have their uses clarified in further versions of the servlet spec - for example, SingleThreadModel should be avoided at all costs - if you're ultimately executing your servlets on a 2.3+ compatibile container, you should avoid SingleThreadModel (it is a bad practice, anyways).
MetroidFan2002
A: 

In most cases, there shouldn't be any compatibility issues. There may be a couple of gotchas, depending on what you are doing. If you are writing some framework that decorates container classes, the interfaces have occasionally been modified. For example, the method ServletRequest.getRemotePort() was not present in the J2EE 1.3 version (before Servlet 2.4). These difficulties can be overcome, but be aware that you're going to have to factor them into your development and testing.

McDowell
Thank you.I noticed one thing - in 2.2 you need to use: HttpUtils.getRequestURL(request).toString();Where as in 2.3+ you can do: request.getRequestURL().toString();
Peter Sankauskas
A: 

It will work, though sometimes some methods will be deprecated and might throw up warnings regarding their implementation.

gnlogic