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 映射一个声明异常

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

  • 相关阅读:
    Completely disable mousewheel on a WinForm
    C# Form内存回收
    解锁用户
    CentOS7+JDK8编译Hadoop2.6.4
    网址收藏
    pvresize
    Linux crontab 命令格式与详细例子
    在CentOS 7中安装与配置JDK8
    Disable SELinux CentOS 7
    Python3标准库:math数学函数
  • 原文地址:https://www.cnblogs.com/aigeileshei/p/5320050.html
Copyright © 2011-2022 走看看