這個問題其實一直很困惑我的,在寫平常的jsp程式時,傳遞參數很容易,透過表單,request,連結等都可以傳遞,但是到了struts2中,在寫的各個地方,都看不到任何的request或是response,不知道該怎麼傳遞參數了,到了今天學習了struts2中的參數傳遞這一節,終於解開了疑惑,但是還不是很清楚,有待以後探索。
在這裡說一下,struts2中,Action之間如何傳遞參數。 Action間的參數傳遞是在struts.xml檔中進行設定的,在result元素中,用param標籤指定傳遞參數的名字和值,但這個參數名,不是隨便寫的,要和將會傳遞給的Action中的屬性名相對應。下面舉例來說明一下。
範例:有一個Login.jsp頁面,有使用者名稱和密碼兩個元素,要將資料提交到Action1中,Action1再要求轉送或重定向到Action2中,在Action1請求轉送或重定向到Action2的過程中,要將使用者名稱和密碼兩個參數,外加一個自訂的不變參數,傳遞到Action2中。 Action2接收到參數,將參數顯示到一個結果頁面:result.jsp
程式碼:
Login.jsp: <form action="/struts2/test/action1" method="post"> 姓名:<input type="text" name="username"/><br/> 密码:<input type="password" name="password"/><br/> <input type="submit" value="提交"/> <input type="hidden" name="type" value="something"/> </form>
struts.xml: <action name="action1" class="com.suo.actions.Action1"> <result name="success" type="redictAction"><!--type指定是请求转发还是重定向--> <param name="actionName">action2</param><!--在这里指定要请求转发或是重定向到的Action--> <param name="username">${username}</param> <param name="password">${password}</param><!--action1中的属性值--> <param name="myparam">piao</param><!-- 自定义的不变参数 --> <!--在这里定义的参数,在传到的Action中,都要有相应的set/get方法,才能够得到该参数 , 并且在传递到的Action中的属性名,要和参数的name保持一致--> </result> </action> <action name="action2" class="com.suo.actions.Action2"> <span> </span><result name="success">/WEB-INF/result/action.jsp</result> </action>
Action1.java: package com.suo.actions; import com.opensymphony.xwork2.ActionSupport; public class Action1 extends ActionSupport { private String username; private String password; public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public String execute() { System.out.println(type); return SUCCESS; } }
Action2.java: package com.suo.actions; import com.opensymphony.xwork2.ActionSupport; public class Action2 extends ActionSupport { private String username; private String password; private String myparam; public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public String getMyparam() { return myparam; } public void setMyparam(String myparam) { this.myparam = myparam; } public String execute() { System.out.println(username); System.out.println(password); System.out.println(myparam); return SUCCESS; } }
result.jsp: <body> username:<s:property value="username"/><br> password:<s:property value="password"/><br> myparam:<s:property value="myparam"/><br> <!-- 这里可以用标签得到的属性值,必须是在Action中有对应的set/get方法才可以 --> </body>
以上就是struts2中的參數傳遞的詳細介紹的內容,更多相關內容請關注PHP中文網(www.php.cn)!

JavadevelovermentIrelyPlatForm-DeTueTososeVeralFactors.1)JVMVariationsAffectPerformanceNandBehaviorAcroSsdifferentos.2)Nativelibrariesviajnijniiniininiinniinindrododerplatefform.3)

Java代碼在不同平台上運行時會有性能差異。 1)JVM的實現和優化策略不同,如OracleJDK和OpenJDK。 2)操作系統的特性,如內存管理和線程調度,也會影響性能。 3)可以通過選擇合適的JVM、調整JVM參數和代碼優化來提升性能。

Java'splatFormentenceHaslimitations不包括PerformanceOverhead,versionCompatibilityIsissues,挑戰WithnativelibraryIntegration,Platform-SpecificFeatures,andjvminstallation/jvminstallation/jvmintenance/jeartenance.therefactorscomplicatorscomplicatethe“ writeOnce”

PlatformIndependendecealLowsProgramStormonanyPlograwsStormanyPlatFormWithOutModification,而LileCross-PlatFormDevelopmentRequiredquiresMomePlatform-specificAdjustments.platFormIndependence,EneblesuniveByjava,EnablesuniversUniversAleversalexecutionbutmayCotutionButMayComproMisePerformance.cross.cross.cross-platformd

JITcompilationinJavaenhancesperformancewhilemaintainingplatformindependence.1)Itdynamicallytranslatesbytecodeintonativemachinecodeatruntime,optimizingfrequentlyusedcode.2)TheJVMremainsplatform-independent,allowingthesameJavaapplicationtorunondifferen

javaispopularforcross-platformdesktopapplicationsduetoits“ writeonce,runany where”哲學。 1)itusesbytiesebyTecodeThatrunsonAnyJvm-備用Platform.2)librarieslikeslikeslikeswingingandjavafxhelpcreatenative-lookingenative-lookinguisis.3)

在Java中編寫平台特定代碼的原因包括訪問特定操作系統功能、與特定硬件交互和優化性能。 1)使用JNA或JNI訪問Windows註冊表;2)通過JNI與Linux特定硬件驅動程序交互;3)通過JNI使用Metal優化macOS上的遊戲性能。儘管如此,編寫平台特定代碼會影響代碼的可移植性、增加複雜性、可能帶來性能開銷和安全風險。

Java將通過雲原生應用、多平台部署和跨語言互操作進一步提昇平台獨立性。 1)雲原生應用將使用GraalVM和Quarkus提升啟動速度。 2)Java將擴展到嵌入式設備、移動設備和量子計算機。 3)通過GraalVM,Java將與Python、JavaScript等語言無縫集成,增強跨語言互操作性。


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

MinGW - Minimalist GNU for Windows
這個專案正在遷移到osdn.net/projects/mingw的過程中,你可以繼續在那裡關注我們。 MinGW:GNU編譯器集合(GCC)的本機Windows移植版本,可自由分發的導入函式庫和用於建置本機Windows應用程式的頭檔;包括對MSVC執行時間的擴展,以支援C99功能。 MinGW的所有軟體都可以在64位元Windows平台上運作。

ZendStudio 13.5.1 Mac
強大的PHP整合開發環境

VSCode Windows 64位元 下載
微軟推出的免費、功能強大的一款IDE編輯器

SAP NetWeaver Server Adapter for Eclipse
將Eclipse與SAP NetWeaver應用伺服器整合。

PhpStorm Mac 版本
最新(2018.2.1 )專業的PHP整合開發工具