1、模块包含:
可以使用include标签在struts的配置文件中包含其他的配置文件:
2、设置默认的Action:
通过default-action-ref标签设置默认的action:
3、配置带结果类型的result标签:
通过result标签的type属性进行设置:
4、配置全局结果集:
通过global-results标签设置全局结果集:
<package name="student" namespace="/student" extends="user">
<action name="student" class="com.action.UserAction">
<result>/exam.jsp</result>
</action>
</package>
5、配置动态结果集:
动态结果集就是根据执行结果中传过来的参数通过OGNL表达式${}从值栈中取值作为action的result:
Action:
public String execute() throws Exception {
if(type == 1) r="/success.jsp";
else if (type == 2) r="/login.jsp";
return "success";
}
struts.xml:
6、配置带参数的结果集:
即是在result标签的结果URL中通过OGNL表达式的方式给这个URL添加参数信息:
Action:
private int type;
@Override
public String execute() throws Exception {
return "success";
}
public int getType() {
return type;
}
public void setType(int type) {
this.type = type;
}
struts.xml:
这个type可以是Action的执行函数赋值的,也可以是从表单或者URL中传过来的。 JSP: 在URL中指定type的值: