zoukankan      html  css  js  c++  java
  • struts2.5.2 通配符问题_亲测有用

    学了一段时间struts2,跟着教程做,但发现struts2的版本不同,很多东西的使用是有差异的。例如之前遇到的创建sessionFactory的方式就跟之前版本有着明显的差异。今天又遇到一个问题,那就是通配符的使用。

    问题:若不使用通配符,可以找到相对应的action,而使用通配符就会报错,找不到actionmapping之内的错,找不到action。

    问题原因: struts2.5 为了增加安全性,在 struts.xml 添加了这么个属性:<global-allowed-methods>regex:.*</global-allowed-methods>

    解决:

    <?xml version="1.0" encoding="UTF-8"?>
    
    <!DOCTYPE struts PUBLIC
        "-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
        "http://struts.apache.org/dtds/struts-2.5.dtd">
     
    <struts>
    
    <package name="default" namespace="/" extends="struts-default">
       <global-allowed-methods>regex:.*</global-allowed-methods>
     <action name="helloworld" class="com.imooc.action.HelloWorldAction">
          <result>/result.jsp</result>
          <result name="add">/add.jsp</result>
          <result name="update">/update.jsp</result>
     </action>
     
    </package>
     
    <constant name="struts.enable.DynamicMethodInvocation" value="true"></constant>
     
    </struts>

    1.首先,注意头部信息,这个应该是用来指定文件中允许使用那些标签。
      <!DOCTYPE struts PUBLIC"-//Apache Software Foundation//DTD Struts Configuration 2.5//EN" "http://struts.apache.org/dtds/struts-2.5.dtd">
    2.加上下面这句。
      <global-allowed-methods>regex:.*</global-allowed-methods>
     或者(不加上面这句),在action中加上指定允许调用的方法的语句:
      <allowed-methods>login,logout</allowed-methods>
      
      
  • 相关阅读:
    CodeForces 446A. DZY Loves Sequences(最长上升子序列)
    CodeForces
    2020牛客暑期多校训练营(第一场)
    POJ3281-Dining(最大流)(拆点)
    「杂题」图论杂题选做
    「学习小结」CDQ 分治多维偏序问题
    「算法笔记」Tarjan 算法 双连通分量
    「算法笔记」状压 DP
    「算法笔记」数位 DP
    「算法笔记」矩阵乘法
  • 原文地址:https://www.cnblogs.com/jasonlixuetao/p/5933671.html
Copyright © 2011-2022 走看看