Struts1第三天

Action子类
   DispatchAction      ForwardAction

 页面
 url?methodName=add
 <input type="hidden" name="methodName" value="add">
 
 配置文件
 <action parameter="methodName">

 DispatchAction
 add(mapping,form,req,resp){

 }
   MappingDispatchAction
 功能:和父类一样,将多个业务流程组织放在一个处理类中
 优势:
  不需要页面指定额外的方法名信息
  只需要在配置文件中直接指定方法名即可

 

<%@page isELIgnored="false"%>

xml文件
 系统运行必不可少的信息
资源文件
 系统运行的辅助信息
 可能存储:国际化显示信息
    错误描述信息

1 全局跳转设置<global-forwards />:在配置文件中配置一次,所有的action共享
 <global-forwards>
  <forward name="errorPage" path="/WEB-INF/page/error.jsp"></forward>
 </global-forwards>

2 基于web容器,设置错误码跳转资源
 <error-page>
  <error-code>404</error-code>
  <location>/404.jsp</location>
 </error-page>
 
 <error-page>
  <exception-type>java.lang.NullPointerException</exception-type>
  <location>/nullPointer.jsp</location>
 </error-page>
3 基于struts框架,设置异常的跳转资源
 1) 在配置文件中指定异常类型及跳转目标
 <global-exceptions>
  <exception key="error.exception.empty" type="java.lang.NullPointerException" path="/nullPointer.jsp"></exception>
 </global-exceptions>

 ===================================
 type 是异常类路径
 path 是异常出现之后,系统跳转的资源目标
 key  是跳转到页面之后,页面中显示的信息,在资源文件中所对应的key信息
 ===================================

 2) 把错误描述信息书写在资源文件中
  error.exception.empty = null pointer exception occured
 3) 在页面中使用struts标签,读取错误描述信息
  <%@taglib prefix="bean" uri="http://struts.apache.org/tags-bean"%>
  <bean:message key="error.exception.empty"/>

4 Action
   ForwardAction IncludeAction  DispatchAction
     MappingDispatchAction   LookupDispatchAction
 

5 IncludeAction:
 解决页面中引入其他页面时,遵循mvc思想
  1) 在页面中必须发送.do方式的请求
 <jsp:include page="/headPage.do">
  <jsp:param name="title" value="stu Management"/>
 </jsp:include>
   2) 在struts-config.xml中指定处理类
 <action path="/headPage" type="org.apache.struts.actions.IncludeAction"  parameter="/head.jsp"></action>

   【3)】 如果引入方页面传递参数给被引入得页面,则在被引入得页面中动态获取参数信息
 ${param.title } System

 


 function assign(msg){
  if(msg == 'modify')
   form1.action.value = 'modify.do';
  if(msg == 'delete')
   form1.action.value = 'delete.do';
  form1.action.submit();
 }

 <form name="form1" action="">
  ......
  <input type="submit" value="modify" οnclick="assign('modify')"/>
  <input type="submit" value="delete" οnclick="assign('delete')"/>
 </form>

6 LookupDispatchAction
 解决问题:一个form表单中具有多个提交按钮
 编写流程:
 1) 编写页面index.jsp
 <form name="form1" action="operate.do">
  <input type="text" name="uname"/><br>
  <html:submit property="bu">
   <bean:message key="button.modifyButton"/>
  </html:submit>
  
  <html:submit property="bu">
   <bean:message key="button.deleteButton"/>
  </html:submit>
 </form>
 ===============================================
 action 指定统一的目标operate.do
 property指定提交按钮的name属性值
 <bean:message key="button.modifyButton"/>
  指定提交按钮在客户端的显示信息
 ===============================================

 2) 配置struts-config.xml
 <action path="/operate" type="com.sinojava.struts.web.AllAction" parameter="bu">
        <forward name="resultPage" path="/result.jsp" />
     </action>
 ===============================================
 parameter="bu" 指定客户端页面中提交按钮的名字
 ===============================================
 
 3) 编写处理类:
 要求必须继承LookupDispatchAction,覆盖其中geteKeyMethodMap方法
 AllAction extends LookupDispatchAction {
  protected Map getKeyMethodMap() {
   Map map = new HashMap();
   map.put("button.modifyButton", "modifyInfo");
   map.put("button.deleteButton", "deleteInfo");
   return map;
  } 
  public ActionForward modifyInfo(....
  public ActionForward deleteInfo(....
 }
 4) 编写资源文件
 button.modifyButton = modify info button
 button.deleteButton = delete info button


html  显示
jstl 逻辑控制
el 数据操作

struts标签:
 struts-html  显示
 struts-bean 数据操作
 struts-logic 逻辑控制

注意:
 使用struts标签的常见异常:
 1 Cannot retrieve mapping for action /regist
 解决:使用<html:form>要求必须配置path属性
 2 Cannot retrieve definition for form bean null
 解决,<html:form>要求必须创建并配置formBean
 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值