一,struts1和struts2的区别
1,struts2 低侵入
2,内核发生了改变 struts1内核 struts ,struts2内核web work;
3,struts1有formbean ,struts2没有formbean(怎么传值呢? 用ognl表达式。)
二,package
name:要求是唯一的。
extends:表示继承其他的package
abstract:里边的action不生效
namespace: 命名空间
1,默认的命名空间 “ ”
2,根命名空间 “/”
3,命名空间 例如 “/test” 注释:必须以反斜杠开头。
访问action的时候 : /工程名/命名空间/action的名字;
先找找看有没有/test这样的命名空间,如果有有,直接调用,如果没有,执行默认的命名空间(如果有根命名空间,那就执行根命名空间下的action);
三,常量
1,
<constant name="struts.action.extension" value="ambow"></constant>
2,web下的src下建立 struts.properties :struts.action.extension=do
### Struts default properties
###(can be overridden by a struts.properties file in the root of the classpath)
###
四,分模块开发
<include file=""/>
五,在action当中调用不同的方法
1,
<package name="test5" extends="struts-default" namespace="/test5">
<!-- <action name="loginAction" class="cn.hdu.action.LoginAction" method="getDeptAll"> -->
<action name="loginAction" class="cn.hdu.action.LoginAction">
<result name="DEPTALL" >/deptAll.jsp</result>
<result name="SUCCESS" >/success.jsp</result>
</action>
</package>,
2, <form action="<%=basePath%>test5/loginAction!getDeptAll.action" method="post">
六,struts2 和 servlet api的结合
1,
// HttpServletRequest request=ServletActionContext.getRequest();
// String user=request.getParameter("username");
// String pass=request.getParameter("password");
// HttpSession session=request.getSession();
2, ActionContext ac=ActionContext.getContext();
// ac.put("user", user);
// ac.put("pass", pass);
//
//
// Map session=ac.getSession();
//
// session.put("session_user", "session_Name213");
// session.put("session_pass", "sesion_pass_123213");