Struts2配置

1.導包

  將lib文件夾下的jar包導入到項目工程中

2.編寫web.xml文件

web.xml

  <display-name>goodsmessage</display-name>
    <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>
  <welcome-file-list>
    <welcome-file>/foolish.jsp</welcome-file>
  </welcome-file-list>
此段代碼包含在<web-app></web-app>中。

3.在src下創建struts.xml文件

struts.xml

<?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>
  <!-- 設置爲true,當struts.xml文件更改時,不需重啓tomcat -->
  <constant name="struts.devMode" value="true"/>

  <!--此處用來實現<input type="file">文件上傳功能 -->
  <constant name="struts.multipart.maxSize" value="102400000"/>

  <include file="struts-default.xml"></include>
  
  <package name="Login" extends="struts-default">
    <action name="login" class="Login.AdminLoginAction">
      <result name="loginfail">/loginerror.jsp</result>
      <result name="loginsuccess">/newhome.lzw</result>
    </action>
    
    <action name="logout" class="Login.logout">
      <result name="logout">/login.jsp</result>
    </action>  
  </package>
</struts>


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章