我的java框架总结
- 格式:doc
- 大小:226.50 KB
- 文档页数:29
SSHD总结
——李玉军
一、struts的简单配置
首先导入所有的jar文件给项目添加struts支持。
然后在web.xml中配置Struts
actionFrom 每一个form都要extends org.apache.struts.action.ActionForm,并且属性名应与表示层的表单名相对应!
actionForm的作用:
action
org.apache.struts.action.ActionServlet
config
/WEB-INF/struts-config.xml
debug
3
detail
3
0
action
*.do
Action 所有的action都要继承 org.apache.struts.action.Action 并且实现execte()方法,并在此方法中进行页面转换和传递数据!
Action 和actionFrom 在struts-config.xml中的配置
到此Struts一个简单程序就可以运行了
在浏览器上输入http://localhost:8080/工程名/自定义的action的path属性值.do就可以访问了。
二、DispatchAction的用法
DispatchAction能够根据传入参数值自动选择Action中同名的方法执行
使用步骤:
1、 创建自定义类,继承自DispatchAction;
2、 实现exectue的方法更该方法名,根据程序可写多个方法
3、 配置dispatchAction 在配置时比配置action多加一个属性parmeter 1. 接收输入的数据
2. 转换类型
name="所用的form名称"
path="/自定义的名字 "
scope="request/session"
type="Action所在的路径" />
4、 在表示层必须向后台传递parmeter的值=要调用的后台方法
三、显示友好的报错信息
1、编辑属性文件
将自动增加的一个名字为:applicationResources.properties文件添加到项目中并在struts-config.xml中配置
在文件中编写:
如:errors.header=
errors.footer=
error.validate.number=divisor cannot be 0
在action中的编写:
如:public ActionForward doDivide(……){
CalcForm myForm=(CalcForm)form;
ActionMessages errors =new ActionMessage(“error.valicate.number”);
If(!errors.isEmpty()){
super.saveErrors(request ,errors);
return mapping。findForward(“input”); }
scope="request/session" type="dispacthAction的路径"
parameter="自定义的名字">
/>
……
return mepping findForward(“result”);
}
在页面上的不同编辑
1.头部引入
<%@ taglib profix=”html” uri=”/WEB-INF/struts-html.tld”%>
四、使用动态Form;
Struts提供了动态form(DynaActionForm)动态Form在Struts-config.xml中的配置;
例如:
在action中配置动态form时和自定义form一样;但在action中得到数据的方法不同
例如:
五、struts标签库
1、引入Struts标签 DynaActionform fwxxForm=(DynaActionForm)form;
String name=fwxxForm..getString(“uname”);
int uid=(Integer)fwxxform.get(“age”);
type="org.apache.struts.action.DynaActionForm">
2、使用html标签
使用Struts html标签有绑定数据的特效
注:在页面写到action时必须已有此action 和其方法及属性;
3 使用logic标签
使用logic:notEmpty判断Bean的值是否存在或非空
注:在session范围内查找名字为user的属性 如果找到并且值不为null则执行中的代码
使用logic:equal判断bean值是否相等
……
.
查询
不限--
1
2
3
4
5
<%@ taglib uri="/tags-bean" prefix="bean" %>
<%@ taglib uri="/tags-html" prefix="html" %>
<%@ taglib uri="/tags-logic" prefix="logic" %> <%@ taglib uri="/tags-bean" prefix="bean" %>
<%@ taglib uri="/tags-html" prefix="html" %>
<%@ taglib uri="/tags-logic" prefix="logic" %>