struts2工程的配置

1 新建一个tomcat web工程


2、 引入struts2的相关包


3、 在工程web.xml中加入过滤器

<filter>
     <filter-name>struts2</filter-name>
     <filterclass>
         org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
      </filter-class>
</filter>

<filter-mapping>
      <filter-name>struts2</filter-name>
      <url-pattern>/*</url-pattern>
</filter-mapping>

4、 添加struts.xml配置文件


    struts.xml默认添加位置在classpath下

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>

    <constant name="struts.enable.DynamicMethodInvocation" value="false" />
    <constant name="struts.devMode" value="false" />

    <constant name="struts.objectFactory" value="org.apache.struts2.spring.StrutsSpringObjectFactory"></constant>

    <package name="user" namespace="/user" extends="struts-default">
        <action name="*" class="user.userAction" method="{1}">
		<result name="create-success">/WEB-INF/user/list_user.jsp</result>
        </action>
    </package>

    <!-- Add packages here -->

</struts>
 

猜你喜欢

转载自yosong.iteye.com/blog/1101129