Error in jsp when i use bean , can any one help?
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;开发者_高级运维
}
}
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).
精彩评论