⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch1.html

📁 为纳福乐观可;个艰苦大使馆幻灯机法安放个体热情人其他人虽然台
💻 HTML
📖 第 1 页 / 共 3 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
<style type="text/css">
<!--
.style1 {color:#FF0000;font-size:32px;}
.style2 {color:#0000FF;font-size:20px;}
-->
</style>
</head>

<body style="text-align:center;background:#ADADAD">
<div style="margin:auto;width:930px;text-align:left;border:2px solid #66FFFF;background:#CACACA;">
page 010
<p>page 011</p>
<img src="toc/1.jpg"/>
<p class="style1"> Chapter 1 Getting Started with Tapestry<br>
  第一章 Tapestry入门</p>
<p>page 012</p>
<p>(译注:使用原书的插图,开发工具是英文版的,希望以后可以换成中文的;<br>
  文中的一些解释处理流程的图表做起来很麻烦,所以使用截图代替它;<br>
  示例代码中增加的内容使用UBB标签“[B][/B]”标注,<br>
  而被删除的代码使用UBB标签“[DEL][/DEL]”标注;<br>
  对于attribute和property,本文为加区分,统一译为“属性”,<br>
  严格说来两者是有区别的,自己也不是很明白,偷懒了,呵呵。)</p>
<p class="style2"> What's in this chapter? <br>
  本章内容</p>
<p>In this chapter you'll learn to how to setup a development environment and develop a Hello World application with <br>
  Tapestry. <br>
  本章中你将学习如何建立Tapestry的开发环境,以及开发Hello World应用。</p>
<p class="style2"> Developing a Hello World application with Tapestry <br>
  使用Tapestry开发Hello World应用</p>
<p>Suppose that you'd like to develop an application like this: <br>
  加入逆向开发类似这样的一个应用:<br>
<img src="ch1/1-1.jpg"/>
<p class="style2"> Installing Eclipse <br>
  安装Eclipse</p>
<p>First, you need to make sure you have Eclipse installed. If not, go to http://www.eclipse.org to download the Eclipse <br>
  platform (e.g., eclipse-platform-3.1-win32.zip) and the Eclipse Java Development Tool (eclipse-JDT-3.1.zip). Unzip both <br>
  into c:\eclipse. Then, create a shortcut to run &quot;c:\eclipse\eclipse -data c:\workspace&quot;. This way, it will store your projects under the c:\workspace folder. To see if it's working, run it and then you should be able to switch to the Java perspective: <br>
  首先,需要保证已经安装了Eclipse。否则,去http://www.eclipse.org下载Eclipse平台(例如,eclipse-platform-3.1-win32.zip)和Eclipse Java开发工具(eclipse-JDT-3.1.zip)。都解压放在c:\eclipse。接着,创建一个快捷方式以执行“c:\eclipse\eclipse -data c:\workspace”。 这样一来,它将把你的项目存储在c:\workspace目录下。 要检查是否可以运行,执行它, 然后你可以看到Java透视图:<br>
<img src="ch1/1-2.jpg"/>
</p>
<p class="style2"> Installing Tomcat <br>
  安装Tomcat</p>
<p>Next, you need to install Tomcat. Go to http://jakarta.apache.org to download a binary package of Tomcat. Download <br>
  the zip version instead of the Windows exe version. Suppose that it is jakarta-tomcat-5.5.7.zip. Unzip it into a folder <br>
  (suppose that it is c:\tomcat). If you're going to use Tomcat 5.5 with JDK 1.4 or 1.3, you also need to download the <br>
  compat package and unzip it into c:\tomcat. <br>
  下一步,你需要安装Tomcat。在http://jakarta.apache.org下载一个Tomcat的二进制包。下载zip版本的而不是Windows的exe版本。假如是jakarta-tomcat-5.5.7.zip。将它解压放入一个目录(假如是 c:\tomcat)。如果你打算在JDK 1.4或者1.3上使用Tomcat 5.5,还需要下载compat包并且解压放入c:\tomcat。</p>
<p>Before you can run it, make sure the environment variable JAVA_HOME is defined to point to your JDK folder (e.g., <br>
  C:\Program Files\Java\jdk1.5.0_02): <br>
  在运行它之前,确保环境变量JAVA_HOME已经被定义指向你的JDK目录(例如,C:\Program Files\Java\jdk1.5.0_02):<br>
<img src="ch1/1-3.jpg"/>
<p>page 013</p>
<p>If you don't have it, define it now. Now, run c:\tomcat\bin\startup.bat. If it is working, you should see: <br>
  如果没有,立刻定义。现在,运行c:\tomcat\bin\startup.bat。如果起作用了,你可以看到:<br>
<img src="ch1/1-4.jpg"/>
<p>Open a browser and go to http://localhost:8080 and you should see:<br>
  打开浏览器进入http://localhost:8080,你可以看到:</p>
<p>page 014</p>
<img src="ch1/1-5.jpg"/>
<p>Let's shut it down by running c:\tomcat\bin\shutdown.bat. <br>
  通过执行c:\tomcat\bin\shutdown.bat可以将它关闭。</p>
<p class="style2"> Installing Tapestry <br>
  安装Tapestry</p>
<p>Next, go to http://jakarta.apache.org/tapestry to download a binary package of Tapestry (e.g., tapestry-4.0-beta-13.zip) and the documentation (e.g., tapestry-4.0-beta-13-docs.tar.gz). Unzip the former into a folder say c:\tapestry. Then unzip the latter into c:\tapestry\doc. That's it. You can't run it yet because it is a library, not an application. <br>
  下一步,去http://jakarta.apache.org/tapestry下载一个Tapestry的二进制包(例如,tapestry-4.0-beta-13.zip)以及文档(例如,tapestry-4.0-beta-13-docs.tar.gz)。将前者解压放在比如c:\tapestry,第二个解压放在c:\tapestry\doc。就是这些。你现在还不能运行它,因为它只是一个库,而不是一个应用。</p>
<p>In addition, Tapestry depends on quite some other libraries. To get them, Download <br>
  http://howardlewisship.com/downloads/quick-start/tapestry-libraries.tar.gz and unpack the files into say <br>
  c:\tapestry\tapestry-libraries. You can find the jar files in c:\tapestry\tapestry-libraries\lib\web: <br>
  另外,Tapestry依赖一些其他的库。可在http://howardlewisship.com/downloads/quick-start/tapestry-libraries.tar.gz下载获得它们,并且解压在比如c:\tapestry\tapestry-libraries。你可以在c:\tapestry\tapestry-libraries\lib\web找到一些jar文件:<br>
<img src="ch1/1-6.jpg"/>
</p>
<p class="style2"> Creating a Hello Word application <br>
  创建Hello World应用</p>
<p>Now, create a new Java project. Name it &quot;HelloWorld&quot; and make sure it uses a separate output folder: <br>
  现在,创建一个新的Java工程。命名为“HelloWorld”并且确保使用一个单独的输出文件夹:</p>
<p>page 015</p>
<img src="ch1/1-7.jpg"/>
<p>Set the output folder as shown below:<br>
  像下面这样设置输出文件夹:</p>
<p>page 016</p>
<img src="ch1/1-8.jpg"/>
<p>Finally, you should see the project structure:<br>
  最后,你可以看到该工程的结构:<br>
<img src="ch1/1-9.jpg"/>
<p>The bin folder is useless so you can delete it. Then right click the project and choose &quot;Properties&quot;, choose &quot;Java Build Path&quot; on the left hand side, choose the &quot;Libraries&quot; tab: <br>
  目录bin没有什么用处所以可以删掉。右击工程并且选择“属性”,选择左手边的“Java构建路径”,选择“库”选项卡:<br>
<img src="ch1/1-10.jpg"/>
<p>Click &quot;Add Library&quot; and choose &quot;User Library&quot;:<br>
  点击“增加库”,选择“用户库”:</p>
<p>page 017</p>
<img src="ch1/1-11.jpg"/>
<p>If you see a &quot;Tapestry Framework&quot; library as shown above, Do NOT choose it! It is Tapestry 3.0 coming with Spindle. <br>
  Click &quot;Next&quot;: <br>
  如果看到了一个在上面显示的库“Tapestry框架”,<b>不要</b>选择它!这是Spindle自带的Tapestry 3.0。点击“下一步”:<br>
<img src="ch1/1-12.jpg"/>
<p>Click &quot;User Libraries&quot; to define your own Tapestry library: <br>
  点击“用户库”以定义自己的Tapestry库:<br>
<img src="ch1/1-13.jpg"/>
<p>Click &quot;New&quot; to define a new one and enter &quot;Tapestry 4&quot; as the name of the library: <br>
  点击“新建”,定义一个新的并输入“Tapestry 4”作为库的名字:<br>
<img src="ch1/1-14.jpg"/>
<p>Click &quot;Add JARs&quot;, browse to c:\tapestry and add the tapestry-*.jar files there:<br>
  点击“增加JAR包”,浏览c:\tapestry并加入其中的tapestry-*.jar文件:<br>
<img src="ch1/1-15.jpg"/>
<p>Then browse to c:\tapestry\tapestry-libraries\lib\web and add all the jar files there except those tapestry-*.jar (they may be for a different beta version of Tapestry, so don't use them): <br>
  然后浏览c:\tapestry\tapestry-libraries\lib\web,加入其中的所有jar文件,除了名为tapestry-*.jar的文件(它们可能是Tapestry的一个不同beta版本,所以不要用它们):</p>
<p>page 018</p>
<img src="ch1/1-16.jpg"/>
<p>Then close all the dialog boxes. Next, create a new file Home.html in context\WEB-INF in the project. It will act as the home page of your application. Next, use DreamWeaver, FrontPage to modify it. But where is it located? It is in <br>
  context/WEB-INF in your project and the whole project is in c:\workspace: <br>
  然后关闭所有的对话框。下一步,在工程的context\WEB-INF中创建一个新的文件Home.html。他将作为你的应用的主页。下一步,使用DreamWeaver,FrontPage修改它。但是如何定位它呢?整个工程在c:\workspace,它就在工程中的context/WEB-INF中:<br>
<img src="ch1/1-17.jpg"/>
</p>
<p>So, its full path is c:\workspace\HelloWorld\context\WEB-INF\Home.html. Knowing its full path, you can modify it to look like: <br>
  所以,它的完全限定路径是c:\workspace\HelloWorld\context\WEB-INF\Home.html。知道了它的完全限定路径,你可以这样修改它:</p>
<p>page 019</p>
<img src="ch1/1-18.jpg"/>
<p>If you'd like, you can edit the HTML code directly in Eclipse: <br>
  如果愿意,你可以直接在Eclipse中编辑HTML代码:<br>
<img src="ch1/1-19.jpg"/>
<p>Next, create a new file Home.page in the same folder as Home.html with the following content: <br>
  接下来,在与Home.html相同的目录中创建一个新的文件Home.page,包含如下内容:</p>
<p> &lt;?xml version=&quot;1.0&quot;?&gt;<br>
&lt;!DOCTYPE page-specification PUBLIC<br>
&quot;-//Apache Software Foundation//Tapestry Specification 4.0//EN&quot;<br>
&quot;http://jakarta.apache.org/tapestry/dtd/Tapestry_4_0.dtd&quot;&gt;<br>
&lt;page-specification&gt;<br>
&lt;/page-specification&gt;</p>
<p>Next, you need to make the Tapestry jar files available to this application. To do that, copy all the tapestry jar files in c:\tapestry and the 3rd party jar files it needs in c:\tapestry\tapestry-libraries\lib\web into c:\tomcat\shared\lib: <br>
  接着,你需要使得Tapestry的jar文件对本应用可用。要实现这点,拷贝c:\tapestry中的所有tapestry的jar文件以及c:\tapestry\tapestry-libraries\lib\web中的第三方jar文件放入c:\tomcat\shared\lib:<br>
<img src="ch1/1-20.jpg"/>
<p>This way, they will be available to all applications running in Tomcat, including your own. Next, create a file web.xml in context\WEB-INF with the following content: <br>
  这样,它们对Tomcat中运行的所有应用都是可用的,包括你自己的。接下来,在context\WEB-INF中创建一个web.xml文件,包含如下内容:</p>
<p> &lt;?xml version=&quot;1.0&quot;?&gt;<br>
&lt;web-app xmlns=&quot;http://java.sun.com/xml/ns/j2ee&quot;<br>
  xmlns:xsi=&quot;http://www.w3.org/TR/xmlschema-1/&quot;<br>
  xsi:schemaLocation=&quot;http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd&quot; version=&quot;2.4&quot;&gt;<br>
&lt;display-name&gt;HelloWorld&lt;/display-name&gt;<br>
&lt;servlet&gt;<br>
&lt;servlet-name&gt;HelloWorld&lt;/servlet-name&gt;<br>
&lt;servlet-class&gt;org.apache.tapestry.ApplicationServlet&lt;/servlet-class&gt;<br>
&lt;load-on-startup&gt;1&lt;/load-on-startup&gt;<br>
&lt;/servlet&gt;<br>
&lt;servlet-mapping&gt;<br>
&lt;servlet-name&gt;HelloWorld&lt;/servlet-name&gt;<br>
&lt;url-pattern&gt;/app&lt;/url-pattern&gt;<br>
&lt;/servlet-mapping&gt;<br>
&lt;/web-app&gt;</p>
<p>You can ignore its meaning for now. <br>
  现在你可以忽略它的含义。</p>
<p>page 020</p>
<p>To make this application run in Tomcat, you must register it with Tomcat. To do that, create a file HelloWorld.xml in <br>
  c:\tomcat\conf\Catalina\localhost: <br>
  要使这个应用可以在Tomcat中运行,你必须在Tomcat中注册它。只需要在c:\tomcat\conf\Catalina\localhost中创建一个文件HelloWorld.xml:<br>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -