今天用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>