﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-云下的天空-随笔分类-JAVA EE</title><link>http://www.blogjava.net/liuwuping12064915/category/48779.html</link><description>       坚持          随心而动        走自己的路</description><language>zh-cn</language><lastBuildDate>Fri, 03 Jun 2011 01:57:46 GMT</lastBuildDate><pubDate>Fri, 03 Jun 2011 01:57:46 GMT</pubDate><ttl>60</ttl><item><title>tomcat7的配置</title><link>http://www.blogjava.net/liuwuping12064915/archive/2011/06/02/351617.html</link><dc:creator>天空布蓝</dc:creator><author>天空布蓝</author><pubDate>Thu, 02 Jun 2011 09:54:00 GMT</pubDate><guid>http://www.blogjava.net/liuwuping12064915/archive/2011/06/02/351617.html</guid><wfw:comment>http://www.blogjava.net/liuwuping12064915/comments/351617.html</wfw:comment><comments>http://www.blogjava.net/liuwuping12064915/archive/2011/06/02/351617.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/liuwuping12064915/comments/commentRss/351617.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/liuwuping12064915/services/trackbacks/351617.html</trackback:ping><description><![CDATA[<span class="Apple-style-span" style="color: #323e32; font-family: simsun; "><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; list-style-type: none; list-style-position: initial; list-style-image: initial; word-wrap: normal; word-break: normal; line-height: 21px; ">&nbsp; <br /><br />原文转载自：</p></span><span class="Apple-style-span" style="color: #323e32; font-family: simsun; "><a href="http://blog.sina.com.cn/s/blog_70b7bbf20100mhiv.html">http://blog.sina.com.cn/s/blog_70b7bbf20100mhiv.html</a></span><span class="Apple-style-span" style="color: #323e32; font-family: simsun; "><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; list-style-type: none; list-style-position: initial; list-style-image: initial; word-wrap: normal; word-break: normal; line-height: 21px; ">&nbsp; &nbsp;Tomcat7已经发布多时，Tomcat7增加了对Servlet 3.0,JSP 2.2和JSP-EL 2。2的支持、支持web application内存泄露的检测和防护等很多新功能。本片教程主要介绍如何配置Tomcat7。</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; list-style-type: none; list-style-position: initial; list-style-image: initial; word-wrap: normal; word-break: normal; line-height: 21px; ">&nbsp;<wbr></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; list-style-type: none; list-style-position: initial; list-style-image: initial; word-wrap: normal; word-break: normal; line-height: 21px; ">一、软件下载<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;首先需要下载Java Jdk以及Tomcat7。JDK下载地址：最新为JDK6 update22, Tomcat7下载地址：最新为Tomcat7.02 Beta。</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; list-style-type: none; list-style-position: initial; list-style-image: initial; word-wrap: normal; word-break: normal; line-height: 21px; ">&nbsp;<wbr></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; list-style-type: none; list-style-position: initial; list-style-image: initial; word-wrap: normal; word-break: normal; line-height: 21px; ">二、软件安装和配置<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;1.首先安装JDK，直接点击安装即可,比如默认安装的路径为：C:\Program Files\Java\jdk1.6.0_22。安装之后需要设定环境变量。在我的电脑-&gt;属性-&gt;高级-&gt;环境变量-&gt;系统变量中添加以下环境变量：(假设你的jdk安装目录如上设置)</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; list-style-type: none; list-style-position: initial; list-style-image: initial; word-wrap: normal; word-break: normal; line-height: 21px; ">&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;新建变量名：&nbsp;<font color="#ED1C24" style="word-wrap: normal; word-break: normal; line-height: 21px; ">JAVA_HOME</font>,值(value)为：<font color="#ED1C24" style="word-wrap: normal; word-break: normal; line-height: 21px; ">C:\Program Files\Java\jdk1.6.0_22<br /></font>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;新建变量名：<font color="#ED1C24" style="word-wrap: normal; word-break: normal; line-height: 21px; ">classpath</font>&nbsp;,值(value)为：&nbsp;<font color="#ED1C24" style="word-wrap: normal; word-break: normal; line-height: 21px; ">.;%JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\lib\tools.jar;</font>&nbsp;<wbr>&nbsp;(.;一定不能少，因为它代表当前路径)<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;查找变量名：path ,增加值(value)为<font color="#ED1C24" style="word-wrap: normal; word-break: normal; line-height: 21px; ">：%JAVA_HOME%\bin;</font></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; list-style-type: none; list-style-position: initial; list-style-image: initial; word-wrap: normal; word-break: normal; line-height: 21px; "><br />添加完毕，确定即可。接下来简单测试环境变量是否配置正确：</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; list-style-type: none; list-style-position: initial; list-style-image: initial; word-wrap: normal; word-break: normal; line-height: 21px; "><font color="#ED1C24" style="word-wrap: normal; word-break: normal; line-height: 21px; ">public class Test{<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;public static void main(String args[]){<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;System.out.println("Hello Leyond");<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;}<br />}<br /></font>&nbsp;<wbr><br />将以上代码拷贝保存成Test.java文件。然后命令行窗口(xp:在运行输入cmd,vista和win7直接在搜索框中输入cmd)，CD到文件所在的目录，然后键入下列命令：<br />javac Test.java<br />java Test</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; list-style-type: none; list-style-position: initial; list-style-image: initial; word-wrap: normal; word-break: normal; line-height: 21px; ">注意第二个命令没有.java后缀。如果看到&#8220;Hello Leyond&#8221;，则表明jdk环境变量配置成功，没有的话，检查自己的配置情况。</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; list-style-type: none; list-style-position: initial; list-style-image: initial; word-wrap: normal; word-break: normal; line-height: 21px; ">&nbsp;<wbr></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; list-style-type: none; list-style-position: initial; list-style-image: initial; word-wrap: normal; word-break: normal; line-height: 21px; ">2. Tomcat7安装和配置</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; list-style-type: none; list-style-position: initial; list-style-image: initial; word-wrap: normal; word-break: normal; line-height: 21px; ">&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;下载zip文件之后直接解压到某个目录下，比如：C:\itdevelop\Tomcat7。然后在我的电脑-&gt;属性-&gt;高级-&gt;环境变量-&gt;系统变量中添加以下环境变量：</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; list-style-type: none; list-style-position: initial; list-style-image: initial; word-wrap: normal; word-break: normal; line-height: 21px; ">&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;新建变量名:&nbsp;<font color="#ED1C24" style="word-wrap: normal; word-break: normal; line-height: 21px; ">TOMCAT_HOME</font>, 值(value)为：<font color="#ED1C24" style="word-wrap: normal; word-break: normal; line-height: 21px; ">C:\itdevelop\Tomcat7</font><br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;查找变量名:&nbsp;<font color="#ED1C24" style="word-wrap: normal; word-break: normal; line-height: 21px; ">classpath</font>, 增加值为<font color="#ED1C24" style="word-wrap: normal; word-break: normal; line-height: 21px; "><font color="#000000" style="word-wrap: normal; word-break: normal; line-height: 21px; ">：</font>%TOMCAT_HOME%\common\lib<br /></font>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;增加后的classpath的值为<font color="#ED1C24" style="word-wrap: normal; word-break: normal; line-height: 21px; "><font color="#000000" style="word-wrap: normal; word-break: normal; line-height: 21px; ">：</font>.;%JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\lib\tools.jar;%TOMCAT_HOME%\lib</font>。<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;最后进入Tomcat7安装目录下的Bin目录，启动Tomcat,在浏览器中输入：<a href="http://localhost:8080/" style="text-decoration: none; color: #006b77; ">http://localhost:8080/</a>，若可以看到Tomcat7的欢迎界面，表示Tomcat7配置成功了。</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; list-style-type: none; list-style-position: initial; list-style-image: initial; word-wrap: normal; word-break: normal; line-height: 21px; ">&nbsp;<wbr></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; list-style-type: none; list-style-position: initial; list-style-image: initial; word-wrap: normal; word-break: normal; line-height: 21px; ">三、新建webApp<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;这里介绍如何搭建一个JSP简单的应用。首先到Tomcat7目录下webapps目录，例如：C:\itdevelop\Tomcat7\webapps，该目录存放了ROOT，docs,examples等目录，ROOT存放的是欢迎界面的代码，docs主要是文档，examples中可以查看各种例子。接下来看看如何新建一个属于自己的jsp应用程序。</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; list-style-type: none; list-style-position: initial; list-style-image: initial; word-wrap: normal; word-break: normal; line-height: 21px; ">&nbsp;<wbr></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; list-style-type: none; list-style-position: initial; list-style-image: initial; word-wrap: normal; word-break: normal; line-height: 21px; ">操作如下：<br />&nbsp;<wbr>&nbsp;1.在webapps下新建myapp目录。<br />&nbsp;<wbr>&nbsp;2.myapp下新建一个目录WEB-INF，注意，目录名称是区分大小写的。<br />&nbsp;<wbr>&nbsp;3.WEB-INF下新建一个文件web.xml，内容如下:</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; list-style-type: none; list-style-position: initial; list-style-image: initial; word-wrap: normal; word-break: normal; line-height: 21px; "><font color="#ED1C24" style="word-wrap: normal; word-break: normal; line-height: 21px; ">&lt;?xml version="1.0" encoding="ISO-8859-1"?&gt;<br />&lt;web-app version="3.0"<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;xmlns="</font><a href="http://java.sun.com/xml/ns/javaee" style="text-decoration: none; color: #006b77; "><font color="#ED1C24" style="word-wrap: normal; word-break: normal; line-height: 21px; ">http://java.sun.com/xml/ns/javaee</font></a><font color="#ED1C24" style="word-wrap: normal; word-break: normal; line-height: 21px; ">"<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;xmlns:xsi="</font><a href="http://www.w3.org/2001/XMLSchema-instance" style="text-decoration: none; color: #006b77; "><font color="#ED1C24" style="word-wrap: normal; word-break: normal; line-height: 21px; ">http://www.w3.org/2001/XMLSchema-instance</font></a><font color="#ED1C24" style="word-wrap: normal; word-break: normal; line-height: 21px; ">"<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;xsi:schemaLocation="</font><a href="http://java.sun.com/xml/ns/javaee" style="text-decoration: none; color: #006b77; "><font color="#ED1C24" style="word-wrap: normal; word-break: normal; line-height: 21px; ">http://java.sun.com/xml/ns/javaee</font></a><a href="http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" style="text-decoration: none; color: #006b77; "><font color="#ED1C24" style="word-wrap: normal; word-break: normal; line-height: 21px; ">http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd</font></a><font color="#ED1C24" style="word-wrap: normal; word-break: normal; line-height: 21px; ">"&gt;<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;&lt;display-name&gt;My Web Application&lt;/display-name&gt;<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;&lt;description&gt;<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;A application for test.<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;&lt;/description&gt;<br />&lt;/web-app&gt;</font></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; list-style-type: none; list-style-position: initial; list-style-image: initial; word-wrap: normal; word-break: normal; line-height: 21px; ">&nbsp;<wbr></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; list-style-type: none; list-style-position: initial; list-style-image: initial; word-wrap: normal; word-break: normal; line-height: 21px; ">4. 在myapp下新建一个测试的jsp页面，文件名为index.jsp，文件内容如下:<br /><font color="#ED1C24" style="word-wrap: normal; word-break: normal; line-height: 21px; ">&lt;html&gt;<br />&nbsp;<wbr>&nbsp;&lt;body&gt;<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;&lt;center&gt; Now time is: &lt;%=new java.util.Date()%&gt;&lt;/center&gt;<br />&nbsp;<wbr>&nbsp;&lt;/body&gt;<br />&lt;/html&gt;</font></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; list-style-type: none; list-style-position: initial; list-style-image: initial; word-wrap: normal; word-break: normal; line-height: 21px; ">5. 启动Tomcat,在浏览器输入<a href="http://localhost:8080/myapp/index.jsp" style="text-decoration: none; color: #006b77; ">http://localhost:8080/myapp/index.jsp</a>看到当前时间的话说明就成功了。</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; list-style-type: none; list-style-position: initial; list-style-image: initial; word-wrap: normal; word-break: normal; line-height: 21px; ">&nbsp;<wbr></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; list-style-type: none; list-style-position: initial; list-style-image: initial; word-wrap: normal; word-break: normal; line-height: 21px; ">四、新建Servlet<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;在之前myapp目下的/WEB-INF/classes/test目录下新建HelloWorld.java(若没有class,test目录，请新建)。HelloWorld内容如下：</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; list-style-type: none; list-style-position: initial; list-style-image: initial; word-wrap: normal; word-break: normal; line-height: 21px; "><font color="#ED1C24" style="word-wrap: normal; word-break: normal; line-height: 21px; ">package test;<br />import java.io.*;<br />import javax.servlet.*;<br />import javax.servlet.http.*;</font></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; list-style-type: none; list-style-position: initial; list-style-image: initial; word-wrap: normal; word-break: normal; line-height: 21px; "><font color="#ED1C24" style="word-wrap: normal; word-break: normal; line-height: 21px; ">public class HelloWorld extends HttpServlet{<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;public void doGet(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException{<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;response.setContentType("text/html");<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;PrintWriter out = response.getWriter();<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;out.println("&lt;html&gt;&lt;head&gt;&lt;title&gt;");<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;out.println("This is my first Servlet");<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;out.println("&lt;/title&gt;&lt;/head&gt;&lt;body&gt;");<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;out.println("&lt;h1&gt;Hello,World!&lt;/h1&gt;");<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;out.println("&lt;/body&gt;&lt;/html&gt;");<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;}<br />}</font></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; list-style-type: none; list-style-position: initial; list-style-image: initial; word-wrap: normal; word-break: normal; line-height: 21px; ">&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;之后用javac HelloWorld.java来编译该文件。倘若出现&#8221;package javax.servlet does not exist&#8220;，请把C:\itdevelop\Tomcat7\lib目录下的servlet-api.jar拷贝到C:\Program Files\Java\jre6\lib\ext，重启电脑，再次编译即可。</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; list-style-type: none; list-style-position: initial; list-style-image: initial; word-wrap: normal; word-break: normal; line-height: 21px; ">目前C:\itdevelop\Tomcat7\webapps\myapp的目录结构如下：</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; list-style-type: none; list-style-position: initial; list-style-image: initial; word-wrap: normal; word-break: normal; line-height: 21px; ">./index.jsp<br />./WEB-INF/web.xml<br />./WEB-INF/classes/test/HelloWorld.class (编译HelloWorld.java生成的)</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; list-style-type: none; list-style-position: initial; list-style-image: initial; word-wrap: normal; word-break: normal; line-height: 21px; ">然后在浏览器中输入<a href="http://localhost:8080/myapp/HelloWorld" style="text-decoration: none; color: #006b77; ">http://localhost:8080/myapp/HelloWorld</a>,于是Server众望所归的报错了:Error 404&#8211;Not Found 怎么回事呢？我们还需要配置Servlet的之行环境。打开WEB-INF目录下的web.xml，在&lt;web-app&gt;&lt;/web-app&gt;添加下面这段程序：</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; list-style-type: none; list-style-position: initial; list-style-image: initial; word-wrap: normal; word-break: normal; line-height: 21px; ">&nbsp;<wbr></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; list-style-type: none; list-style-position: initial; list-style-image: initial; word-wrap: normal; word-break: normal; line-height: 21px; "><font color="#ED1C24" style="word-wrap: normal; word-break: normal; line-height: 21px; ">&lt;servlet&gt;<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;&lt;servlet-name&gt;HelloWorld&lt;/servlet-name&gt;<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;&lt;servlet-class&gt;test.HelloWorld&lt;/servlet-class&gt;<br />&nbsp;<wbr>&lt;/servlet&gt;</font></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; list-style-type: none; list-style-position: initial; list-style-image: initial; word-wrap: normal; word-break: normal; line-height: 21px; "><font color="#ED1C24" style="word-wrap: normal; word-break: normal; line-height: 21px; ">&lt;servlet-mapping&gt;<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;&lt;servlet-name&gt;HelloWorld&lt;/servlet-name&gt;<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;&lt;url-pattern&gt;/HelloWorld&lt;/url-pattern&gt;<br />&nbsp;<wbr>&lt;/servlet-mapping&gt;</font></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; list-style-type: none; list-style-position: initial; list-style-image: initial; word-wrap: normal; word-break: normal; line-height: 21px; ">&nbsp;<wbr></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; list-style-type: none; list-style-position: initial; list-style-image: initial; word-wrap: normal; word-break: normal; line-height: 21px; ">&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;这段xml内容，首先指定servlet的名字，类的名字。然后把servlet映射到一种URL模式，使得通过URL来访问这个servlet。修改之后，若需要重启Tomcat,然后浏览<a href="http://localhost:8080/myapp/HelloWorld" style="text-decoration: none; color: #006b77; ">http://localhost:8080/myapp/HelloWorld</a>一个Hello,World!等着你，如果你看到了，表示servlet也成功了。<div style="display: inline-block; "></div></p></span><span class="Apple-style-span" style="color: #323e32; font-family: Verdana, 宋体, sans-serif; font-size: 12px; line-height: 20px; "><h2 id="t_70b7bbf20100mhiv" class="titName SG_txta" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; list-style-type: none; list-style-position: initial; list-style-image: initial; color: #006b77; font-size: 18px; font-family: 微软雅黑, 黑体; font-weight: 300; display: inline; ">Tomcat7配置</h2></span><span class="Apple-style-span" style="color: #323e32; font-family: Verdana, 宋体, sans-serif; font-size: 12px; line-height: 20px; ">&nbsp;</span><img src ="http://www.blogjava.net/liuwuping12064915/aggbug/351617.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/liuwuping12064915/" target="_blank">天空布蓝</a> 2011-06-02 17:54 <a href="http://www.blogjava.net/liuwuping12064915/archive/2011/06/02/351617.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>tomcat简介之web.xml详解</title><link>http://www.blogjava.net/liuwuping12064915/archive/2011/06/02/351614.html</link><dc:creator>天空布蓝</dc:creator><author>天空布蓝</author><pubDate>Thu, 02 Jun 2011 09:40:00 GMT</pubDate><guid>http://www.blogjava.net/liuwuping12064915/archive/2011/06/02/351614.html</guid><wfw:comment>http://www.blogjava.net/liuwuping12064915/comments/351614.html</wfw:comment><comments>http://www.blogjava.net/liuwuping12064915/archive/2011/06/02/351614.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/liuwuping12064915/comments/commentRss/351614.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/liuwuping12064915/services/trackbacks/351614.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 原文转载自：http://blog.csdn.net/facepp/archive/2008/04/19/2306602.aspx一、Tomcat背景　　自从JSP发布之后，推出了各式各样的JSP引擎。Apache Group在完成GNUJSP1.0的开发以后，开始考虑在SUN的JSWDK基础上开发一个可以直接提供Web服务的JSP服务器，当然同时也支持Servlet, 这样Tomcat就诞生了。...&nbsp;&nbsp;<a href='http://www.blogjava.net/liuwuping12064915/archive/2011/06/02/351614.html'>阅读全文</a><img src ="http://www.blogjava.net/liuwuping12064915/aggbug/351614.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/liuwuping12064915/" target="_blank">天空布蓝</a> 2011-06-02 17:40 <a href="http://www.blogjava.net/liuwuping12064915/archive/2011/06/02/351614.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Tomcat中web.xml文件的详细说明</title><link>http://www.blogjava.net/liuwuping12064915/archive/2011/06/02/351611.html</link><dc:creator>天空布蓝</dc:creator><author>天空布蓝</author><pubDate>Thu, 02 Jun 2011 09:19:00 GMT</pubDate><guid>http://www.blogjava.net/liuwuping12064915/archive/2011/06/02/351611.html</guid><wfw:comment>http://www.blogjava.net/liuwuping12064915/comments/351611.html</wfw:comment><comments>http://www.blogjava.net/liuwuping12064915/archive/2011/06/02/351611.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/liuwuping12064915/comments/commentRss/351611.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/liuwuping12064915/services/trackbacks/351611.html</trackback:ping><description><![CDATA[<span class="Apple-style-span" style="font-family: verdana, sans-serif; "><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "><span style="font-family: verdana, sans-serif; font-size: 14px; line-height: 21px; "><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; ">原文转自：</p></span></p></span><span class="Apple-style-span" style="font-family: verdana, sans-serif; "><a href="http://blog.csdn.net/pathfinder163/archive/2009/09/02/4506817.aspx">http://blog.csdn.net/pathfinder163/archive/2009/09/02/4506817.aspx</a></span><span class="Apple-style-span" style="font-family: verdana, sans-serif; "><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "><span style="font-family: verdana, sans-serif; font-size: 14px; line-height: 21px; "><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "><br />&lt;?xml version="1.0" encoding="GB2312"?&gt; &lt;!--&nbsp;<br />Web.xml依次定议了如下元素：&nbsp;<br /><span style="font-size: 14pt; ">&lt;web-app&gt;&nbsp;<br /></span><br /><span style="font-size: 14pt; ">&lt;display-name&gt;&lt;/display-name&gt; 定义了WEB应用的名字&nbsp;<br /></span><br /><span style="font-size: 14pt; ">&lt;description&gt;&lt;/description&gt; 声明WEB应用的描述信息&nbsp;<br /></span><br /><span style="font-size: 14pt; ">&lt;filter&gt;&lt;/filter&gt;&nbsp;<br /></span><br /><span style="font-size: 14pt; ">&lt;filter-mapping&gt;&lt;/filter-mapping&gt;<br />&nbsp;</span><br /><span style="font-size: 14pt; ">&lt;servlet&gt;&lt;/servlet&gt;&nbsp;<br /></span><br /><span style="font-size: 14pt; ">&lt;servlet-mapping&gt;&lt;/servlet-mapping&gt;&nbsp;<br /></span><br /><span style="font-size: 14pt; ">&lt;session-config&gt;&lt;/session-config&gt;&nbsp;<br /></span><br /><span style="font-size: 14pt; ">&lt;welcome-file-list&gt;&lt;/welcome-file-list&gt;&nbsp;<br /></span><br /><span style="font-size: 14pt; ">&lt;taglib&gt;&lt;/taglib&gt;&nbsp;<br /></span><br /><span style="font-size: 14pt; ">&lt;resource-ref&gt;&lt;/resource-ref&gt;&nbsp;<br /></span><br /><span style="font-size: 14pt; ">&lt;security-constraint&gt;&lt;/security-constraint&gt;&nbsp;<br /></span><br /><span style="font-size: 14pt; ">&lt;login-config&gt;&lt;/login-config&gt;&nbsp;<br /></span><br /><span style="font-size: 14pt; ">&lt;/web-app&gt;&nbsp;</span><br />在web.xml中元素定义的先后顺序不能颠倒，否则Tomcat服务器可能会抛出SAXParseException.&nbsp;<br />--&gt;&nbsp;<br />&lt;!DOCTYPE web-app PUBLIC "-//Sun Microsystems,Inc.//DTD Web Application 2.3//EN" "<a href="http://java.sun.com/dtd/web-app_2_3.dtd" style="text-decoration: none; color: #336699; ">http://java.sun.com/dtd/web-app_2_3.dtd</a>"&gt;&nbsp;<br />&lt;web-app&gt;</p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; ">&lt;display-name&gt;Sample Application&lt;/display-name&gt;</p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; ">&lt;description&gt;&nbsp;<br />This is a Sample Application&nbsp;<br />&lt;/description&gt;</p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; ">&lt;!--&nbsp;<br />filter 配置Servlet过滤器&nbsp;<br />filter-name 定义过滤器的名字。当有多个过滤器时，不能同名&nbsp;<br />filter-class 指定实现这一过滤的类，这个类负责具体的过滤事务&nbsp;<br />--&gt;&nbsp;<br />&lt;filter&gt;&nbsp;<br />&lt;filter-name&gt;SampleFilter&lt;/filter-name&gt;&nbsp;<br />&lt;filter-class&gt;mypack.SampleFilter&lt;/filter-class&gt;&nbsp;<br />&lt;/filter&gt;</p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; ">&lt;!--&nbsp;<br />filter-mapping 设定过滤器负责过滤的URL&nbsp;<br />filter-name 过滤器名。这里的名字一定要和filter中的过滤器名匹配&nbsp;<br />url-pattern 指定过滤器负责过滤的URL&nbsp;<br />--&gt;&nbsp;<br />&lt;filter-mapping&gt;&nbsp;<br />&lt;filter-name&gt;SampleFilter&lt;/filter-name&gt;&nbsp;<br />&lt;url-pattern&gt;*.jsp&lt;/url-pattern&gt;&nbsp;<br />&lt;/filter-mapping&gt;</p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; ">&lt;!--&nbsp;<br />servlet 配置Servlet.&nbsp;<br />servlet-name 定义Servlet的名字&nbsp;<br />servlet-class 指定实现这个servlet的类&nbsp;<br />init-param 定义Servlet的初始化参数和参数值，可有多个init-param。在servlet类中通过getInitParamenter(String name)方法访问初始化参数&nbsp;<br />load-on-startup 指定当Web应用启动时，装载Servlet的次序。&nbsp;<br />当值为正数或零时：Servlet容器先加载数值小的servlet，再依次加载其他数值大的servlet.&nbsp;<br />当值为负或未定义：Servlet容器将在Web客户首次访问这个servlet时加载它&nbsp;<br />--&gt;&nbsp;<br />&lt;servlet&gt;&nbsp;<br />&lt;servlet-name&gt;SampleServlet&lt;/servlet-name&gt;&nbsp;<br />&lt;servlet-class&gt;mypack.SampleServlet&lt;/servlet-class&gt;&nbsp;<br />&lt;init-param&gt;&nbsp;<br />&lt;param-name&gt;initParam1&lt;/param-name&gt;&nbsp;<br />&lt;param-value&gt;2&lt;/param-value&gt;&nbsp;<br />&lt;/init-param&gt;&nbsp;<br />&lt;load-on-startup&gt;1&lt;/load-on-startup&gt;&nbsp;<br />&lt;/servlet&gt;</p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; ">&lt;!--&nbsp;<br />配置servlet映射（下面代码为SampleServlet指定的相对URL为"/sample":&nbsp;<br />servlet-name 指定servlet的名字，这里的名字应该和&lt;Servlet&gt;元素中定义的名字匹配。&nbsp;<br />url-pattern 指定访问这个servlet的URL。只需给出相对路径。&nbsp;<br />--&gt;&nbsp;<br />&lt;servlet-mapping&gt;&nbsp;<br />&lt;servlet-name&gt;SampleServlet&lt;/servlet-name&gt;&nbsp;<br />&lt;url-pattern&gt;/sample&lt;/url-pattern&gt;&nbsp;<br />&lt;/servlet-mapping&gt;</p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; ">&lt;!--配置session session用来设定HttpSession的生命周期。单位（秒）--&gt;&nbsp;<br />&lt;session-config&gt;&nbsp;<br />&lt;session-timeout&gt;30&lt;/session-timeout&gt;&nbsp;<br />&lt;/session-config&gt;</p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; ">&lt;!--配置Wel0come0文件清单--&gt;&nbsp;<br />&lt;welcome-file-list&gt;&nbsp;<br />&lt;welcome-file&gt;login.jsp&lt;/welcome-file&gt;&nbsp;<br />&lt;welcome-file&gt;index.htm&lt;/welcome-file&gt;&nbsp;<br />&lt;/welcome-file-list&gt;</p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; ">&lt;!--&nbsp;<br />配置Tag Library&nbsp;<br />taglib-uri 设定Tag Library的唯一标识符，在Web应用中将根据这一标识符来引用Tag Library&nbsp;<br />taglib-location 指定和Tag Library对应的TLD文件的位置&nbsp;<br />--&gt;&nbsp;<br />&lt;taglib&gt;&nbsp;<br />&lt;taglib-uri&gt;/mytaglib&lt;/taglib-uri&gt;&nbsp;<br />&lt;taglib-location&gt;/WEB-INF/mytaglib.tld&lt;/taglib-location&gt;&nbsp;<br />&lt;/taglib&gt;</p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; ">&lt;!--&nbsp;<br />配置资源引用&nbsp;<br />description 对所引用的资源的说明&nbsp;<br />res-ref-name 指定所引用资源的JNDI名字&nbsp;<br />res-type 指定所引用资源的类名字&nbsp;<br />res-auth 指定管理所引用资源的Manager,它有两个可选值：&nbsp;<br />Container：由容器来创建和管理resource&nbsp;<br />Application:同WEB应用来创建和管理Resource&nbsp;<br />--&gt;&nbsp;<br />&lt;resource-ref&gt;&nbsp;<br />&lt;description&gt;DB Connection&lt;/description&gt;&nbsp;<br />&lt;res-ref-name&gt;jdbc/sampleDB&lt;/res-ref-name&gt;&nbsp;<br />&lt;res-type&gt;javax.sql.DataSource&lt;/res-type&gt;&nbsp;<br />&lt;res-auth&gt;Container&lt;/res-auth&gt;&nbsp;<br />&lt;/resource-ref&gt;</p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; ">&lt;!--&nbsp;<br />配置安全约束（以下代码指定当用户访问该WEB应用下的所有资源时，必须具备guest角色）&nbsp;<br />web-resource-collection 声明受保护的WEB资源&nbsp;<br />auth-constraint 声明可以访问受保护资源的角色，可以包含多个&lt;role-name&gt;子元素</p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; ">web-resource-name 标识受保护的WEB资源&nbsp;<br />url-pattern 指定受保护的URL路径&nbsp;<br />--&gt;&nbsp;<br />&lt;Security-constraint&gt;&nbsp;<br />&lt;web-resource-collection&gt;&nbsp;<br />&lt;web-resource-name&gt;sample appliction&lt;/web-resource-name&gt;&nbsp;<br />&lt;url-pattern&gt;/*&lt;/url-pattern&gt;&nbsp;<br />&lt;/web-resource-collection&gt;&nbsp;<br />&lt;auth-constraint&gt;&nbsp;<br />&lt;role-name&gt;guest&lt;/role-name&gt;&nbsp;<br />&lt;/auth-constraint&gt;&nbsp;<br />&lt;/Security-constraint&gt;</p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "><br />&lt;!--&nbsp;<br />配置安全验证登录界面：指定当WEB客户访问受保护的WEB资源时，系统弹出的登录对话框的类型。&nbsp;<br />auth-method 指定验证方法，它有三个可选值：BASIC(基本验证)、DIGEST(摘要验证)、FORM(表单验证)&nbsp;<br />realm-name 设定安全域的名称&nbsp;<br />form-login-config 当验证方法为FORM时，配置验证网页和出错网页&nbsp;<br />form-login-page 当验证方法为FORM时，设定验证网页&nbsp;<br />form-error-page 当验证方法为FORM时，设定出错网页&nbsp;<br />--&gt;&nbsp;<br />&lt;login-config&gt;&nbsp;<br />&lt;auth-method&gt;FORM&lt;/auth-method&gt;&nbsp;<br />&lt;realm-name&gt;&nbsp;<br />Tomcat Server Configuration form-Based Authentication Area&nbsp;<br />&lt;/realm-name&gt;&nbsp;<br />&lt;form-login-config&gt;&nbsp;<br />&lt;form-login-page&gt;/login.jsp&lt;/form-login-page&gt;&nbsp;<br />&lt;form-error-page&gt;/error.jsp&lt;/form-error-page&gt;&nbsp;<br />&lt;/form-login-config&gt;&nbsp;<br />&lt;/login-config&gt;</p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; ">&lt;!--配置对安全验证角色的引用--&gt;&nbsp;<br />&lt;security-role&gt;&nbsp;<br />&lt;description&gt;&nbsp;<br />The role that is required to log into the sample application&nbsp;<br />&lt;/description&gt;&nbsp;<br />&lt;role-name&gt;guest&lt;/role-name&gt;&nbsp;<br />&lt;/security-role&gt;&nbsp;<br /></p></span></p></span><span class="Apple-style-span" style="font-family: verdana, sans-serif; ">&lt;/web-app&gt;</span><span class="Apple-style-span" style="font-family: verdana, sans-serif; "><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; ">&lt;?xml version="1.0" encoding="GB2312"?&gt; &lt;!--&nbsp;<br />Web.xml依次定议了如下元素：&nbsp;<br />&lt;web-app&gt;&nbsp;<br />&lt;display-name&gt;&lt;/display-name&gt; 定义了WEB应用的名字&nbsp;<br />&lt;description&gt;&lt;/description&gt; 声明WEB应用的描述信息&nbsp;<br />&lt;filter&gt;&lt;/filter&gt;&nbsp;<br />&lt;filter-mapping&gt;&lt;/filter-mapping&gt;&nbsp;<br />&lt;servlet&gt;&lt;/servlet&gt;&nbsp;<br />&lt;servlet-mapping&gt;&lt;/servlet-mapping&gt;&nbsp;<br />&lt;session-config&gt;&lt;/session-config&gt;&nbsp;<br />&lt;welcome-file-list&gt;&lt;/welcome-file-list&gt;&nbsp;<br />&lt;taglib&gt;&lt;/taglib&gt;&nbsp;<br />&lt;resource-ref&gt;&lt;/resource-ref&gt;&nbsp;<br />&lt;security-constraint&gt;&lt;/security-constraint&gt;&nbsp;<br />&lt;login-config&gt;&lt;/login-config&gt;&nbsp;<br />&lt;/web-app&gt;&nbsp;<br />在web.xml中元素定义的先后顺序不能颠倒，否则Tomcat服务器可能会抛出SAXParseException.&nbsp;<br />--&gt;&nbsp;<br />&lt;!DOCTYPE web-app PUBLIC "-//Sun Microsystems,Inc.//DTD Web Application 2.3//EN" "<a href="http://java.sun.com/dtd/web-app_2_3.dtd" style="text-decoration: none; color: #336699; ">http://java.sun.com/dtd/web-app_2_3.dtd</a>"&gt;&nbsp;<br />&lt;web-app&gt;</p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; ">&lt;display-name&gt;Sample Application&lt;/display-name&gt;</p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; ">&lt;description&gt;&nbsp;<br />This is a Sample Application&nbsp;<br />&lt;/description&gt;</p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; ">&lt;!--&nbsp;<br />filter 配置Servlet过滤器&nbsp;<br />filter-name 定义过滤器的名字。当有多个过滤器时，不能同名&nbsp;<br />filter-class 指定实现这一过滤的类，这个类负责具体的过滤事务&nbsp;<br />--&gt;&nbsp;<br />&lt;filter&gt;&nbsp;<br />&lt;filter-name&gt;SampleFilter&lt;/filter-name&gt;&nbsp;<br />&lt;filter-class&gt;mypack.SampleFilter&lt;/filter-class&gt;&nbsp;<br />&lt;/filter&gt;</p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; ">&lt;!--&nbsp;<br />filter-mapping 设定过滤器负责过滤的URL&nbsp;<br />filter-name 过滤器名。这里的名字一定要和filter中的过滤器名匹配&nbsp;<br />url-pattern 指定过滤器负责过滤的URL&nbsp;<br />--&gt;&nbsp;<br />&lt;filter-mapping&gt;&nbsp;<br />&lt;filter-name&gt;SampleFilter&lt;/filter-name&gt;&nbsp;<br />&lt;url-pattern&gt;*.jsp&lt;/url-pattern&gt;&nbsp;<br />&lt;/filter-mapping&gt;</p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; ">&lt;!--&nbsp;<br />servlet 配置Servlet.&nbsp;<br />servlet-name 定义Servlet的名字&nbsp;<br />servlet-class 指定实现这个servlet的类&nbsp;<br />init-param 定义Servlet的初始化参数和参数值，可有多个init-param。在servlet类中通过getInitParamenter(String name)方法访问初始化参数&nbsp;<br />load-on-startup 指定当Web应用启动时，装载Servlet的次序。&nbsp;<br />当值为正数或零时：Servlet容器先加载数值小的servlet，再依次加载其他数值大的servlet.&nbsp;<br />当值为负或未定义：Servlet容器将在Web客户首次访问这个servlet时加载它&nbsp;<br />--&gt;&nbsp;<br />&lt;servlet&gt;&nbsp;<br />&lt;servlet-name&gt;SampleServlet&lt;/servlet-name&gt;&nbsp;<br />&lt;servlet-class&gt;mypack.SampleServlet&lt;/servlet-class&gt;&nbsp;<br />&lt;init-param&gt;&nbsp;<br />&lt;param-name&gt;initParam1&lt;/param-name&gt;&nbsp;<br />&lt;param-value&gt;2&lt;/param-value&gt;&nbsp;<br />&lt;/init-param&gt;&nbsp;<br />&lt;load-on-startup&gt;1&lt;/load-on-startup&gt;&nbsp;<br />&lt;/servlet&gt;</p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; ">&lt;!--&nbsp;<br />配置servlet映射（下面代码为SampleServlet指定的相对URL为"/sample":&nbsp;<br />servlet-name 指定servlet的名字，这里的名字应该和&lt;Servlet&gt;元素中定义的名字匹配。&nbsp;<br />url-pattern 指定访问这个servlet的URL。只需给出相对路径。&nbsp;<br />--&gt;&nbsp;<br />&lt;servlet-mapping&gt;&nbsp;<br />&lt;servlet-name&gt;SampleServlet&lt;/servlet-name&gt;&nbsp;<br />&lt;url-pattern&gt;/sample&lt;/url-pattern&gt;&nbsp;<br />&lt;/servlet-mapping&gt;</p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; ">&lt;!--配置session session用来设定HttpSession的生命周期。单位（秒）--&gt;&nbsp;<br />&lt;session-config&gt;&nbsp;<br />&lt;session-timeout&gt;30&lt;/session-timeout&gt;&nbsp;<br />&lt;/session-config&gt;</p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; ">&lt;!--配置Wel0come0文件清单--&gt;&nbsp;<br />&lt;welcome-file-list&gt;&nbsp;<br />&lt;welcome-file&gt;login.jsp&lt;/welcome-file&gt;&nbsp;<br />&lt;welcome-file&gt;index.htm&lt;/welcome-file&gt;&nbsp;<br />&lt;/welcome-file-list&gt;</p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; ">&lt;!--&nbsp;<br />配置Tag Library&nbsp;<br />taglib-uri 设定Tag Library的唯一标识符，在Web应用中将根据这一标识符来引用Tag Library&nbsp;<br />taglib-location 指定和Tag Library对应的TLD文件的位置&nbsp;<br />--&gt;&nbsp;<br />&lt;taglib&gt;&nbsp;<br />&lt;taglib-uri&gt;/mytaglib&lt;/taglib-uri&gt;&nbsp;<br />&lt;taglib-location&gt;/WEB-INF/mytaglib.tld&lt;/taglib-location&gt;&nbsp;<br />&lt;/taglib&gt;</p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; ">&lt;!--&nbsp;<br />配置资源引用&nbsp;<br />description 对所引用的资源的说明&nbsp;<br />res-ref-name 指定所引用资源的JNDI名字&nbsp;<br />res-type 指定所引用资源的类名字&nbsp;<br />res-auth 指定管理所引用资源的Manager,它有两个可选值：&nbsp;<br />Container：由容器来创建和管理resource&nbsp;<br />Application:同WEB应用来创建和管理Resource&nbsp;<br />--&gt;&nbsp;<br />&lt;resource-ref&gt;&nbsp;<br />&lt;description&gt;DB Connection&lt;/description&gt;&nbsp;<br />&lt;res-ref-name&gt;jdbc/sampleDB&lt;/res-ref-name&gt;&nbsp;<br />&lt;res-type&gt;javax.sql.DataSource&lt;/res-type&gt;&nbsp;<br />&lt;res-auth&gt;Container&lt;/res-auth&gt;&nbsp;<br />&lt;/resource-ref&gt;</p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; ">&lt;!--&nbsp;<br />配置安全约束（以下代码指定当用户访问该WEB应用下的所有资源时，必须具备guest角色）&nbsp;<br />web-resource-collection 声明受保护的WEB资源&nbsp;<br />auth-constraint 声明可以访问受保护资源的角色，可以包含多个&lt;role-name&gt;子元素</p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; ">web-resource-name 标识受保护的WEB资源&nbsp;<br />url-pattern 指定受保护的URL路径&nbsp;<br />--&gt;&nbsp;<br />&lt;Security-constraint&gt;&nbsp;<br />&lt;web-resource-collection&gt;&nbsp;<br />&lt;web-resource-name&gt;sample appliction&lt;/web-resource-name&gt;&nbsp;<br />&lt;url-pattern&gt;/*&lt;/url-pattern&gt;&nbsp;<br />&lt;/web-resource-collection&gt;&nbsp;<br />&lt;auth-constraint&gt;&nbsp;<br />&lt;role-name&gt;guest&lt;/role-name&gt;&nbsp;<br />&lt;/auth-constraint&gt;&nbsp;<br />&lt;/Security-constraint&gt;</p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; "><br />&lt;!--&nbsp;<br />配置安全验证登录界面：指定当WEB客户访问受保护的WEB资源时，系统弹出的登录对话框的类型。&nbsp;<br />auth-method 指定验证方法，它有三个可选值：BASIC(基本验证)、DIGEST(摘要验证)、FORM(表单验证)&nbsp;<br />realm-name 设定安全域的名称&nbsp;<br />form-login-config 当验证方法为FORM时，配置验证网页和出错网页&nbsp;<br />form-login-page 当验证方法为FORM时，设定验证网页&nbsp;<br />form-error-page 当验证方法为FORM时，设定出错网页&nbsp;<br />--&gt;&nbsp;<br />&lt;login-config&gt;&nbsp;<br />&lt;auth-method&gt;FORM&lt;/auth-method&gt;&nbsp;<br />&lt;realm-name&gt;&nbsp;<br />Tomcat Server Configuration form-Based Authentication Area&nbsp;<br />&lt;/realm-name&gt;&nbsp;<br />&lt;form-login-config&gt;&nbsp;<br />&lt;form-login-page&gt;/login.jsp&lt;/form-login-page&gt;&nbsp;<br />&lt;form-error-page&gt;/error.jsp&lt;/form-error-page&gt;&nbsp;<br />&lt;/form-login-config&gt;&nbsp;<br />&lt;/login-config&gt;</p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; ">&lt;!--配置对安全验证角色的引用--&gt;&nbsp;<br />&lt;security-role&gt;&nbsp;<br />&lt;description&gt;&nbsp;<br />The role that is required to log into the sample application&nbsp;<br />&lt;/description&gt;&nbsp;<br />&lt;role-name&gt;guest&lt;/role-name&gt;&nbsp;<br />&lt;/security-role&gt;&nbsp;<br />&lt;/web-app&gt;</p></span><img src ="http://www.blogjava.net/liuwuping12064915/aggbug/351611.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/liuwuping12064915/" target="_blank">天空布蓝</a> 2011-06-02 17:19 <a href="http://www.blogjava.net/liuwuping12064915/archive/2011/06/02/351611.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>