记录今天在IDEA 用srtruts2写一个简单登录验证遇到的一些问题

今天用IDEA写了一个简单的登录验证,struts2的jar包版本是struts-2.5.16

1.在idea中创建struts2项目时,在配置文件struts.xml的extends="struts-default"中,struts-default一直标红。
 
解决方法:
File -> Project Structure -> Modules -> Web -> Struts2 -> File Sets
在Default File Set中点击“+”,将struts.xml和struts-default.xml放在一个组里就可以了,注意要重新Deloyment。
2.注意2.5以上的版本,请把org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter修改为org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter。
----------------------------------------------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
         version="4.0">
    <filter>
        <filter-name>struts2</filter-name>
        <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
</web-app>
修改为:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
         version="4.0">
    <filter>
        <filter-name>struts2</filter-name>
        <filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
</web-app>

3.发现在struts.xml配置文件中不能像以前一样使用通配了
百度原因:
struts22.5以上为了增强安全性,在struts2.5 以上为了增加安全性,在 struts.xml 添加了这么个属性:regex:.*,添加完成之后就可以正常运行通配符的配置了。

<struts>
    <constant name="struts.devMode" value="true"></constant>
    <package name="user" extends="struts-default" namespace="/">

        <global-allowed-methods>regex:.*</global-allowed-methods>
        <action name="user_*" class="com.jiuyue.controller.LoginController" method="{1}">
            <result name="success">success.jsp</result>
        </action>

    </package>
</struts>
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值