!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-nameStruts Blank Application/display-name
!-- Standard Action Servlet Configuration (with debugging) --
servlet
servlet-nameaction/servlet-name
servlet-classorg.apache.struts.action.ActionServlet/servlet-class
init-param
param-nameapplication/param-name
param-valueApplicationResources/param-value
/init-param
init-param
param-nameconfig/param-name
param-value/WEB-INF/struts-config.xml/param-value
/init-param
init-param
param-namedebug/param-name
param-value2/param-value
/init-param
init-param
param-namedetail/param-name
param-value2/param-value
/init-param
load-on-startup2/load-on-startup
/servlet
!-- Standard Action Servlet Mapping --
servlet-mapping
servlet-nameaction/servlet-name
url-pattern*.do/url-pattern
/servlet-mapping
!-- The Usual Welcome File List --
welcome-file-list
welcome-fileindex.jsp/welcome-file
/welcome-file-list
!-- Struts Tag Library Descriptors --
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
4、在jzxue/WEB-INF/目录下建立一个struts-config.xml文件,文件内容如下:
?xml version="1.0" encoding="ISO-8859-1" ?
!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.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-resources parameter="ApplicationResources"/
/struts-config
说明:web.xml和struts-config.xml这两个文件可以压缩包struts-1.2.9-bin webapps struts-blank.war文件直接拷贝到tomcat安装目录下的webapps目录中,启动tomcat服务器,struts-blank.war就会自动解压缩成一个文件夹struts-blank,复制struts-blank/WEB-INF下web.xml和struts-config.xml到jzxue/WEB-INF下修改对应配置。
5、然后在WEB-INF/classes中建立ApplicationResources.properties文件,其中输入:
index.title=My Struts
6、在webapps/jzxue目录建立test.jsp文件,有如下内容:
%@page contentType="text/html;charset=GBK"%
%@ taglib uri="/tags/struts-logic" prefix="logic" %
%@ taglib uri="/tags/struts-bean" prefix="bean" %
%@ taglib uri="/tags/struts-html" prefix="html" %
html:html locale="true"
head
title
bean:message key="index.title" /
/title
/head
body
你好 Struts!
/body
/html:html
随后用http://localhost:8080/jzxue/test.jsp访问该文件,如果页面显示"你好 Struts!"字样,并且页面标题是My Struts就是成功了。
配置中注意事项:
如果出现“Cannot find message resources under key org.apache.struts.action.MESSAGE”,是说明找不到ApplicationResources.properties,要注意三方面设置。
第一:在web.xml适当位置要有如下设置:
init-param
param-nameapplication/param-name
param-valueApplicationResources/param-value
/init-param
第二:在struts-config.xml中适当位置要有如下设置:
message-resources parameter="ApplicationResources"/
第三:确保ApplicationResources.properties文件在你建立的WEB-INFclasses文件夹中,而且其中有关于index.title的设置(当然,以你要提取的key名称为准)。
另外说明,你也可以把ApplicationResources.properties放到classes文件夹下其它目录,同时修改struts-config.xml中的对应设置。例如:
将“ApplicationResources.properties”放入WEB-INFclassestest文件夹下。struts-config.xml中的对应设置:
message-resources parameter="test/ApplicationResources"/