I want yo create a java bean in servlet and set its properties there.
I want to access this bean in a jsp.
Is this possible?
I tried the following :
Wrote a java bean.
Created its instance in the servlet and set its properties.
Next I put the bean tags in the jsp to access the attribute values:
When the jsp executes it get the following error message:
org.apache.jasper.JasperException: /delbookchoose2.jsp(47,0) UseBean: Mandatory attribute id missing
Is it possible to set the attribute for the bean BookSelectedforDel in the servlet?
The class attribute must match the bean classname -- I have no idea what that is that you put there. And you need an id attribute that matches the scoped variable name.
The code in the jsp to which I am forwarding the request:
I have put the bean class file in the classes folder of my application "onlinelib".
Now I get the following error when the jsp execute:
org.apache.jasper.JasperException: /delbookchoose2.jsp(48,0) GetProperty: Mandatory attribute name missing
Also, I am using Tomcat 5.0.28
The exact location of my bean class is:
Tomcat 5.0\webapps\onlinelib\WEB-INF\classes
Hi David,
You are right. I have not specified the name attribute.
I am confused here.
When you create a java bean in a jsp it has a name attribute in jsp:usebean tag.
But I have create this one in a servlet. So how do I set the name attribute here?
Well I tried to give a name attribute in the jsp:
Then I got the error:
rg.apache.jasper.JasperException: /delbookchoose2.jsp(47,0) UseBean has invalid attribute: name
So looks like it expects the name attirbute to be set when the java bean is created in the servlet.
How do I set this name attribute in the servlet?
name attribute is in the <jsp:getProperty name="nameOfTheBean" property="nameOfTheProperty" value="valueForThatProperty"/>. Please check the JSp Specification for further details.
|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
This is what I have now in my jsp which is trying to access the bean created in the servlet:
As mentioned earlier the bean class is in the WEB-INF\classes folder of my application [onlinelib].
I now get the following error on the jsp:
org.apache.jasper.JasperException: /delbookchoose2.jsp(47,0) The value for the useBean class attribute BookSelectedforDel is invalid.
So, in which scope, did you bind the attribute? Default scope for this standard action is page, which you can't set from a servlet. So have a look on that!
Now I get the following error message:
org.apache.jasper.JasperException: Cannot find any information on property 'author' in a bean of type 'BookSelectedforDel'
Is it again creating a new bean here and hence the error above?
I have made all bean getter and setter methods public now.
Now getting great amount of errors:
org.apache.jasper.JasperException: Unable to compile class for JSP An error occurred at line: 49 in the jsp file: /delbookchoose2.jsp Generated servlet error: D:\Apache Software Foundation\Tomcat 5.0\work\Catalina\localhost\onlinelib\org\apache\jsp\delbookchoose2_jsp.java:99: cannot find symbol symbol : class BookSelectedforDel location: class org.apache.jsp.delbookchoose2_jsp BookSelectedforDel bkinfobean = null; ^ An error occurred at line: 49 in the jsp file: /delbookchoose2.jsp Generated servlet error: D:\Apache Software Foundation\Tomcat 5.0\work\Catalina\localhost\onlinelib\org\apache\jsp\delbookchoose2_jsp.java:101: cannot find symbol symbol : class BookSelectedforDel location: class org.apache.jsp.delbookchoose2_jsp bkinfobean = (BookSelectedforDel) _jspx_page_context.getAttribute("bkinfobean", PageContext.REQUEST_SCOPE); ^ An error occurred at line: 49 in the jsp file: /delbookchoose2.jsp Generated servlet error: D:\Apache Software Foundation\Tomcat 5.0\work\Catalina\localhost\onlinelib\org\apache\jsp\delbookchoose2_jsp.java:103: cannot find symbol symbol : class BookSelectedforDel location: class org.apache.jsp.delbookchoose2_jsp bkinfobean = new BookSelectedforDel(); ^ An error occurred at line: 50 in the jsp file: /delbookchoose2.jsp Generated servlet error: D:\Apache Software Foundation\Tomcat 5.0\work\Catalina\localhost\onlinelib\org\apache\jsp\delbookchoose2_jsp.java:109: cannot find symbol symbol : class BookSelectedforDel location: class org.apache.jsp.delbookchoose2_jsp out.write(org.apache.jasper.runtime.JspRuntimeLibrary.toString((((BookSelectedforDel)_jspx_page_context.findAttribute("bkinfobean")).getAuthor()))); ^ An error occurred at line: 51 in the jsp file: /delbookchoose2.jsp Generated servlet error: D:\Apache Software Foundation\Tomcat 5.0\work\Catalina\localhost\onlinelib\org\apache\jsp\delbookchoose2_jsp.java:112: cannot find symbol symbol : class BookSelectedforDel location: class org.apache.jsp.delbookchoose2_jsp out.write(org.apache.jasper.runtime.JspRuntimeLibrary.toString((((BookSelectedforDel)_jspx_page_context.findAttribute("bkinfobean")).getBookname()))); ^ An error occurred at line: 52 in the jsp file: /delbookchoose2.jsp Generated servlet error: D:\Apache Software Foundation\Tomcat 5.0\work\Catalina\localhost\onlinelib\org\apache\jsp\delbookchoose2_jsp.java:115: cannot find symbol symbol : class BookSelectedforDel location: class org.apache.jsp.delbookchoose2_jsp out.write(org.apache.jasper.runtime.JspRuntimeLibrary.toString((((BookSelectedforDel)_jspx_page_context.findAttribute("bkinfobean")).getCopies()))); ^ 6 errors
Have you read through the entries in the JSP FAQ? If so, you'd discover that all classes used in web applications must be in a package other than the default.