java_home
jre_>path
在web.xml中添加tag标记。
<taglib>
<taglib-uri>/WEB-INF/struts-nested.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-nested.tld</taglib-location>
</taglib>
在页面中
<%@ page contentType="text/html; charset=gb2312"%>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<bean:write name="HelloWordForm" scope="session" property="word"/>
<html:form action="/helloword">
请输入Hello Word:<html:text property="word"/>
<html:submit/>
</html:form>
在调用Action之前做以下动作:
默认在session中检查bean的实例。
如果没有则新建一个,并添加到用户的Session。
调用Bean中的setter。
调用Action的execute方法。
针对一个Bean多个页面的情况,同一个表单的不同页面也提交到相同的Action。
ActionForm Beans
Business Beans【Stateful or stateless bean】
System Status Beans【Entity Bean】
View
国际化,用户界面
<jsp:include/>
<bean:message bundle="" key=""/>
<bean:message key="login.title"/>
<message-resources>标记必须在 <controller />标记的下面,不然就会出错
<message-resources parameter="test.struts.ApplicationResources2" key="another" />
验证用户输入:
1.ActionForm中验证
实现validate方法。
validate="true"
return mapping.getInputForward();
DynaActionForm
1.指定dynamic=true
2.type为org.apache.struts.action.DynaActionForm
3.form-property为要添加的属性
在ActionForm中使用映射属性
public Object getMap(String key) { return map.get(key); }
public void setMap(String key,Object obj) { this.map.put(key,obj); }
<html:text property="map(ok)"/>
<bean:write name="UserForm" property="map(ok)"/>
ActionServlet多模块配置(ReloadableActionServlet)
<init-param> <param-name>config</param-name> <param-value>/WEB-INF/struts-config.xml </param-value> </init-param> <init-param> <param-name>config/model2</param-name> <param-value>/WEB-INF/struts-config2.xml </param-value> </init-param>
对Struts应用来说,把load-on-startup元素包括进去来保证资源的正确初始化是很关键的。
Action
Dispatch Action
根据传入的参数决定调用那个方法
在action的config档中设定parameter="method",
在Action中添加各种method
在URL中加入?method=***
LookUpDispatchAction
按照不同的目的把表单提交到不同的Action
1.在ActionForm中添加action属性
2.在HTML中添加以下submit代码,代表两个不同的action
<html:submit property="action"><bean:message key="button.submit.hello"/></html:submit>
<html:submit property="action"><bean:message key="button.submit.ok"/></html:submit>
3.extend LookupDispatchAction
getKeyMethodMap()
ActionMessages.GLOBAL_MESSAGE;
ActionErrors errors = new ActionErrors();
errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("demo"));
saveErrors(request, errors);
plug-in
plug-in通常我们提供一种对应用程序进行一些常用的资源进行初始化,特别是一些比较费时的操作,如文件的I/O操作数据库的连接等,对这些资源你就不需要经常去初始化这些资源,这样就可以提高你的应用程序的速度