tags:

views:

20

answers:

1

I want to use bean in my jsp page but run time occure and i can't resolve.

Error:
An error occurred at line: 28 in the jsp file: /WEB-INF/AdminPages/AddUser.jsp
listOfGroupNo cannot be resolved
25: %>
26: <%! void addGroup(int no) {
27:    
28:     listOfGroupNo.getGroupList().add(no);
29:     }
30: 
31: %>

is that error means the object is not defined? Here is the decleration and initialization of bean in my jsp

<jsp:useBean id="listOfGroupNo" class="iug.edu.entities.GroupsNoList" scope="request">
  <jsp:setProperty name="listOfGroupNo" property="groupList"  />
</jsp:useBean>

and here is my bean

public class GroupsNoList {
    private List groupList= new ArrayList();

    public List getGroupList() {
        return groupList;
    }

    public void setGroupList(List groupList) {
        this.groupList = groupList;
    }
}
+1  A: 

You have declared listOfGroupNo to have request scope, so you have to retrieve it through the request object:

request.getAttribute("listOfGroupNo")

Have a look at the specifications for jsp:useBean:

You can use the Bean from any JSP page processing the same request, until a JSP page sends a response to the client or forwards the request to another file. You can use the request object to access the Bean, for example, request.getAttribute(beanInstanceName).

casablanca
i want to fill the bean with data from the form then send it to seervlet, i think the scope here isn't correct , and is it correct to send bean as aparameter like this:<%request.setAttribute("listOfGroupBean", listOfGroupNo);%>
Alaa