框架Struts2使用之配置(使用中央仓库maven)




如下

1,先导在pom.xml中导入jar包


<properties>
<struts2.version>2.3.34</struts2.version>
</properties>

<dependencies>

<dependency>
  <groupId>org.apache.logging.log4j</groupId>
  <artifactId>log4j-api</artifactId>
  <version>${log4j2.version}</version>
</dependency>
</dependencies>

2,在web.xml中配置过滤器

<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_3_1.xsd"
         version="3.1">

    <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>

3,在src下面一般在resources下面建struts.xml 再配置

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE struts PUBLIC
        "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
        "http://struts.apache.org/dtds/struts-2.3.dtd">

<struts>

        
 <!--开发者模式 默认为false-->
  <constant name="struts.devMode" value="true"></constant>
  <!--用/作通配符 默认为- -->
<constant name="struts.enable.SlashesInActionNames" value="true"></constant>
  <!--采用动态获取方法-->
  <constant name="struts.enable.DynamicMethodInvocation" value="true"></constant>

 
 
  <!--
package中的name的属性功能本身没有关系,在一个配置文件中可以写多个package ,但name的属性不能相 同,
extends="struts-default"这个是固定的,让package中的类具有action的功能
namespace="/"这个属性和action的name属性构成了访问路径


 
 
-->

<package name="struts2" extends="struts-default" namespace="/">
   
<!--通配符在访问的时候要有一定的规范 1表示建的类 2表示方法-->
 
<action name="*/*" class="com.oracle.action.{1}Action" method="{2}">
        <result name="{2}">/{1}/{2}.jsp</result>
        <result name="query">/commons/tip.jsp</result>
    </action>
</package>


</struts>



猜你喜欢

转载自blog.csdn.net/zyljjf/article/details/79816983