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>
      
      
  • 相关阅读:
    字符编码 进制转换
    Android工具HierarchyViewer 代码导读(1) 功能实现演示
    jQuery中的bind(), live(), on(), delegate()
    [转]ActionScript3.0中XML处理方法
    Pane和Panel的区别
    [转]在命令行中编译运行Java Applet
    [转]关于五险一金,你知道多少?
    [转]ActionScript3.0对象深复制
    [转]用Flashbug调试Flash
    [转]用EditPlus搭建简易的Java开发环境
  • 原文地址:https://www.cnblogs.com/jasonlixuetao/p/5933671.html
Copyright © 2011-2022 走看看