Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The function must be used with a prefix when a default namespace is not specified

Tags:

jstl

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

like image 569
ashlesha Avatar asked Feb 06 '13 21:02

ashlesha


1 Answers

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);
like image 171
JB Nizet Avatar answered Oct 21 '22 09:10

JB Nizet