Understanding jsp Interator

Asked 2 years ago, Updated 2 years ago, 86 views

I'd like to get a value for the session using the iterator in jsp.

<s:form action="hogeAction">//hogeAction
<s:iterator value="session.data">//session.data can be used as an iterator to view the data contained in the session.data 
have in one's possession of
<s:name in property value="name"/>//session.data
<s:property value="id"/>//id in session.data

<input type="hidden" name="item" value='<s:property value="name"/>'>
// ↑ Again, I want to get the name in session.data, but for some reason, there is one. 
It contains all the values of name. 
</s:iterator>
</s:form>

I did an iterator before input, but it didn't go as I wanted...
Can I take it out only once with the iterator?

Note:
The value of the name in session.data is Apple, orange, peach in the array and is displayed one by one in the JSP using an iterator.In order to add the function of hitting into the shopping basket when you click on it, you put the data into the form with a div tag.I just want to send the data and put it in the shopping basket.It seems that the value to be sent in the form has to be written in the input, so I made it a hidden attribute, so when I clicked on Apple for confirmation, I got all the values in the array value.For some reason, when I set the type to checkbox, I could only see the one I checked, but I'm planning to add photos and descriptions to the div tag, so I'd like to add them to the shopping basket when I click on any of them.I want to get rid of the muddiness.

java jsp struts

2022-09-30 18:03

1 Answers

The current code will print three input tags with the same name attribute (below), so the request parameter item has three values: apple, orange, peach.

<input type="hidden" name="item" value="apple"/>
<input type="hidden" name="item" value="orange"/>
<input type="hidden" name="item" value="peach"/>

If you only want to send the data that you click on, you need to implement a simple mechanism to identify it.Please google that.

add

Thank you!When I asked Google, I didn't really understand.

The following article appeared first.I think it will be helpful.

https://stackoverflow.com/questions/13020727/how-to-submit-specific-iterator-entry-to-action-in-struts-2


2022-09-30 18:03

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.