Struts開發指南之安裝與使用

2021-04-08 21:47:34 字數 2466 閱讀 5683

struts開發指南之安裝與使用- -

struts可以執行在任何乙個支援jsp1.2和servlet2.3的web container中struts將所有的請求提交到同乙個中心控制器,org.apache.struts.action.actionservlet 類

web.xml配置

<servlet-name>action</servlet-name>

<servlet-class>org.apache.struts.action.actionservlet</servlet-class>

<init-param>

<param-name>config</param-name>

<param-value>/web-inf/struts-config.xml</param-value>

</init-param>

<load-on-startup>2</load-on-startup>

乙個標準的使用了struts的url樣式如下:

擴充套件對映:http://www.my_site_name.com/mycontext/actionname.do

路徑對映:http://www.my_site_name.com/mycontext/do/action_name

<servlet-name>action</servlet-name>

<url-pattern>*.do或/do/*</url-pattern>

struts執行

struts首先在container啟動的時候呼叫actionservlet的init()方法。初始化各種配置。這些配置寫在struts-config.xml檔案中。

乙個標準的struts-config檔案包含如下結構:

<data-sources /> // 定義資料源

<form-beans /> // 定義actionform

<global-exceptions /> // 定義全域性異常

<global-forwards /> // 定義全域性轉向url

<controller /> // 配置controller

<message-resources /> // 配置資源檔案

</struts-config>

struts由上述幾部分組成。其中最主要的是action和form。下面簡單敘述一下其處理過程。

我們來看乙個最簡單的例項

說明:例項一是最簡單的struts程式。它僅僅使用了1個form和1個action功能是將首頁輸入的值傳遞給action,經過判斷後返回結果。如果是空則返回empty。**如下:

input.jsp:

<form method="post" action="/example.do">

請輸入值

<input type="text" name="test"/>

<br><br>

<input type="submit" name="submit" >

<input name="reset" type="reset" >

</form>

struts-config.xml:

<struts-config>

// 配置formbean

<form-beans>

<form-bean name="exampleactionform" type="com.zotn.struts.example1.exampleactionform" />

</form-beans>

// 配置action

<action name="exampleactionform" path="/example" type="com.zotn.struts.example1.exampleaction">

// action內部的foward

<forward name="foward" path="/foward.jsp" />

</action>

</struts-config>

action:

public class exampleaction extends action else

} }

formbean:

public class exampleactionform extends actionform

public void settest(string test)

PF RING開發指南 安裝指南

1 pf ring 主頁 3 概述 pf ring是luca deri發明的提高核心處理資料報效率,並兼顧應用程式的補丁,如libpcap和tcpdump等,以及一些輔助性程式 如ntop檢視並分析網路流量等 pf ring是一種新型的網路socket,它可以極大的改進包捕獲的速度。並且有如下特徵 ...

NDK開發指南 NDK安裝

android ndk 安裝 安裝 1 安裝需要 android ndk目前可以在linux os x 或者 windows作業系統上使用 windows使用者需要安裝cygwin1.7或以後的版本,注意,現在msys和cygwin1.5現在已經不支援了 你必須搭建了android sdk環境才可以...

OpenTSDB 開發指南之 Api運算元據

引數 說明example summary 返回主要摘要 api put?summary details 返回詳細資訊 api put?details sync 是否同步,即是否等待資料都寫入成功後才返回結果 api put?sync sync timeout 返回結果之前的等待時間 api put ...