简体   繁体   中英

How to pass multiple parameters using html link in Struts1.x

I am trying to pass multiple parameters to my Struts action class using <html:link> property.

I am having a link, it should take two parameters from the JSP page to my action class.

How to achieve this?

在 Struts 1.3 中,参数可以设置为action属性,就像在这个例子中一样

<html:link action="/path/to/action?param1=2&param2=${param2Value}">Some text</html:link> 

Quote from the documentation :

If you prefer to specify a java.util.Map that contains all of the request parameters to be added to the hyperlink, use one of the following techniques:

  • Specify only the name attribute - The named JSP bean (optionally scoped by the value of the scope attribute) must identify a java.util.Map containing the parameters.
  • Specify both name and property attributes - The specified property getter method will be called on the bean identified by the name (and optional scope) attributes, in order to return the java.util.Map containing the parameters.

As the Map is processed, the keys are assumed to be the names of query parameters to be appended to the hyperlink. The value associated with each key must be either a String or a String array representing the parameter value(s), or an object whose toString() method will be called. If a String array is specified, more than one value for the same query parameter name will be created.

Supplmenting these two methods, you can nest one or more tags to dynamically add parameters in a logic-friendly way (such as executing a for loop that assigns the name/value pairs at runtime). This method does not compete with the aforementioned; it will adds its parameters in addition to whatever parameters are already specified.

You can also use a regular HTML <a> tag and create the URL using the standard <c:url> tag from the JSTL.

why don't you go with ajax calling ? by using ajax you can pass many parameter to action class by set the method K

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM