Quick Pickle XDoclet 1 - Servlet Simple Instance

xiaoxiao2021-03-06  14

XDoclet is an extended Javadoc Doclet engine. It is a common Java tool that allows you to create your own javadoc @tags and use the Templet Engening in the XDoclet to generate source code or other files (eg XML Deployment Descriptors) based on the TEMPLET ENGING in the xdoclet.

I don't want to say more about the architecture and working principle of XDoclet, you can google. I just want to quickly pick up the xdoclet through a simple instance. Because I found that when I learned a new knowledge point, there are a lot of concepts, but the example is very small, it is difficult to quickly digest conceptual things through instances. Instead of saying a lot of books, it is better to give me an example, so that I try to figure it out.

Before watching this article, it is best to be familiar with Ant.

First, download, installation, and configuration

1. Software required

● Ant 1.6.2

http://ant.apache.org

download

http://mirror.apache.or.kr/ant/binaries/apache-ant-1.6.2-bin.zip

● xDoclet 1.2.2

http://xdoclet.sourceforge.net/xdoclet/

download

http://prdownloads.sourceforge.net/xdoclet/xdoclet-bin-1.2.2.zip?download

● Tomcat 5.0.28

Http://jakarta.apache.org/tomcat/

download

http://apache.justdn.org/jakarta/tomcat-5/v5.0.28/bin/jakarta-tomcat-5.0.28.zip

2. Installation

F: / j2sdk jdk directory

F: / java / ant Ant catalog

F: / java / xdoclet xdoclet directory

F: / java / jakarta-tomcat tomcat directory

Here, it is important to set up Ant_home in the environment variable, and point to the ANT installation directory, but also add "% Ant_home% / bin in the PATH variable;" can be referenced

Java environment variable settings.

Second, a simple example

Writing code

Create a D: / XDocletsample directory, establish 3 files in accordance with the following structure.

D: / xdocletsample/src/javamxj/helloservlet.java

/ *

* @author javamxj (9cbs blog) creation date 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-maping url-pattern = "/ hello / *"

* /

