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

📄 ch1.html

📁 为纳福乐观可;个艰苦大使馆幻灯机法安放个体热情人其他人虽然台
💻 HTML
📖 第 1 页 / 共 3 页
字号:
<img src="ch1/1-1-d.jpg"/>
<p> HelloWorld.xml <br>
&lt;Context<br>
  docBase=&quot;c:/workspace/HelloWorld/context&quot;<br>
  path=&quot;/HelloWorld&quot;/&gt;<br>
  解释:<br>
  This file is called the &quot;context descriptor&quot;. It tells Tomcat that you have a web application (yes, a web application is called a &quot;context&quot;).<br>
  这个文件称为“上下文描述符”。它告诉Tomcat,你有一个web应用(是的,一个web应用被称为一个“上下文”)。</p>
<p>Tell Tomcat that the application's files can be found in c:\workspace\HelloWorld\context.<br>
  告诉Tomcat,该应用的文件可以在c:\workspace\HelloWorld\context找到。</p>
<p>This is called the &quot;context path&quot;. It is telling Tomcat that users should access this application using<br>
  http://localhost:8080/HelloWorld.<br>
  这被称为“上下文路径”。它告诉Tomcat,用户将使用http://localhost:8080/HelloWorld访问该应用。</p>
<p>Actually, this is no longer used in Tomcat 5.5. In Tomcat 5.5, it uses the filename of the context descriptor to determine the path:<br>
  实际上,在Tomcat 5.5中已经不再这样使用。在Tomcat 5.5中,它使用上下文描述符的文件名指定路径:</p>
<p>HelloWorld.xml /HelloWorld<br>
  Foo.xml /Foo<br>
  Bar.xml /Bar<br>
</p>
<p>Now, start Tomcat (by running startup.bat). To run your application, run a browser and try to go to <br>
  http://localhost:8080/HelloWorld/app?service=page&amp;page=Home. You should see: <br>
  现在,启动Tomcat(通过运行startup.bat)。要运行你的应用,运行浏览器并尝试定位到http://localhost:8080/HelloWorld/app?service=page&amp;page=Home。你将看到:<br>
<img src="ch1/1-21.jpg"/>
<p>What does this URL mean? It is interpreted this way:<br>
  这个URL表示什么意思呢?它是被这样解释的:</p>
<p>page 021</p>
<img src="ch1/1-2-d.jpg"/>
<p> &lt;Context <br>
  docBase=&quot;c:/workspace/HelloWorld/context&quot;<br>
  path=&quot;/HelloWorld&quot;/&gt;</p>
<p> http://localhost:8080/HelloWorld/app?service=page&amp;page=Home<br>
  解释:<br>
  Context path 上下文路径<br>
  Please show a page 请显示一个页面<br>
  The page to show is named &quot;Home&quot; 要显示的页面名为“Home”<br>
  It represents your Tapestry application 它代表你的Tapestry应用</p>
<p>In fact, if you don't request any particular service, your Tapestry application will show the Home page by default. So, <br>
  you can just enter http://localhost:8080/HelloWorld/app and the same page will be displayed. <br>
  事实上,如果你没有请求任何特别的服务,你的Tapestry应用缺省地将显示Home页。所以,你可以只输入http://localhost:8080/HelloWorld/app,同样的页面仍会显示。<br>
</p>
<p class="style2"> Generating dynamic content <br>
  产生动态内容</p>
<p>Displaying &quot;Hello World&quot; is not particularly interesting. Generate the message dynamically in Java. First, modify <br>
  Home.html as: <br>
  显示“Hello World”并不是特别有趣。在Java中产生动态的消息。首先,像这样修改Home.html:</p>
<p> &lt;html&gt;<br>
  Hello &lt;span&gt;world&lt;/span&gt;!<br>
&lt;/html&gt;</p>
<p>&lt;span&gt; is just a regular HTML element. It is used to enclose a section of HTML code. Next, add an attribute to this <br>
  span: <br>
&lt;span&gt;是一个常规的HTML元素。它被用于包装一段HTML代码。接着,向这个span中加入一个属性:</p>
<p> &lt;html&gt;<br>
  Hello &lt;span <b>jwcid=&quot;subject&quot;</b>&gt;world&lt;/span&gt;!<br>
&lt;/html&gt;</p>
<p>&quot;jwcid&quot; stands for &quot;Java Web Component id&quot;. It is a Tapestry thing. You are saying that this span is a Tapestry component. The id of the component is &quot;subject&quot;. What is the effect of marking it as a component? When Tapestry displays (i.e., renders) the Home page, it will basically output the code in Home.html (check the diagram below). However, when it finds that this span is a Tapestry component, it will create this component and ask it to generate any <br>
  HTML code that it likes. Tapestry will use whatever the component generates to completely replace the &lt;span&gt; element. That is, the process is like: <br>
  “jwcid”代表“Java Web Component id”。它是个Tapestry中的物件。它表明这个span是一个Tapestry组件。这个组件的id是“subject”。把它标记为组建的作用是什么呢?当Tapestry显示(也就是,翻译)Home页时,它将主要输出Home.html中的代码(核对下面的图表)。然而,当它发现这个span是个Tapestry组件,将创建该组件并且要求它产生一些它希望的HTML代码。Tapestry将使用该组件产生的代码完全替换该&lt;span&gt;元素。就是说,过程就像这样:</p>
