Presented by developerWorks, your source for great tutorials
ibm.com/developerWorks
...
*/
public class BasicServlet extends HttpServlet {
These parameters will generate the following
>init param>
s in the deployment
descriptor:
BasicServlet
...
hi
Ant is cool!
bye
XDoc Rocks!
...
Hopefully you are looking at this example and screaming WAIT! Why Wait? I just hard
code init parameters into the source code. Does this give you shivers? No? It should
make you wonder. I was giving a talk at a conference about XDoclet and someone
stopped me at this point and read me the riot act about how the
s were
now hard coded. Not so fast ... Read on.
Step three: combine Ant and XDoclet to configure
components
Hard coding initialization parameters into source code is something that you typically
do not
want to do. The whole idea around having
s is so the Web
component can be customized by the application assembler into a J2EE application.
A better way is to set the init parameters to point to a token as in @bye@ and @hi@,
and then later use the Ant copying with filtering enabled to pass the right token value
for the right application. This assumes you are using Ant to build your project.
You can use Ant filtering to replace tokens in a configuration file with their proper
values for the deployment environment. Filters are another way to support configuring
J2EE components for more than one application. Here is an example Ant script: that
configures the
web.xml
based on a condition:
Enhance J2EE component reuse with XDoclets
Page 11 of 49
footer
Our partners:
PHP: Hypertext Preprocessor Best Web Hosting
Java Web Hosting
Jsp Web Hosting
Cheapest Web Hosting
Visionwebhosting.net Business web hosting division of Web
Design Plus. All rights reserved