ActionForm的校验 <struts-config> <form-beans> <form-bean name="xxx" type="ActionForm的类全名"> < fail" path="/basic/fail.jsp" redirect="false"(重定向,默认false)/> </action> <action-mappings> </struts-config <struts-config> ..... --使用message标签时配置资源文件的位置--> </struts-config> struts会自动的判断返回ActionError是否为空,如果是空可以自动的转向指定页面,也可以强制不进行校验 要实现上面提得到功能还需要在struts-config中配置。
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> <! --指定资源文件的路径--> <message-resources parameter="hello.ApplicationResources"/> </struts-config> -----
DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.0//EN" "http: DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN" "http:
注: 转向方式: forward 如struts-config文件中配置<forward name="success" path="/WEB-INF/main.jsp" /> 或 在Action WEB-INF/main.jsp").forward(request, response);都是服务器读取了该页面内容,并发送到客户端.客户端的地址不变.内容跳转了 重定向方式: Redirect 如struts-config
file" name = "up" />
<input type = "submit" value = "上传" />
</form>
//struts-config.xml文件中
<struts-config action>
</action-mappings>
<message-resources parameter="com.etoak.struts.ApplicationResources" />
</struts-config name = "filename" />
<input type = "submit" value = "确定" />
</form>
struts-config.xml文件中
<struts-config action>
</action-mappings>
<message-resources parameter="com.etoak.struts.ApplicationResources" />
</struts-config
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> <action-mappings> name="error" path="/jsp/loginError.jsp"></forward> </action> </action-mappings> </struts-config
DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.3//EN" "http: //struts.apache.org/dtds/struts-config_1_3.dtd"> <struts-config> <form-beans> <form-bean name value="/org/apache/struts/validator/validator-rules.xml,/WEB-INF/validations.xml" /> </plug-in> </struts-config
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> <! overview" forward="/hello.jsp"/> <action path="/failed" forward="/wuwu.jsp" /> </action-mappings> </struts-config
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> <! request"> <forward name="test" path="/WEB-INF/jsp/test/test.jsp"/> </action> </action-mappings> </struts-config
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 forward> <forward name="error" path="/login_error.jsp"></forward> </action> </action-mappings> </struts-config
<struts-config> <form-beans> <form-bean name="xxx" type="ActionForm的类全名"> <form-bean name="LoginForm path="跳转页面的路径"/> <forward name="xxx" path="xxx/xxx.jsp"/> </action> </action-mappings> </struts-config
-- 典型的Struts配置片段 --> <struts-config> <form-beans> <form-bean name="loginForm" type="com.example.LoginForm /> <forward name="error" path="/error.jsp"/> </action> </action-mappings> </struts-config
DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.3//EN" "http: //struts.apache.org/dtds/struts-config_1_3.dtd"> <struts-config> <form-beans> <form-bean name="BookForm com.yourcompany.struts.BookAction"> <forward name="list" path="/list.jsp"/> </action> </action-mappings> </struts-config 本例中的资源文件放在com.zy包中,代码如下所示: <struts-config> <! -- 其他代码省略 --> <message-resources parameter="com.zy.ApplicationResources" /> </struts-config> 配置时,只需要指定资源文件的基本名即可
表1-1-2 Struts配置元素 配置元素 说明 <struts-config> Struts 1配置文件的根元素 <form-beans> 用来配置项目中的ActionFrom,包含<form-bean DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.3//EN" "http: //struts.apache.org/dtds/struts-config_1_3.dtd"> <struts-config> <form-beans > <form-bean name="LoginForm </action-mappings> <message-resources parameter="com.yourcompany.struts.ApplicationResources" /> </struts-config
是struts-config.xml中ActionForm定义名称,如下: <struts-config> <form-beans> <form-bean name=" </<em>struts-config</em>> 可见我们的界面模型完整类com.jdon.framework.test.web.UserActionForm是在struts-config.xml中form-beans
path属性的值等于所截部分的那个 Action. 3(页面数据注入) 找到对应的action之后,ActionServlet会把表单提交的数据给存放(生成对应调用 set/get方法)到struts-config