学习struts-blank的知识点
1. 之后,对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> <global-forwards> <forward name="welcome" path="/Welcome.do"/> </global-forwards> <action-mappings> <action path="/Welcome" type="org.apache.struts.actions.ForwardAction" parameter="/pages/Welcome.jsp"/> </action-mappings> <message-resources parameter="resources.application"/> </struts-config> ----------- 在这里action path指定type指定的ForwardAction来出来连接,而ForwardAction简单的把请求流转给parameter所指的JSP页面。这样的好处是客户端的地址栏里显示的仍是Welcome.do这样的地址。 2. index.jsp ----------- <%@ taglib uri="/tags/struts-logic" prefix="logic" %> <logic:redirect forward="welcome"/> ----------- 引用了定义在web.xml里的标签库资源,并使用redirect标签。welcome的标签在前面的<global-forwards>中作了定义。 3. Welcome.jsp ------- <%@ taglib uri="/tags/struts-bean" prefix="bean" %> <%@ taglib uri="/tags/struts-html" prefix="html" %> <%@ taglib uri="/tags/struts-logic" prefix="logic" %><html:html locale="true">
<head> <title><bean:message key="welcome.title"/></title> <html:base/> </head> <body bgcolor="white"><logic:notPresent name="org.apache.struts.action.MESSAGE" scope="application">
<font color="red"> ERROR: Application resources not loaded -- check servlet container logs for error messages. </font> </logic:notPresent><h3><bean:message key="welcome.heading"/></h3>
<p><bean:message key="welcome.message"/></p></body>
</html:html> -------- 最终的页面是使用了一些STRUTS自定义TAG的简单页面,而其中的一些属性key是定义在application.properties这个资源文件中的。我的资源文件的定义如下 --------- # -- welcome -- welcome.title=Hello!Struts! welcome.heading=face to Struts! welcome.message=Welcome to Your First Struts! --------- 4. 最后按照自己定义的目录结构简单的修改一下Lomboze项目中的ANT的build文件,就可以生成第1个struts实例的war文件,导入相应的容器就可以实验了。