ibm.com/developerWorks
Presented by developerWorks, your source for great tutorials
Section 2. Step by step Servlet example
Servlet XDoclet example
To get this tutorial started, let s kick it off with a simple Servlet and XDoclet
combination. Remember that XDoclet extends the idea of the JavaDoc engine to allow
the generation of code and other files based on custom JavaDoc tags. XDoclet ships
with an Ant task that enables you to create
web.xml
files, ejb jar.xml files, and much
more. In this section, you will use XDoclet to generate a Web application deployment
descriptor with the
webdoclet
Ant task. This will be the simplest endeavor in this
tutorial. Note that XDoclet Ant tasks do not ship with the standard distribution of Ant.
If you have worked with J2EE technology before, you know what the
web.xml
file is
used to configure Web applications. The
web.xml
file is the deployment descriptor for
the Web application. XDoclet allows you to generate the
web.xml
deployment
descriptor using JavaDoc like tags within Servlet s source code.
The following Servlet specifies XDoclet tags that will be used to generate a
web.xml
file. Let s do a quick preview and then I will break down how these tags map to
elements that are generated in the Web application deployment descriptor (
web.xml
).
/*
* BasicServlet.java
*
*/
package rickhightower.servlet;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.sql.*;
import java.sql.*;
import javax.naming.*;
/**
*
* @author
Rick Hightower
*
* @version 1.0
* @web.servlet name="BasicServlet"
display name="Basic Servlet"
load on startup="1"
* @web.servlet init param name="hi" value="Ant is cool!"
* @web.servlet init param name="bye" value="XDoc Rocks!"
* @web.resource ref description="JDBC resource"
*
name="jdbc/mydb"
*
type="javax.sql.DataSource"
*
auth="Container"
* @web.servlet mapping url pattern="/Basic/*"
* @web.servlet mapping url pattern="*.Basic"
Page 6 of 49
Enhance J2EE component reuse with XDoclets






footer




 

 

 

 

 Home | About Us | Network | Services | Support | FAQ | Control Panel | Order Online | Sitemap | Contact

j2ee web hosting

 

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