zoukankan      html  css  js  c++  java
  • Struts2 注解基础

    The Struts dispatcher cannot be found.  This is usually caused by using Struts tags without the associated filter. Struts tags are only usable when the request has passed through its servlet filter, which initializes the Struts dispatcher needed for this tag. - [unknown location]

    先是报这个错,因为struts2的filter是*.action的原因。改为以下即可。

    <filter-mapping>
    <filter-name>struts2Filter</filter-name>
    <url-pattern>/*</url-pattern>
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>FORWARD</dispatcher>
    </filter-mapping>

    1.convention plugin插件

    convention plugin默认result页面存放在WEB-INF/content.(可以通过struts.convention.result.path属性来设置)。

    如 http://localhost:8080/hello-world该url将访问WEB-INF/content/hello-world.jsp。

    2.convention plugin查找类的规则

        convention plugin会查找struts、struts2、action、actions等包里的满足以下条件的类(好像可以设置)

    • 实现或继承com.opensymphony.xwork2.Action、ActionSupport的类。
    • 或者action结尾的类名
      修改包查找规则修改下面两个属性
    <constant name="struts.convention.package.locators" value="test" />
    <constant name="struts.convention.package.locators.basePackage" value="com.test" />

    3.convention plugin类对应URL规则

      在struts、struts2、action、actions等包下生成“/”,更深层次则继续以“包名/”,类名子目全小写,按驼峰法分隔单词添加“-”。举例如下:

    com.example.actions.MainAction -> /main
    com.example.actions.products.Display -> /products/display
    com.example.struts.company.details.ShowCompanyDetailsAction -> /company/details/show-company-details

    4.result对应页面名称

      页面命名与类名规则相同,再加上“-”与result值即可,如果找不到result的页面,似乎会返回到省略result名称的页面,还有success可省略,如下:

    URLResultFile that could matchResult Type
    /hello success /WEB-INF/content/hello.jsp Dispatcher
    /hello success /WEB-INF/content/hello-success.htm Dispatcher
    /hello success /WEB-INF/content/hello.ftl FreeMarker
    /hello-world input /WEB-INF/content/hello-world-input.vm Velocity
    /test1/test2/hello error /WEB-INF/content/test/test2/hello-error.html Dispatcher


    5.chaining

      例子:foo action找不到result页面,会自动查找foo-bar action

    package com.example.actions;

    import com.opensymphony.xwork2.Action;
    import com.opensymphony.xwork2.ActionSupport;

    public class HelloAction extends ActionSupport {
    @Action("foo")
    public String foo() {
    return "bar";
    }

    @Action("foo-bar")
    public String bar() {
    return SUCCESS;
    }
    }

      

      

    参考:

    struts2 convention-plugin文档

    http://www.vaannila.com/struts-2/struts-2-example/struts-2-annotation-example-1.html

    http://apps.hi.baidu.com/share/detail/48320875

  • 相关阅读:
    start pyhton project(2)
    java.lang.ClassFormatError: Truncated class file
    linux 查看计算机信息命令
    VS2010UltimTrialCHS 版注册码
    VS2008打包安装程序,实现覆盖安装设置
    WPF移动不规则渐变色窗体
    C#下移动无边框窗体(直接粘贴可用)
    TCP通信过程中时时监测连接是否已断开
    WIN7下使用DotNetBar,关闭Aero效果,使用Office2007Form皮肤
    【原创】企业级工作流管理系统评价依据或标准
  • 原文地址:https://www.cnblogs.com/yyyy/p/2307928.html
Copyright © 2011-2022 走看看