乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      struts2 框架下MyEclipse編寫(xiě)HelloWorld程序

       LibraryPKU 2013-08-12
      我們必須首先下載struts2的包。其下載地址為:http://struts./download.cgi#struts2211

         struts2的開(kāi)發(fā)步驟大致如下:

         (1)準(zhǔn)備類庫(kù)

         (2)在web.xml文件中配置FilterDispatcher

         (3)開(kāi)發(fā)action。針對(duì)每一個(gè)功能點(diǎn),編寫(xiě)一個(gè)action類。

         (4)編寫(xiě)相關(guān)的結(jié)果頁(yè)面。針對(duì)action返回的結(jié)果代碼,編寫(xiě)相應(yīng)的結(jié)果頁(yè)面。

         (5)在Web應(yīng)用程序的WEB-INF/classes目錄下創(chuàng)建struts.xml,對(duì)action進(jìn)行配置,將頁(yè)面與結(jié)果頁(yè)面關(guān)聯(lián)在一起。

          具體的操作如下:

      step 1:新建web項(xiàng)目

          新建web project。

      struts2 <wbr>框架下MyEclipse編寫(xiě)HelloWorld程序

      step 2:導(dǎo)入struts類庫(kù)

      struts2 <wbr>框架下MyEclipse編寫(xiě)HelloWorld程序

      step 3:在web.xml文件中配置FilterDispatcher

      得到的web.xml文件內(nèi)容如下:

      <?xml version="1.0" encoding="UTF-8"?>
      <web-app version="2.4"
       xmlns="http://java./xml/ns/j2ee"
       xmlns:xsi="http://www./2001/XMLSchema-instance"
       xsi:schemaLocation="http://java./xml/ns/j2ee
       http://java./xml/ns/j2ee/web-app_2_4.xsd">
        <welcome-file-list>
          <welcome-file>index.jsp</welcome-file>
        </welcome-file-list>
       
        <filter>
          <filter-name>struts2</filter-name>
          <filter-class>
             org.apache.struts2.dispatcher.FilterDispatcher
          </filter-class>
        </filter>
       
        <filter-mapping>
          <filter-name>struts2</filter-name>
          <url-pattern>/*</url-pattern>
        </filter-mapping>
      </web-app>
      step 4:編寫(xiě)Action類

      輸入Name為:HelloWorldAction。

      然后選擇Add,在choose interfaces中填入Action,選擇com.open....。如下圖:

      struts2 <wbr>框架下MyEclipse編寫(xiě)HelloWorld程序

      于是在src的ch03.action中生成了文件HelloWorldAction.java。

      編輯其內(nèi)容如下:

      package ch03.action;

      import com.opensymphony.xwork2.Action;

      public class HelloWorldAction implements Action {

       private String message;
       public String getMessage()
       {
        return message;
       }
       public String execute() throws Exception {
        message="Hello World.";
        return SUCCESS;
       }

      }
      step 5:編寫(xiě)結(jié)果頁(yè)面

      新建jsp文件,命名為HelloWorld.jsp。內(nèi)容如下:

      <%@ page contentType="text/html;charset=GBK"%>
      <%@ taglib prefix="s" uri="/struts-tags"%>
      <html>
        <head><title>歡迎頁(yè)面</title></head>
        <body>
           <h2><s:property value="message"/></h2>
        </body>
      </html>

      step 6:在struts.xml文件中配置action

      struts.xml是Struts框架的核心設(shè)置文件,默認(rèn)的路徑是:WEB-INF/classes/struts.xml。

      其內(nèi)容如下:

      <?xml version="1.0" encoding="UTF-8" ?>
      <!DOCTYPE struts PUBLIC
          "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
          "http://struts./dtds/struts-2.0.dtd">

      <struts>
         <package name="default" extends="struts-default">
            <action name="HelloWorld" class="ch03.action.HelloWorldAction">
               <result name="success">/HelloWorld.jsp</result>
            </action>
         </package>
      </struts>

      step 7:發(fā)布并測(cè)試

      struts2 <wbr>框架下MyEclipse編寫(xiě)HelloWorld程序


      struts2 <wbr>框架下MyEclipse編寫(xiě)HelloWorld程序

      最后得到的目錄結(jié)構(gòu)為:

      struts2 <wbr>框架下MyEclipse編寫(xiě)HelloWorld程序

      以上的目錄結(jié)構(gòu)非常重要,程序出錯(cuò)的很大一部分原因就是一些文件放錯(cuò)了位置。具體的錯(cuò)誤表現(xiàn)為:程序的各部分都沒(méi)有出錯(cuò),但是最后卻得不到想要的結(jié)果。

      測(cè)試輸入網(wǎng)址:http://localhost:8080/ch03/HelloWorld.action

      得到的結(jié)果為:HelloWorld

        本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買(mǎi)等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評(píng)論

        發(fā)表

        請(qǐng)遵守用戶 評(píng)論公約

        類似文章 更多