zoukankan      html  css  js  c++  java
  • 注解实现struts2零配置

    零配置指的是不经过配置文件struts.xml配置Action

    首先:导入jar   struts2-convention-plugin-2.3.24.1.jar

    package com.action;
    
    import javax.xml.ws.Action;
    
    import org.apache.struts2.convention.annotation.ExceptionMapping;
    import org.apache.struts2.convention.annotation.ExceptionMappings;
    import org.apache.struts2.convention.annotation.Namespace;
    import org.apache.struts2.convention.annotation.Result;
    import org.apache.struts2.convention.annotation.Results;
    
    import com.opensymphony.xwork2.ActionSupport;
    /**
     * @Namespace
     * @Result
     */
    @Namespace(value="/test")
    @Results({
        @Result(name="success",location="/success.jsp"),
        @Result(name="redirect",location="/redirect.jsp",type="ServletRedrectResult.class"),
        @Result(name="login",location="/login.jsp")
    })
    @ExceptionMappings( { 
        @ExceptionMapping(exception = "java.lange.RuntimeException", result = "error")
    }) 
    public class AnnotatedAction extends ActionSupport {
        @Action(input="login")
        public String login()throws Exception{
            return SUCCESS;
        }
        @Action(input="add",output="/add.jsp")
        public String add()throws Exception{
            return "add";
        }
        
    
    
    }

    1) @ParentPackage 指定父包

      2) @Namespace 指定命名空间

      3) @Results 一组结果的数组

      4) @Result(name="success",location="/msg.jsp") 一个结果的映射

      5) @Action(input="login") 指定某个请求处理方法的请求URL。注意,它不能添加在Action类上,要添加到方法上。

      6) @ExceptionMappings 一级声明异常的数组

      7) @ExceptionMapping 映射一个声明异常

    由于这种方式不是很常用,所以大家只做了解即可

  • 相关阅读:
    September 29th 2017 Week 39th Friday
    September 28th 2017 Week 39th Thursday
    September 27th 2017 Week 39th Wednesday
    September 26th 2017 Week 39th Tuesday
    September 25th 2017 Week 39th Monday
    September 24th 2017 Week 39th Sunday
    angular2 学习笔记 ( Form 表单 )
    angular2 学习笔记 ( Component 组件)
    angular2 学习笔记 ( Http 请求)
    angular2 学习笔记 ( Router 路由 )
  • 原文地址:https://www.cnblogs.com/aigeileshei/p/5320050.html
Copyright © 2011-2022 走看看