Public class helloservlet extends httpservlet {public void init (servletconfig config) throws servletexception {

// Get initialization parameters from 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 {

// Set the document type first

Response.setContentType ("text / html; charset = GBK");

// Get output flow

Java.io.printwriter out = response.getwriter ();

Out.println (" Welcome JavaMxj Blog! </ Title> </ head>");</p> <p>Out.println ("<Body> <H1>");</p> <p>Out.println ("Hello:" H);</p> <p>Out.println ("</ h1> </ body> </ html>");</p> <p>Out.close ();</p> <p>} catch (exception e) {</p> <p>Throw new servletexception (e);</p> <p>}</p> <p>}</p> <p>}</p> <p>D: / xdocletsample/build.xml</p> <p><? XML Version = "1.0" encoding = "GBK"?></p> <p><Project name = "filtering" default = "deploy" basedir = "."></p> <p><Description> A simple xdoclet instance </ description></p> <p><! - Load Properties Files -></p> <p><property file = "build.properties" /></p> <p><! - Define Class Path -></p> <p><path id = "Web.classpath"></p> <p><PATHELEMENT LOCATION = "$ {Tomcat.home} /common/lib/servlet-api.jar" /></p> <p><PATHELEMENT LOCATION = "$ {Tomcat.home} /common/lib/jsp-api.jar" /></p> <p></ path></p> <p><path id = "xdoclet.classpath"></p> <p><fileset dir = $ {xdoclet.home} / lib></p> <p><include Name = "*. jar" /></p> <p></ fileset></p> <p><path refid = "Web.classpath" /></p> <p></ path></p> <p><! - Initialization, establish a directory -></p> <p><target name = "init"> <mkdir dir = "$ {dist.dir}" /></p> <p><mkdir dir = "$ {dist.dir} / web-inf" /></p> <p><mkdir dir = "$ {dist.dir} / web-inf / class" /></p> <p></ target></p> <p><! - xdoclet WebDoclet Task -></p> <p><target name = "WebDoclet" depends = "init"></p> <p><taskdef</p> <p>Name = "WebDoclet"</p> <p>ClasspathRef = "xdoclet.classpath"</p> <p>ClassName = "xdoclet.modules.web.webdoclettask" /></p> <p><WebDoclet destdir = "$ {dist.dir} / web-inf" force = "$ {xdoclet.force}"></p> <p><deploymentdescriptor servletspec = "2.4" xmlencoding = "gbk" /></p> <p><fileset dir = "$ {src.dir}" incrudes = "** / * servlet.java" /></p> <p></ WebDoclet></p> <p></ target></p> <p><! - Compilation and Deployment -></p> <p><target name = "deploy" depends = "WebDoclet"></p> <p><javac srcdir = "$ {src.dir}" destdir = "$ {dist.dir} / web-inf / class"></p> <p><classpath refid = "Web.classpath" /></p> <p></ javac></p> <p><jar destfile = "$ {tomcat.home} / webapps / $ {app.name} .war" basedir = $ {dist.dir} "/></p> <p></ target></p> <p></ provject></p> <p>D: / xdocletsample/build.properties ########################################################################################################################################################################################################################################################################################</p> <p>#</p> <p># File Name: Build.properties</p> <p># Author: 9CBS javamxj</p> <p>#</p> <p># Web server directory</p> <p>Tomcat.home = f: / java / jakarta-tomcat</p> <p># xdoclet directory</p> <p>xdoclet.home = f: / java / xdoclet</p> <p># w 的 临 临 directory</p> <p>Dist.dir =. / dist</p> <p># 源 文件 文件 directory</p> <p>Src.dir =. / src</p> <p># 发布 程序 名</p> <p>app.name = HelloWeb</p> <p># Servlet parameter, you can change</p> <p>Hello.Servlet = Javamxj Blog</p> <p>You can change the directory directory of Tomcat, XDoclets in the build.properties property file according to your own settings.</p> <p>2. Run the program</p> <p>● Open an MS-DOS window to switch to the D: / XDocletsample directory, enter the ANT command:</p> <p>● The Tomcat server is then started, open the browser window, type the address: http: // localhost: 8080 / helloweb / hello /</p> <p>Open the build.properties file, will "</p> <p>Hello.servlet = javamxj blog "Statement is modified"</p> <p>Hello.servlet = 9cbs, then save.</p> <p>● In MS-DOS, enter "Ant -DxDoclet.Force = true"</p> <p>● Refresh the browser window, the following:</p> <p>Ok, this is just a simple xdoclet instance.</p> <p>Third, how is Web.xml generated</p> <p>Note that there is no, here doesn't write a web.xml file, but you can find a web.xml file from the D: / XDocletsample / DIST / Web-Inf directory. The content is as follows (for easy browsing, I have deleted the comment):</p> <p>D: / xdocletsample/dist/web-inf/web.xml</p> <p>Maybe you will think that this is nothing, it is not very simple, but when using XDoclet to develop EJB, you will make more experience in its superiority. The next article talks about how to develop EJB.</p> <p>Fourth, reference information:</p> <p>article:</p> <p>Use xDoclet to improve the reuse of J2EE components</p> <p>(This is a tutorial on the IBM website. This article is written by it for blueprint. Need registration to log in.)</p> <p>http://www2.tw.ibm.com/developerWorks/Tutorial/content/java/t20031110_Xdoclets.htm</p> <p>(Ibida, this is the article on China's Taiwan website, traditional, no registration)</p> <p>XDoclet learning notes</p> <p>(This is a series, there are 4 articles, and the principle of xdoclet is relatively thorough.)</p> <p>books:</p> <p>MANNING - XDoclet in Action</p> <p>Others: XDoclet itself comes with documents and instances.</p> <p>(It is recommended to look at it, anyway, I often use it)</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-48220.html</div><div class="plugin d-flex justify-content-center mt-3"></div><hr><div class="row"><div class="col-lg-12 text-muted mt-2"><i class="icon-tags mr-2"></i><span class="badge border border-secondary mr-2"><h2 class="h6 mb-0 small"><a class="text-secondary" href="tag-2.html">9cbs</a></h2></span></div></div></div></div><div class="card card-postlist border-white shadow"><div class="card-body"><div class="card-title"><div class="d-flex justify-content-between"><div><b>New Post</b>(<span class="posts">0</span>) </div><div></div></div></div><ul class="postlist list-unstyled"> </ul></div></div><div class="d-none threadlist"><input type="checkbox" name="modtid" value="48220" checked /></div></div></div></div></div><footer class="text-muted small bg-dark py-4 mt-3" id="footer"><div class="container"><div class="row"><div class="col">CopyRight © 2020 All Rights Reserved </div><div class="col text-right">Processed: <b>0.032</b>, SQL: <b>9</b></div></div></div></footer><script src="./lang/en-us/lang.js?2.2.0"></script><script src="view/js/jquery.min.js?2.2.0"></script><script src="view/js/popper.min.js?2.2.0"></script><script src="view/js/bootstrap.min.js?2.2.0"></script><script src="view/js/xiuno.js?2.2.0"></script><script src="view/js/bootstrap-plugin.js?2.2.0"></script><script src="view/js/async.min.js?2.2.0"></script><script src="view/js/form.js?2.2.0"></script><script> var debug = DEBUG = 0; var url_rewrite_on = 1; var url_path = './'; var forumarr = {"1":"Tech"}; var fid = 1; var uid = 0; var gid = 0; xn.options.water_image_url = 'view/img/water-small.png'; </script><script src="view/js/wellcms.js?2.2.0"></script><a class="scroll-to-top rounded" href="javascript:void(0);"><i class="icon-angle-up"></i></a><a class="scroll-to-bottom rounded" href="javascript:void(0);" style="display: inline;"><i class="icon-angle-down"></i></a></body></html><script> var forum_url = 'list-1.html'; var safe_token = 'vQhKI_2BP5KVXkRTCt0n4BpTExlWoQeRTJ271G2WMvK_2F0CToQDPVjpa4_2B5ZQoo6dKCgExeYQP4_2FBTyIkAvLsyvhQ_3D_3D'; var body = $('body'); body.on('submit', '#form', function() { var jthis = $(this); var jsubmit = jthis.find('#submit'); jthis.reset(); jsubmit.button('loading'); var postdata = jthis.serializeObject(); $.xpost(jthis.attr('action'), postdata, function(code, message) { if(code == 0) { location.reload(); } else { $.alert(message); jsubmit.button('reset'); } }); return false; }); function resize_image() { var jmessagelist = $('div.message'); var first_width = jmessagelist.width(); jmessagelist.each(function() { var jdiv = $(this); var maxwidth = jdiv.attr('isfirst') ? first_width : jdiv.width(); var jmessage_width = Math.min(jdiv.width(), maxwidth); jdiv.find('img, embed, iframe, video').each(function() { var jimg = $(this); var img_width = this.org_width; var img_height = this.org_height; if(!img_width) { var img_width = jimg.attr('width'); var img_height = jimg.attr('height'); this.org_width = img_width; this.org_height = img_height; } if(img_width > jmessage_width) { if(this.tagName == 'IMG') { jimg.width(jmessage_width); jimg.css('height', 'auto'); jimg.css('cursor', 'pointer'); jimg.on('click', function() { }); } else { jimg.width(jmessage_width); var height = (img_height / img_width) * jimg.width(); jimg.height(height); } } }); }); } function resize_table() { $('div.message').each(function() { var jdiv = $(this); jdiv.find('table').addClass('table').wrap('<div class="table-responsive"></div>'); }); } $(function() { resize_image(); resize_table(); $(window).on('resize', resize_image); }); var jmessage = $('#message'); jmessage.on('focus', function() {if(jmessage.t) { clearTimeout(jmessage.t); jmessage.t = null; } jmessage.css('height', '6rem'); }); jmessage.on('blur', function() {jmessage.t = setTimeout(function() { jmessage.css('height', '2.5rem');}, 1000); }); $('#nav li[data-active="fid-1"]').addClass('active'); </script>