struts2開發(fā)流程及詳細配置
一:Struts開發(fā)步驟:
1. web項目,引入struts - jar包
2. web.xml中,引入struts的核心功能
配置過濾器
3. 開發(fā)action
4. 配置action
src/struts.xml
二:詳細配置
1.引入8個jar文件
commons-fileupload-1.2.2.jar 【文件上傳相關包】
commons-io-2.0.1.jar
struts2-core-2.3.4.1.jar 【struts2核心功能包】
xwork-core-2.3.4.1.jar 【Xwork核心包】
ognl-3.0.5.jar 【Ognl表達式功能支持表】
commons-lang3-3.1.jar 【struts對java.lang包的擴展】
freemarker-2.3.19.jar 【struts的標簽模板庫jar文件】
javassist-3.11.0.GA.jar 【struts對字節(jié)碼的處理相關jar】
2.web.xml詳細配置
<?xml version="1.0" encoding="UTF-8"?> <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <!-- 其他攔截器 --> <!-- 引入struts核心過濾器 --> <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>index.jsp</welcome-file> </welcome-file-list> </web-app>
3.開發(fā)Action(3種方式)
1種:直接繼承ActionSupport
package cn.itcast.a_config; import com.opensymphony.xwork2.ActionSupport; public class UserAction extends ActionSupport { // Action中業(yè)務處理方法 public String login() { System.out.println("UserAction.login()"); return "success"; } }
2種:繼承Action接口
package cn.itcast.a_config; import com.opensymphony.xwork2.Action; import com.opensymphony.xwork2.ActionSupport; public class UserAction implements Action { // Action中業(yè)務處理方法 public String login() { System.out.println("UserAction.login()"); return "success"; } @Override public String execute() throws Exception { return null; } }
3種:不繼承任何類,不實現(xiàn)任何接口
package cn.itcast.a_config; import com.opensymphony.xwork2.Action; import com.opensymphony.xwork2.ActionSupport; public class UserAction { private String userName; public void setUserName(String userName) { this.userName = userName; } // Action中業(yè)務處理方法 public String login() { System.out.println("UserAction.login()" + userName); return "login"; } public String register() { System.out.println("register()" + userName); return "register"; } }
4. 配置action : src/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> <package name="config" namespace="/" extends="struts-default"> <action name="login" class="cn.a_config.UserAction" method="login"> <result name="success">/index.jsp</result> </action> </package> </struts>
本文有關struts開發(fā)流程及詳細配置的內(nèi)容就到這里,希望對大家有所幫助。有興趣的朋友可以參閱:struts1之簡單mvc示例_動力節(jié)點Java學院整理、jsp 開發(fā)之struts2中s:select標簽的使用等。歡迎閱讀本站其他有關專題,感謝大家對腳本之家的支持!
相關文章
如何在mybatis中向BLOB字段批量插入數(shù)據(jù)
這篇文章主要介紹了如何在mybatis中向BLOB字段批量插入數(shù)據(jù)的相關知識,本文通過實例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友參考下吧2020-10-10spring mybatis多數(shù)據(jù)源實例詳解
本文主要介紹sping mybatis多數(shù)據(jù)源處理,在開發(fā)過程中經(jīng)常會遇到多個數(shù)據(jù)庫,這里給大家舉例說明如何處理,希望能幫助有需要的小伙伴2016-07-07- SpringCloudAlibaba是一款優(yōu)秀的微服務架構,在市面上有著廣泛的應用,這篇文章介紹了SpringCloudAlibaba的一些基本使用,適合初學者,希望能夠給大家?guī)韼椭?/div> 2024-08-08
最新評論