zoukankan      html  css  js  c++  java
  • struts2总结三:struts2配置文件struts.xml的简单总结

    一、struts中的常量constant的配置。

    在struts2中同一个常量的配置有三种方式,第一种在struts.xml中,第二种在struts.properties中配置,第三种在web.xml中配置。

    以配置struts2为开发模式为例:

    1.在struts.xml中配置

    <constant name="struts.devMode" value="true"></constant>

    2.在struts.properties中配置

    struts.devMode=true

    3.在web.xml中配置

    <filter>

        <filter-name>struts2</filter-name>

    <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>

      <init-param>

      <param-name>struts.devMode</param-name>

      <param-value>true</param-value>

      </init-param>

      </filter>

    二、struts中的include配置(引入其他配置文件)的几个注意点:

    1、被引入的配置文件的格式与struts.xml的格式一致。

    2、包名的名字要保持单一性。

    3、不同的命名空间里面可以出现相同的action名。

    三.struts的package的配置和命名空间(namespace)的配置的注意点

    1.在struts2中,包的存在是用来继承的,命名空间的存在是用来解决相同的action的名字。

    2.当发起请求时,当在指定的命名空间里找不到指定的action时,系统会自动到默认的命名空间里去找。

    3.当发起请求时,先在根命名空间里找,如果找不到,然后去默认命名空间里找,如果再找不到,报错。

    4.如果配置了命名空间,需要注意的是访问的路径变为根目录/命名空间/*.jsp形式。

    四.action的配置

    1.在请求端配置Action Mappings路径

    2.配置Action名称Action Names

    3.配置Action Metods。action的方法有三种使用方式,直接配置,动态方法调用(Wildcard Method),通配符(Wildcard Method)。

    要使用动态方法调用(Wildcard Method),首先要在struts.xml中开启DMI动态方法调用。

    <constant name="struts.enable.DynamicMethodInvocation" value="true"></constant>

    访问方式:在URL中输入:http://localhost:8080/项目名/action名!方法名.action

  • 相关阅读:
    MongoDB笔记: 安装和常见问题
    Spring Boot方式的Dubbo项目
    Centos7安装Redis5.0.5并加入Systemd服务
    生成Nginx服务器SSL证书和客户端证书
    OpenSSL的证书, 私钥和签名请求(CSRs)
    迁移Git项目到Gitlab
    Ubuntu18.04 Server安装Nginx+Git服务和独立的svn服务
    ESXi6.5上的Ubuntu虚机在远程SSH时宕机
    Nginx访问路径添加密码保护
    从阿里云DATAV GeoAtlas接口抽取行政区划数据
  • 原文地址:https://www.cnblogs.com/longshiyVip/p/4544909.html
Copyright © 2011-2022 走看看