struts 记录的一些参数
result 的 type 参数 :
<result-type name="chain" /> // 转发 Action (动作链)
<result-type name="dispatcher" default="true"/> // 转发页面(默认)
<result-type name="freemarker" />
<result-type name="httpheader" />
<result-type name="redirect" /> // 重定向页面
<result-type name="redirectAction" /> // 重定向 Action
<result-type name="stream" />
<result-type name="velocity" />
<result-type name="xslt" />
<result-type name="plainText" />
<result-type name="postback" />
========================================================================
默认的 拦截器 defaultStack(栈) :
以下的拦截器都可以视为接口
<interceptor-ref name="exception"/>
<interceptor-ref name="alias"/>
<interceptor-ref name="servletConfig"/>
<interceptor-ref name="i18n"/> // 基本配置拦截器
<interceptor-ref name="prepare"/>
// 用于准备数据,可以在被赋值前「提前」存入对象来进行赋值
<interceptor-ref name="chain"/>
<interceptor-ref name="scopedModelDriven"/>
<interceptor-ref name="modelDriven"/>
// 用来 action 实现接口 可以进行一些列的存取 (属性、对象、集合)
<interceptor-ref name="fileUpload"/>
<interceptor-ref name="checkbox"/>
<interceptor-ref name="datetime"/>
<interceptor-ref name="multiselect"/>
<interceptor-ref name="staticParams"/>
<interceptor-ref name="actionMappingParams"/>
<interceptor-ref name="params"/> // 和赋值的时候有点关系
<interceptor-ref name="conversionError"/>
<interceptor-ref name="validation">
<param name="excludeMethods">
input,back,cancel,browse
</param>
</interceptor-ref>
<interceptor-ref name="workflow">
<param name="excludeMethods">
input,back,cancel,browse
</param>
</interceptor-ref>
<interceptor-ref name="debugging"/>
<interceptor-ref name="deprecation"/>
========================================================================
struts 标签
1.需要引入标签 <%@ taglib prefix="s" uri="/struts-tags" %>
2.一些常用的标签
显示错误信息:<s:property value="exception.message" />
等...
========================================================================
OGNL 表达式
实则就是 Root(栈)+Context(值)
讲解:
Root -- 里面存的都是对象,一般是当前运行的 Action 对象,和自己需要复制的一些对象(User),该栈是遵循「先进后出 / 后进先出」的原则,所以存对象的时候要注意,并且是 ArrayList 模拟的,两个方法 pop push。
Context -- 里面存的是 ActionContext(数据中心),想要获取该对象可以通过
ActionContext.getContext() 方法来获得,生命周期同 request 一样,可以取出
ActionContext 数据中心
|-request
|-response
|-ServletContext
|-requestScope
|-sessionScope
|-applicationScope
|-params
|-attrs
....
可以取出很多对象,不过这些对象的生命周期不会受到 ActionContext 的生命周期影响,说白了就是一个中介。
如何取出值栈对象
ValueStack vs=ActionContext.getContext().getValueStack();
========================================================================
Struts2返回JSON数据类型的时候,无需提供action的配置(注意,指定方法名):
<action name="doProductTypeAction" class="doProductTypeAction" method="doAction">
<!-- <result name="success" type="json"></result> -->
</action>
将JSON对象返回,在Action里的用法:
public void doAction() {
HttpServletResponse response = ServletActionContext.getResponse();
PrintWriter writer;
try {
writer = response.getWriter();
JSONObject obj = productTypeManager.doFindProductType(1);
writer.print(obj.toJSONString());
} catch (IOException e) {
e.printStackTrace();
}
}
注意:此时方法无需返回字符串,作为映射路径名。在方法内部,将JSON对象通过response的getWriter写入对象,即可把JSON传向输出端。
需要格外注意:方法一定不能返回String,否则会报找不到相应Action的错误!!
========================================================================
要想使返回的结果还要经过别的 Action :
<result name="toList" type="redirectAction" >
<param name="namespace">/</param>
<param name="actionName">CustomerAction_list</param>
</result>
========================================================================
struts 文件上传的获取的方法:
1.在action 类中定义以下属性,并创建 get set 方法
private File photo;
private String photoFileName;
private String photoContentType;
2.在方法中采用「renameTo」方法
photo.renameTo(new File("G:/SSH/"+photoFileName));
========================================================================
jq 中的在家页面就显示:
$(document).ready(function(){
code....
});
js 中的在家页面就显示:
window.onload=function(){
code...
};
========================================================================
待更新...