I am currently creating a web application use java servlets and jspx pages. I have created a java class with a parameter when called with the class being LessonSelection(int owner). I know that you cannot use a bean with a parameter so I made an object of that class with the parameter and then added it to the session, then used that session attribute in the useBean.
I have an error coming up saying 'The value of the useBean class attribute ${selected} is invalid'
The useBean code is below.
<jsp:useBean class="${selected}" id="timetable" scope="session"/>
The java code is below.
HttpSession session = request.getSession(true);
session.setAttribute("username", user);
session.setAttribute("id", id);
selected = new LessonSelection(id);
session.setAttribute("selected", selected);
dispatcher = this.getServletContext().getRequestDispatcher("/LessonTimetableView.jspx");
If you need any more of the code that I wrote, just ask thanks.
EDIT 1:
I thought I would check whether it is actually added to the session attribute and it is added. It is printed as 'model.LessonSelection@1457de3'. It still shows the same error.
The
class
atjsp:useBean
must be the package + class of your attribute! Suppose yourLessonSelection
is located in the packagecom.test
. The code would be as follow:Edit 1
Try this:
It seens that using type, the JSP wont instantiate it for your, it'll just look from the bean of the given type in the given scope. See it here.