国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JSP > 正文

初學(xué)JSP:配置第一個(gè)Struts的配置過程

2024-09-05 00:20:34
字體:
供稿:網(wǎng)友

  這篇文章主要針對(duì)有一定jsp編程經(jīng)驗(yàn)的愛好者初學(xué)struts,如何配置struts過程的一個(gè)簡(jiǎn)單練習(xí)。

  首先下載struts軟件包,到http://struts.apache.org/下載struts,struts各版本的差異很大,這里已struts1.2.9版本為例,解壓縮包內(nèi)容如下: 

  1、在tomcat安裝目錄下的webapps目錄中建立一個(gè)VeVb目錄。這樣就可以通過訪問"http://localhost:8080/VeVb"訪問"VeVb"這個(gè)目錄。

  2、在你創(chuàng)建的目錄VeVb中,建立web-inf目錄,在web-inf中建立classes、lib和tld文件夾。將壓縮包struts-1.2.9-binlib文件夾中的commons-*.jar(*代表任意位任意字符)和struts.jar文件拷貝到建立的VeVb/web-inf/lib目錄下,然后將struts中的標(biāo)簽庫文件struts-*.tld(*代表任意位任意字符)拷貝到VeVb/web-inf/tld目錄下

  3、在VeVb/web-inf/目錄下建立一個(gè)web.xml文件,文件內(nèi)容如下:

<?xmlversion="1.0"encoding="iso-8859-1"?> 
<!doctypeweb-app 
 public"-//sunmicrosystems,inc.//dtdwebapplication2.2//en" 
 "http://java.sun.com/j2ee/dtds/web-app_2_3.dtd"> 
<web-app> 
 <display-name>strutsblankapplication</display-name> 
 <!--standardactionservletconfiguration(withdebugging)--> 
 <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> 
 <!--standardactionservletmapping--> 
 <servlet-mapping> 
  <servlet-name>action</servlet-name> 
  <url-pattern>*.do</url-pattern> 
 </servlet-mapping> 
 <!--theusualwelcomefilelist--> 
 <welcome-file-list> 
  <welcome-file>index.jsp</welcome-file> 
 </welcome-file-list> 
 <!--strutstaglibrarydescriptors--> 
 <taglib> 
  <taglib-uri>/tags/struts-bean</taglib-uri> 
  <taglib-location>/web-inf/tld/struts-bean.tld</taglib-location> 
 </taglib>
 <taglib> 
  <taglib-uri>/tags/struts-html</taglib-uri> 
  <taglib-location>/web-inf/tld/struts-html.tld</taglib-location> 
 </taglib>
 <taglib> 
  <taglib-uri>/tags/struts-logic</taglib-uri> 
  <taglib-location>/web-inf/tld/struts-logic.tld</taglib-location> 
 </taglib>
 <taglib> 
  <taglib-uri>/tags/struts-nested</taglib-uri> 
  <taglib-location>/web-inf/tld/struts-nested.tld</taglib-location> 
 </taglib>
 <taglib> 
  <taglib-uri>/tags/struts-tiles</taglib-uri> 
  <taglib-location>/web-inf/tld/struts-tiles.tld</taglib-location> 
 </taglib>
</web-app>

|||

收集最實(shí)用的網(wǎng)頁特效代碼!

   4、在VeVb/web-inf/目錄下建立一個(gè)struts-config.xml文件,文件內(nèi)容如下:

<?xmlversion="1.0"encoding="iso-8859-1"?> 
<!doctypestruts-configpublic 
     "-//apachesoftwarefoundation//dtdstrutsconfiguration1.2//en" 
     "http://jakarta.apache.org/struts/dtds/struts-config_1_2.dtd"> 
<struts-config> 
  <form-beans> 
  </form-beans> 
  <global-forwards> 
  </global-forwards> 
  <action-mappings> 
  </action-mappings> 
  <message-resourcesparameter="applicationresources"/> 
</struts-config>

   說明:web.xml和struts-config.xml這兩個(gè)文件可以壓縮包struts-1.2.9-binwebappsstruts-blank.war文件直接拷貝到tomcat安裝目錄下的webapps目錄中,啟動(dòng)tomcat服務(wù)器,struts-blank.war就會(huì)自動(dòng)解壓縮成一個(gè)文件夾struts-blank,復(fù)制struts-blank/web-inf下web.xml和struts-config.xml到VeVb/web-inf下修改對(duì)應(yīng)配置。

  5、然后在web-inf/classes中建立applicationresources.properties文件,其中輸入:

  index.title=mystruts

  6、在webapps/VeVb目錄建立test.jsp文件,有如下內(nèi)容:

<%@pagecontenttype="text/html;charset=gbk"%> 
<%@tagliburi="/tags/struts-logic"prefix="logic"%> 
<%@tagliburi="/tags/struts-bean"prefix="bean"%> 
<%@tagliburi="/tags/struts-html"prefix="html"%> 
<html:htmllocale="true"> 
  <head> 
    <title> 
      <bean:messagekey="index.title"/>
    </title> 
  </head> 
  <body> 
    你好 struts! 
  </body> 
</html:html>

   隨后用http://localhost:8080/VeVb/test.jsp訪問該文件,如果頁面顯示"你好struts!"字樣,并且頁面標(biāo)題是mystruts就是成功了。

  配置中注意事項(xiàng):

  如果出現(xiàn)“cannotfindmessageresourcesunderkeyorg.apache.struts.action.message”,是說明找不到applicationresources.properties,要注意三方面設(shè)置。

  第一:在web.xml適當(dāng)位置要有如下設(shè)置:

<init-param> 
  <param-name>application</param-name> 
  <param-value>applicationresources</param-value> 
</init-param>

   第二:在struts-config.xml中適當(dāng)位置要有如下設(shè)置:

  <message-resourcesparameter="applicationresources"/>

  第三:確保applicationresources.properties文件在你建立的web-infclasses文件夾中,而且其中有關(guān)于index.title的設(shè)置(當(dāng)然,以你要提取的key名稱為準(zhǔn))。

  另外說明,你也可以把a(bǔ)pplicationresources.properties放到classes文件夾下其它目錄,同時(shí)修改struts-config.xml中的對(duì)應(yīng)設(shè)置。例如:

  將“applicationresources.properties”放入web-infclasses  est文件夾下。struts-config.xml中的對(duì)應(yīng)設(shè)置:

  <message-resourcesparameter="test/applicationresources"/>

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 长岭县| 甘洛县| 澄江县| 县级市| 师宗县| 五指山市| 宜阳县| 黄浦区| 临澧县| 潮安县| 武清区| 侯马市| 佛冈县| 通山县| 白沙| 元谋县| 仪陇县| 锡林浩特市| 高碑店市| 卢氏县| 平南县| 宁安市| 隆化县| 荥经县| 玛多县| 正镶白旗| 水富县| 晋宁县| 兴化市| 连州市| 富阳市| 阳高县| 巴中市| 广水市| 三门县| 新兴县| 建水县| 广安市| 沂南县| 达拉特旗| 株洲县|