Note on Jstl el usage (java.lang.NumberFormatException:For input string: "UserName")

Source: Internet
Author: User

When using Jstl tag <c:foreach var= "Item" items= "${managerpurviewlist}" begin= "0" >, it can be used to display the collection of data on the page, but one thing must be noted, Is the question of the meaning of Var and items.

Look at the API documentation, just a simple explanation, in fact, in the implementation of the tag, the inside is through the items specified in the collection object to obtain a iterator, this is foreachiterator. In other words, take out the collection object of your items property and get the iterator above it, and get the first element in the collection by the next method of the iterator (although there are few differences depending on whether you have configured the start end and step iterations), it is important to note that When you get to the first element, it assigns the element to the variable name specified in the var attribute as a generic object, such as when you know Var= "item" in the Var attribute, then I is an object.

If you iterate over a list of custom objects such as list<user>, then item gets an object, and the object is an object "" type, which means The property value of each User object inside the list is get out, as an object and then into the object referenced by I to go, here, we should understand, in fact, the label in dealing with the List<user> type collection of the presentation of the problem, It is simple to take the property value of each specific object in the collection to encapsulate it into a single object, and then put it into the object array of item, so we can not use the $ (item.username) method to get the corresponding value when we show it on the foreground JSP page. , otherwise it will be reported java.lang.NumberFormatException:For input string: "UserName" Such an exception, because the returned item is an array of object, $ ( Item.username) This access method is not used to access the array, otherwise, when processing the JSP engine will first convert the string userName to int to determine the array subscript, and at the time of conversion, the string "UserName" cannot be converted to an int exception.

So how do we get the value, should be a subscript to access the array, that is, item "0", item "1", so that the value of the channel is our user object in accordance with the defined order of the various property values.

Visible, the data type is very important, using different data types to save the value, then the value of the time to use the corresponding method to take the value, otherwise it will be reported abnormal.

Note on Jstl el usage (java.lang.NumberFormatException:For input string: "UserName")

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.