In JSP/JSTL, how can I set values for a usebean of class=”java.util.ArrayList”.
If I try using c:set property or value, I get the following error:
javax.servlet.jsp.JspTagException: Invalid property in : “null”
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
That isn’t directly possible. There are the
<c:set>and<jsp:setProperty>tags which allows you to set properties in a fullworthy javabean through a setter method. However, theListinterface doesn’t have a setter, just anadd()method.A workaround would be to wrap the list in a real javabean like so:
and set it by
But that makes little sense. How to solve it rightly depends on the sole functional requirement. If you want to preserve some
Listupon a GET request, then you should be using a preprocessing servlet. Create a servlet which does the following indoGet()method:When you invoke the servlet by its URL, then the list is in the forwarded JSP available by
without the need for old fashioned
<jsp:useBean>tags. In a servlet you’ve all freedom to write Java code the usual way. This way you can use JSP for pure presentation only without the need to gobble/hack some preprocessing logic by<jsp:useBean>tags.See also: