這篇文章主要針對有一定jsp編程經驗的愛好者初學struts,如何配置struts過程的一個簡單練習。
首先下載Struts軟體包,到http://struts.apache.org/下載Struts,Struts各版本的差異很大,這裡已Struts1.2.9版本為例,解壓縮包內容如下:
1、在tomcat安裝目錄下的webapps目錄中建立一個webjx目錄。這樣就可以通過訪問"http://localhost:8080/webjx"訪問"webjx"這個目錄。
2、在你建立的目錄webjx中,建立WEB-INF目錄,在WEB-INF中建立classes、lib和tld檔案夾。將壓縮包struts-1.2.9-binlib檔案夾中的commons-*.jar(*代表任意位任一字元)和struts.jar檔案拷貝到建立的webjx/WEB-INF/lib目錄下,然後將Struts中的標籤庫檔案struts-*.tld(*代表任意位任一字元)拷貝到webjx/WEB-INF/tld目錄下
3、在webjx/WEB-INF/目錄下建立一個web.xml檔案,檔案內容如下:
<?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>