Struts2環境搭建

1.導包java

  • struts2-core-2.3.31.jar
  • xwork-core-2.3.31.jar
  • ognl-3.0.19.jar
  • log4j-core-2.3.jar
  • log4j-api-2.3.jar
  • javassist-3.11.0.GA.jar
  • freemarker-2.3.22.jar
  • commons-lang3-3.2.jar
  • commons-io-2.2.jar
  • commons-fileupload-1.3.2.jar
  • asm-tree-3.3.jar
  • asm-commons-3.3.jar
  • asm-3.3.jar

 2.在 src 目錄下建立 struts.xml 文件web

<?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>
<!--配置action的訪問後綴-->
<constant name="struts.action.extension" value="do,,"></constant>
<!--修改struts配置後自動加載struts文件 不須要重啓tomcat-->
<constant name="struts.configuration.xml.reload" value="true"></constant>
    <package name="default" namespace="/" extends="struts-default">
        <action name="employee" class="com.ww.struts2.action.EmployeeAction" method="success">  //配置action(Servlet)類
            <result name="success">index.jsp</result>  //name屬性的值與action的execute方法的返回值對應
        </action>
    </package>
</struts>

 3.在web.xml中配置struts過濾器apache

<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>
相關文章
相關標籤/搜索