拼搏的人生

          拼搏在繁華的都市

            BlogJava :: 首頁(yè) :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
            7 隨筆 :: 13 文章 :: 6 評(píng)論 :: 0 Trackbacks
          ??? Struts Framework是一種基于Java的技術(shù),Web應(yīng)用程序開(kāi)發(fā)人員通過(guò)Struts Framework即可充分利用OOP的思想,真正做到"write once,run anywhere".Struts提供了一種可創(chuàng)建Web應(yīng)用程序的框架,其中對(duì)應(yīng)用程序的顯示,表示和數(shù)據(jù)的后端代碼進(jìn)行了抽象.
          ??? 作為一個(gè)程序員你必須得了解STRUTS,在之前配置是一個(gè)問(wèn)題,萬(wàn)丈高樓從地起,基礎(chǔ)是保障!所以我們先得讓它RUN起來(lái),然后再談駕御它^_^!
          ??? 配置Struts,必須要以下的環(huán)境和工具:
          ?
          ? . JDK(Java Development Kit)
          ??? 可以從 http://java.sun.com/j2se 下載最新版本
          ? . Servlet容器
          ??? 這個(gè)容器必須支持Servlet規(guī)范2.2版或后續(xù)的版本,已經(jīng)JavaServer Pages規(guī)范1.1或者更高
          ? . XML解析器
          ??? 支持JAXP 1.1版或者后續(xù)版.Xerces解析器正好符合此要求,可以從 http://xml.apache.org/xerces-j 下載
          ? . Xalan XSLT處理器
          ??? 1.2 版或者后續(xù)版本.注意,2.0 版存在一些問(wèn)題.這個(gè)處理器可以把XML文件轉(zhuǎn)換成HTML文檔.這個(gè)處理器包含Xerces解析器.
          ??? 可以從 http://xml.apache.org/xalan-j/index.html 下載Xalan .
          ? . JDBC 2.0以上的package .

          ??? 具體的配置過(guò)程:
          ?
          ? 1. 新建一個(gè)WEB應(yīng)用,如在Tomcat\webapps目錄下新建立一個(gè) Dalston目錄.
          ? 2. 將Struts中的 lib/commons-*.jar 和 lib/struts.jar 文件copy到應(yīng)用中的Dalston\WEB-INF\lib目錄下,然后將Struts中全部的標(biāo)簽庫(kù)描述文件
          ???? (lib/struts-*.tld) copy到Dalston\WEB-INF\tld目錄下 .
          ? 3. 在Dalston\WEB-INF下新建立一個(gè)web.xml文件,在文件加入以下的內(nèi)容:
          ? -------------------------------------------------------------------------
          ? web.xml

          <?xml version="1.0" encoding="ISO-8859-1"?>

          <!DOCTYPE web-app
          ? PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
          ? "http://java.sun.com/j2ee/dtds/web-app_2_3.dtd">

          <web-app>
          ? <display-name>Struts Blank Application</display-name>
          ?
          ? <!-- Standard Action Servlet Configuration (with debugging) -->
          ? <servlet>
          ??? <servlet-name>action</servlet-name>
          ??? <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
          ???? <init-param>
          ????? <param-name>application</param-name>
          ????? <param-value>ApplicationResources</param-value>
          ??? </init-param>
          ??? <init-param>
          ????? <param-name>config</param-name>
          ????? <param-value>/WEB-INF/struts-config.xml</param-value>
          ??? </init-param>
          ?? ?
          ??? <init-param>
          ????? <param-name>debug</param-name>
          ????? <param-value>2</param-value>
          ??? </init-param>
          ??? <init-param>
          ????? <param-name>detail</param-name>
          ????? <param-value>2</param-value>
          ??? </init-param>
          ??? <load-on-startup>2</load-on-startup>
          ? </servlet>


          ? <!-- Standard Action Servlet Mapping -->
          ? <servlet-mapping>
          ??? <servlet-name>action</servlet-name>
          ??? <url-pattern>*.do</url-pattern>
          ? </servlet-mapping>


          ? <!-- The Usual Welcome File List -->
          ? <welcome-file-list>
          ??? <welcome-file>index.jsp</welcome-file>
          ? </welcome-file-list>


          ? <!-- Struts Tag Library Descriptors -->
          ? <taglib>
          ??? <taglib-uri>/struts-bean</taglib-uri>
          ??? <taglib-location>/WEB-INF/tld/struts-bean.tld</taglib-location>
          ? </taglib>

          ? <taglib>
          ??? <taglib-uri>/struts-html</taglib-uri>
          ??? <taglib-location>/WEB-INF/tld/struts-html.tld</taglib-location>
          ? </taglib>

          ? <taglib>
          ??? <taglib-uri>/struts-logic</taglib-uri>
          ??? <taglib-location>/WEB-INF/tld/struts-logic.tld</taglib-location>
          ? </taglib>

          ? <taglib>
          ??? <taglib-uri>/struts-nested</taglib-uri>
          ??? <taglib-location>/WEB-INF/tld/struts-nested.tld</taglib-location>
          ? </taglib>

          ? <taglib>
          ??? <taglib-uri>/struts-tiles</taglib-uri>
          ??? <taglib-location>/WEB-INF/tld/struts-tiles.tld</taglib-location>
          ? </taglib>
          ?
          ? <taglib>
          ??? <taglib-uri>/struts-template</taglib-uri>
          ??? <taglib-location>/WEB-INF/tld/struts-template.tld</taglib-location>
          ? </taglib>
          ?? <taglib>
          ??? <taglib-uri>/jstl/c</taglib-uri>
          ??? <taglib-location>/WEB-INF/tld/c.tld</taglib-location>
          ? </taglib>
          ?

          </web-app>
          =================================================================================================
          ? 4. 修改完web.xml后,在WEB-INF目錄中新建一個(gè)struts-config.xml文件.struts-config.xml內(nèi)容如下:
          struts-config.xml

          <?xml version="1.0" encoding="ISO-8859-1"?>

          <!DOCTYPE struts-config PUBLIC
          ????????? "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN"
          ????????? "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">

          ? <struts-config>
          ????? <form-beans>
          ????? </form-beans>
          ????? <global-forwards>
          ????? </global-forwards>
          ????? <action-mapping>
          ????? </action-mapping>
          ? </struts-config>
          ======================================================================================================
          做完以上的工作,我們就可以測(cè)試一下配置是否正確了.
          在WEB-INF 目錄下建立一個(gè)ApplicationResource.properties 文件,增加一個(gè)屬性:
          index.title=Struts Tutorial
          我們寫一個(gè)測(cè)試JSP文件---test.jsp,它的代碼如下:
          test.jsp

          <%@ page contentType="text/html;charset=gb2312"%>
          <%@ taglib uri="/struts-logic" prefix="logic" %>
          <%@ taglib uri="/struts-bean" prefix="bean" %>
          <%@ taglib uri="/struts-html" prefix="html" %>
          <html:html locale="true">
          <head>
          <html:base/>
          <title>
          <bean:message key="index.title"/>
          </title>
          </head>
          <body>
          測(cè)試我剛配置的Struts!
          </body>
          </html:html>
          重新啟動(dòng)WEB服務(wù)器,在瀏覽器里輸入測(cè)試文件所在地址:
          http://127.0.0.1:8080/Dalston/test.jsp
          如果配置正確那么在IE里就會(huì)輸出:
          測(cè)試我剛配置的Struts!
          如果這樣,那么你成功了,你就可以繼續(xù)高階修煉了!^_^

          posted on 2006-05-21 11:05 Dalston.Young 閱讀(149) 評(píng)論(0)  編輯  收藏 所屬分類: STRUTS

          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 阿拉善左旗| 浮山县| 霍邱县| 班玛县| 和林格尔县| 左贡县| 北京市| 西吉县| 政和县| 修文县| 松原市| 偃师市| 郴州市| 驻马店市| 都安| 满城县| 鄱阳县| 鲁山县| 金山区| 滁州市| 将乐县| 铜鼓县| 普陀区| 玉田县| 连南| 芒康县| 崇阳县| 阜新市| 图木舒克市| 平谷区| 兴文县| 凉山| 大渡口区| 和龙市| 皋兰县| 黑山县| 嘉兴市| 揭阳市| 湘西| 灵石县| 澄城县|