Below is the code I wrote in body
<% List<UserInfo> userInfoList = new ArrayList<UserInfo>();
UserInfo userInfo = new UserInfo();
userInfoList = new CRUDOps().retrieveUserDataList();
pageContext.setAttribute("userInfoList", userInfoList);%>
Below is the code I wrote in div
<c:forEach var="userInfo" items="${userInfoList}">
<input type="radio" name="buyer" value="hhhh">${userInfo.get(0).getFirstName()}/><br />
<c:forEach>
Above code , have to display first and last name from UserInfo table ... UserInfoList contains UserInfo object and UserInfo has first and last names. So, using userInfoList with index value as "0" calling the getFirstName defined in POJO.
The error that I am getting is
org.apache.jasper.JasperException: /requestorGroup.jsp(63,59) The function get must be used with a prefix when a default namespace is not specified
If UserInfo
has a first name and a last name, and userInfo
is of type UserInfo
, calling get(0)
on it makes no sense: it's not a list, and it doesn't have any first element. It has a first name and a last name.
You simply need
<c:forEach var="userInfo" items="${userInfoList}">
<input type="radio" name="buyer" value="hhhh">${userInfo.firstName}/><br />
<c:forEach>
The JSP expression language (EL) accesses properties via getters. So you shouldn't use the getter, but simply the name of the property: firstName
.
You should also avoid scriptlets in JSP, and put the code which gets data from the database into a servlet instead. Moreover, two out of the 4 lines are completely unnecessary. The code should be reduced to:
List<UserInfo> userInfoList = new CRUDOps().retrieveUserDataList();
pageContext.setAttribute("userInfoList", userInfoList);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With