struts-笔记

1、 jsp可以include Action     <jsp:include page="welcome.do"/><br>

struts.xml ::::::

 <form-beans>
  <form-bean name="loginForm" type="org.apache.struts.validator.DynaValidatorForm">
   <form-property name="username" type="java.lang.String"/>
   <form-property name="pass" type="java.lang.String"/>
  </form-bean>
 </form-beans>

<action-mappings>
        <action path="/welcome"
             type="org.apache.struts.actions.IncludeAction"
             parameter="/welcome.jsp"/>
 </action-mappings>

 

------------------------------------------------------------------------------------------------

2、LookupDispatchAction继承DispatchAction, 用于对同一个页面上的多个submit按钮进行不同的响应。其原理是首先用MessageResource将按钮的文本和ResKey相关联,例如button.save=保存;然后再复写getKeyMethodMap(), 将ResKey和MethodName对应起来.分别点击不同submit会跳转到两个不同的页面one.jsp,two.jsp

JSP

<html:submit property="method">
   <bean:message key="button.add"/>
  </html:submit>
  <html:submit property="method">
   <bean:message key="button.modify"/>
  </html:submit>

 

struts.xml ::::::

<form-beans>
  <form-bean name="loginForm" type="org.apache.struts.validator.DynaValidatorForm">
   <form-property name="username" type="java.lang.String"/>
   <form-property name="pass" type="java.lang.String"/>
  </form-bean>
 </form-beans>

<action-mappings>
        <action path="/welcome"
             type="org.apache.struts.actions.IncludeAction"
             parameter="/welcome.jsp"/>
 </action-mappings>

 

Action.java

 protected Map getKeyMethodMap()
 {
  Map map = new HashMap();
  map.put("button.add", "add");
  map.put("button.modify", "modify");
  return map;
 }

    public ActionForward add(ActionMapping mapping, ActionForm form,
       HttpServletRequest request, HttpServletResponse response)throws Exception
    {
        System.out.println("增加");
        request.setAttribute("method" , "增加");
        return mapping.findForward("success");
    }
   
    public ActionForward modify(ActionMapping mapping, ActionForm form,
       HttpServletRequest request, HttpServletResponse response)throws Exception
    {
        System.out.println("修改");
        request.setAttribute("method" , "修改");
        return mapping.findForward("success");
    }

 --------------------------------------------------------

3、多按钮,分别执行自己的action

JSP     

     <input type="submit" value='<bean:message key="button.add"/>'  onClick="document.loginForm.action='add.do'"/>        
      <input type="submit" value='<bean:message key="button.modify"/>' onClick="document.loginForm.action='modify.do'"/>   

struts.xml

  <action path="/add" type="lee.LoginAction" name="loginForm"
   scope="request" validate="true" input="/login.jsp" parameter="add">
   <forward name="success" path="/welcome.jsp"/>
  </action>

  <action path="/modify" type="lee.LoginAction" name="loginForm"
   scope="request" validate="true" input="/login.jsp" parameter="modify">
   <forward name="success" path="/welcome.jsp"/>
  </action>

  --------------------------------------------------------

4、RequestProcesso将客户请求转交给合适的 处理器进行处理

 <controller processorClass="lee.MyRequestProcessor" />

 --------------------------------------------------------

5、strutsException

<global-exceptions>
            <exception key="test.exceptionA" 
                       type="lee.exception.ExceptionTestA"
                       scope="request"
                       path="/error.jsp"/>   
            <exception key="test.unknown" 
                       type="java.lang.Exception"
                       scope="request"
                       path="/error.jsp"/> 
    </global-exceptions>

<action path="/processLogin"
    type="lee.LoginAction"
    name="loginForm"
    scope="request"
    validate="true"
    input="/login.jsp">
            <exception key="test.exceptionB" type="lee.exception.ExceptionTestB" path="/error.jsp"/>
   <forward name="failure" path="/failure.jsp"/>
   <forward name="success" path="/success.jsp"/>
  </action>

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值