This problem has always puzzled me. When writing ordinary jsp programs, it is easy to pass parameters through forms, requests, links, etc. However, in struts2, I cannot see them in every place I write. When it comes to any request or response, I don’t know how to pass parameters. Today I learned the parameter passing section in struts2 and finally solved the doubt, but it is not very clear yet and needs to be explored in the future.
Let me talk here about how to pass parameters between Actions in struts2. Parameter transfer between Actions is configured in the struts.xml file. In the result element, use the param tag to specify the name and value of the passed parameter. However, this parameter name is not written casually. It must be consistent with the Action to be passed to. corresponding to the attribute name. Let’s illustrate with an example.
Example: There is a Login.jsp page with two elements: username and password. The data needs to be submitted to Action1. Action1 then requests forwarding or redirection to Action2, and Action1 requests forwarding or redirection to In the process of Action2, the two parameters of user name and password, plus a customized constant parameter, must be passed to Action2. Action2 receives the parameters and displays the parameters to a result page: result.jsp
Code:
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>
The above is a detailed introduction to parameter passing in struts2 For more related content, please pay attention to the PHP Chinese website (www.php.cn)!

The class loader ensures the consistency and compatibility of Java programs on different platforms through unified class file format, dynamic loading, parent delegation model and platform-independent bytecode, and achieves platform independence.

The code generated by the Java compiler is platform-independent, but the code that is ultimately executed is platform-specific. 1. Java source code is compiled into platform-independent bytecode. 2. The JVM converts bytecode into machine code for a specific platform, ensuring cross-platform operation but performance may be different.

Multithreading is important in modern programming because it can improve program responsiveness and resource utilization and handle complex concurrent tasks. JVM ensures the consistency and efficiency of multithreads on different operating systems through thread mapping, scheduling mechanism and synchronization lock mechanism.

Java's platform independence means that the code written can run on any platform with JVM installed without modification. 1) Java source code is compiled into bytecode, 2) Bytecode is interpreted and executed by the JVM, 3) The JVM provides memory management and garbage collection functions to ensure that the program runs on different operating systems.

Javaapplicationscanindeedencounterplatform-specificissuesdespitetheJVM'sabstraction.Reasonsinclude:1)Nativecodeandlibraries,2)Operatingsystemdifferences,3)JVMimplementationvariations,and4)Hardwaredependencies.Tomitigatethese,developersshould:1)Conduc

Cloud computing significantly improves Java's platform independence. 1) Java code is compiled into bytecode and executed by the JVM on different operating systems to ensure cross-platform operation. 2) Use Docker and Kubernetes to deploy Java applications to improve portability and scalability.

Java'splatformindependenceallowsdeveloperstowritecodeonceandrunitonanydeviceorOSwithaJVM.Thisisachievedthroughcompilingtobytecode,whichtheJVMinterpretsorcompilesatruntime.ThisfeaturehassignificantlyboostedJava'sadoptionduetocross-platformdeployment,s

Containerization technologies such as Docker enhance rather than replace Java's platform independence. 1) Ensure consistency across environments, 2) Manage dependencies, including specific JVM versions, 3) Simplify the deployment process to make Java applications more adaptable and manageable.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Atom editor mac version download
The most popular open source editor

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.