<p>page 022</p>
<img src="ch1/1-3-d.jpg"/>
</p>
<p>Component &quot;subject&quot; 组件“subject”<br>
  1: Look, just regular HTML code 看,只是常规的HTML代码<br>
  2: Output it 输出它<br>
  3: Look, we have a component here 看,这儿有一个组件<br>
  4: Create the component. It is just a Java object. 创建组件。它正是个Java对象。<br>
  5: Generate HTML for yourself 为自己产生代码<br>
  7: Regular HTML code again 仍然是常规的HTML代码<br>
  6: Output HTML code for itself such as &quot;John&quot; 为自己输出HTML代码,比如“John”<br>
  8: Output it 输出它<br>
</p>
<p>However, in order for Tapestry to create the component, it need to know what type of the component it is. Therefore, <br>
  you need specify its type. This is done in the Home.page file: <br>
  然而,为了让Tapestry创建组件,它需要知道组件是什么类型。因此,你需要指定类型。这是在文件Home.page中做的:<br>
<img src="ch1/1-4-d.jpg"/>
<p> &lt;page-specification&gt;<b><br>
&lt;component id=&quot;subject&quot; type=&quot;Insert&quot;&gt;<br>
&lt;binding name=&quot;value&quot; value=&quot;ognl:greetingSubject&quot;/&gt;<br>
&lt;/component&gt;</b><br>
&lt;/page-specification&gt;<br>
  解释:<br>
  We're talking about the component named &quot;subject&quot; here<br>
  我们谈论的是这儿名为“subject”的组件<br>
  It is an Insert component. It will output some plain text as the HTML. <br>
  它是个Insert组件。它将输出一些纯文本作为HTML。<br>
  Each Insert component has a few &quot;parameters&quot;. In particular, it will evaluate its parameter named &quot;value&quot; and output the result as the plain text to output.<br>
  每个Insert组件拥有一些“参数”。特别地,它将计算名为“value”的参数,把结果作为将要输出的纯文本输出。<br>
  This is the &quot;prefix&quot; of the expression. It is saying that what is following is an &quot;OGNL&quot; expression. <br>
  这是表达式的“前缀”。它说明其后是一个“OGNL”表达式。<br>
  This is an OGNL expression. But what does it mean? <br>
  这是个OGNL表达式。但是代表什么意思呢?<br>
  The whole thing will be evaluated as the value of the &quot;value&quot; parameter and output <br>
  整个物件将作为参数“value”的值被计算并输出<br>
</p>
<p>What is OGNL? It stands for Object Graph Navigation Language. What does this particular expression &quot;greetingSubject&quot; mean? Before the page is rendered, actually, Tapestry will first create a Java object to represent the page. What is the Java class of this object? By default, it is the class org.apache.tapestry.html.BasePage provided by Tapestry. Let's call this object the page object. Then it will create all the components listed here in Home.page and put them into the page object (imagine a page object contains an array to store the components). In this case there is only one Insert component named &quot;subject&quot;: <br>
  OGNL是什么?它代表对象图表导航语言。具体到这个表达式“greetingSubject”是什么意思呢?在页面被翻译之前,实际上,Tapestry经首先创建一个Java对象来表示该页。该对象对应的Java类是什么呢?默认是Tapestry提供的类org.apache.tapestry.html.BasePage。我们把这个对象称为“页面对象”。接着它将创建Home.page中列举的所有组件,并且将它们放进页面对象(想象一个页面对象包含一个数组以存储这些组件)。本例中只有一个名为“subject”的Insert组件:</p>
<p>page 023</p>
<img src="ch1/1-5-d.jpg"/>
<p>解释:<br>
  Page object (a BasePage object) 页面对象(一个BasePage对象)<br>
  Component &quot;subject&quot; 组件“subject”<br>
</p>
<p>It is this page object that is reading Home.html and generating the output. As mentioned before, when it sees the &quot;subject&quot; component in Home.html, it will ask the &quot;subject&quot; component to output HTML code for itself (see the diagram below). Then this component will evaluate the expression &quot;greetingSubject&quot;, which means that it will call a getGreetingSubject() method on the page object and expect that the result to be some plain text for it to output: <br>
  读取Home.html并且产生输出的是该页面对象。如前所述,当它在Home.html中看到“subject”组件,将让该组件为自己输出HTML代码(见下面的图示)。接着,该组件将计算表达式“greetingSubject”,这个表达式意指它将调用页面对象的一greetingSubject()方法并且预期结果是一些将被输出的纯文本。<br>
<img src="ch1/1-6-d.jpg"/>
<p>解释:<br>
  Page object (a BasePage object) 页面对象(一个BasePage对象)<br>
  Component &quot;subject&quot; 组件“subject”<br>
  1: Generate HTML for yourself 为自己产生HTML<br>
  2: call the getGreetingSubject() method 调用getGreetingSubject()方法<br>
  3: Result is &quot;John&quot; 结果是“John”<br>
  4: Output &quot;John&quot; 输出“John”<br>
