D:/XDocletSample/src/javamxj/HelloServlet.java
/* * @author javamxj (CSDN Blog) 创建日期 2005-1-7 */ package javamxj; import javax.servlet.*; import javax.servlet.http.*; /** * @web.servlet name="HelloServlet" * display-name="Hello Servlet" * load-on-startup="1" * @web.servlet-init-param name="hello" * value="${hello.servlet}" * @web.servlet-mapping url-pattern="/Hello/*" */ public class HelloServlet extends HttpServlet {
public void init(ServletConfig config) throws ServletException {
//从web.xml中获得初始化参数 super.init(config);
}
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException,
java.io.IOException {
ServletConfig config = this.getServletConfig();
String h = config.getInitParameter("hello");
try {
//首先设置文档类型 response.setContentType("text/html; charset=GBK");
//获取输出流 java.io.PrintWriter out = response.getWriter();
out.println("Welcome javamxj Blog! ");
out.println(""
);
out.println(" Hello: " + h);
out.println("");
out.close();
} catch (Exception e) {
throw new ServletException(e);
}
}
}
D:/XDocletSample/build.xml
xml version="1.0" encoding="GBK"?> <project name="filtering" default="deploy" basedir="."> <description>一个简单的XDoclet实例description> <property file="build.properties"/> <path id="web.classpath"> <pathelement location="${ tomcat.home}/common/lib/servlet-api.jar"/> <pathelement location="${ tomcat.home}/common/lib/jsp-api.jar"/> path> <path id="xdoclet.classpath"> <fileset dir="${ xdoclet.home}/lib"> <include name="*.jar"/> fileset> <path refid="web.classpath"/> path> <target name="init"> <mkdir dir="${ dist.dir}"/> <mkdir dir="${ dist.dir}/WEB-INF"/> <mkdir dir="${ dist.dir}/WEB-INF/classes"/> target> <target name="webdoclet" depends="init"> <taskdef
name="webdoclet"
classpathref="xdoclet.classpath"
classname="xdoclet.modules.web.WebDocletTask"/> <webdoclet destDir="${dist.dir}/WEB-INF" force="${xdoclet.force}"> <deploymentdescriptor Servletspec="2.4" xmlencoding="GBK"/> <fileset dir="${src.dir}" includes="**/*Servlet.java"/>
webdoclet>
target> <target name="deploy" depends="webdoclet"> <javac srcdir="${ src.dir}" destdir="${ dist.dir}/WEB-INF/classes"> <classpath refid="web.classpath"/> javac> <jar destfile="${ tomcat.home}/webapps/${ app.name}.war" basedir="${ dist.dir}"/> target>
project>
D:/XDocletSample/build.properties |
################ 环境设置 ################### # # 文件名:build.properties # 作者: CSDN javamxj # # web服务器目录 tomcat.home=F:/java/jakarta-tomcat |