</p>
<p>As you can see, when displaying the Home page, Home.html is acting as a template. So it is called a &quot;template&quot; in Tapestry. Home.page is specifying the Java class for the page object and list the components to be created in the page <br>
  object, it is called a &quot;page specification&quot;. <br>
  如你所见,当显示Home页的时候,Home.html担当了一个模板。所以在Tapestry中被称为“模板”。Home.page指定了页面对象的类,并且列举了将在页面对象中创建的组件,因此被称为“页面规范”。</p>
<p>Since BasePage is a class coming with Tapestry, it doesn't have such a getGreetingSubject() method. So, you need to create a subclass from it. Let's call it Home (because it is used along with Home.html and Home.page) and put it into package com.ttdev.helloworld: <br>
  由于BasePage来自于Tapestry,它没有getGreetingSubject()这样一个方法。所以,你需要创建一个它的子类。让我们叫它Home(因为它被连同Home.html和Home.page一起使用)并放入包com.ttdev.helloworld中:</p>
<p>page 024</p>
<img src="ch1/1-22.jpg"/>
<p>Define a getGreetingSubject() method that returns a string: <br>
  定义一个返回字符串的getGreetingSubject()方法:</p>
<p> package com.ttdev.helloworld;</p>
<p> import org.apache.tapestry.html.BasePage;</p>
<p> public class Home extends BasePage {<br>
  public String getGreetingSubject() {<br>
  return &quot;John&quot;;<br>
  }<br>
  }</p>
<p>Modify Home.page to use your subclass instead of the default BasePage: <br>
  修改Home.page,使用你的子类代替默认的BasePage:</p>
<p> &lt;page-specification <b>class=&quot;com.ttdev.helloworld.Home&quot;</b>&gt;<br>
&lt;component id=&quot;subject&quot; type=&quot;Insert&quot;&gt;<br>
&lt;binding name=&quot;value&quot; value=&quot;greetingSubject&quot;/&gt;<br>
&lt;/component&gt;<br>
&lt;/page-specification&gt;</p>
<p>Now, you are about to run the application again. If you run it now, you'll still see &quot;Hello World&quot;, not &quot;Hello John&quot;: <br>
  现在,你将要在此运行应用。如果现在运行它,你看到的仍是“Hello World”,而不是“Hello World”:<br>
<img src="ch1/1-23.jpg"/>
<p>Why? You have made changes to your Home.html, Home.page and Home.java files, but Tapestry will cache HTML files and .page files in memory once they're read. In addition, Tomcat will cache Java class files once they're read. So, these changes won't take effect. To make them take effect, you need to reload the application. To do that, go to http://localhost:8080 and choose &quot;Tomcat Manager&quot;, but it requires you to enter a user name and password: <br>
  为什么?你已经改变了你的Home.html、Home.page和Home.java文件,但是一旦HTML文件和.page文件被读取,Tapestry将会在内存中缓存它们。所以,那些改变不会生效。要让它们生效,你需要重新加载应用。要那样,转向http://localhost:8080并选择“Tomcat Manager”,但是它要求你输入用户名和密码:<br>
  page 025</p>
<img src="ch1/1-24.jpg"/>
<p>Therefore, you need to create a user account first. To do that, edit c:\tomcat\conf\tomcat-users.xml: <br>
  因此,你需要首先创建一个用户帐户。要那样,编辑c:\tomcat\conf\tomcat-users.xml:</p>
<p> &lt;?xml version='1.0' encoding='utf-8'?&gt;<br>
&lt;tomcat-users&gt;<br>
&lt;role rolename=&quot;tomcat&quot;/&gt;<br>
&lt;role rolename=&quot;role1&quot;/&gt;<br>
  <b>&lt;role rolename=&quot;manager&quot;/&gt;</b><br>
&lt;user username=&quot;tomcat&quot; password=&quot;tomcat&quot; roles=&quot;tomcat&quot;/&gt;<br>
&lt;user username=&quot;role1&quot; password=&quot;tomcat&quot; roles=&quot;role1&quot;/&gt;<br>
&lt;user username=&quot;both&quot; password=&quot;tomcat&quot; roles=&quot;tomcat,role1&quot;/&gt;<br>
  <b>&lt;user username=&quot;tomcatAdmin&quot; password=&quot;123456&quot; roles=&quot;manager&quot;/&gt;</b><br>
&lt;/tomcat-users&gt;</p>
<p>Then, restart Tomcat so that it can see the user account. Then, using this account to access the Tomcat Manager: <br>
  接着,重新启动Tomcat以便它可以发现这个账户。然后,使用这个账户访问Tomcat管理器:<br>
<img src="ch1/1-25.jpg"/>
<p>To restart the application, just click &quot;Reload&quot; for /HelloWorld. However, as you have already restarted Tomcat, all the <br>
  applications have been reloaded in the process. <br>
  要重启应用,只要点击/HelloWorld的“Reload”链接。然而,由于已经重启了Tomcat,所有的应用已经在该过程中被重新加载了。</p>

⌨️ 快捷键说明

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