Regards, Sharmila.
We will have a future if we save Nature!
SCJP5.0, SCWCD5.0, OCEJPAD6, OCPJWSD6
Regards, Sharmila.
We will have a future if we save Nature!
Then how come result.java is not created if i do not add jsp:useBean into result.jsp. And browser
displays error as -
"General exception jsp:getProperty for bean with name 'person'. Name was not previously introduced as per JSP.5.3"
The <jsp:getProperty> action places the value of a bean instance property, converted
to a String, into the implicit out object, from which the value can be displayed
as output. The bean instance must be defined as indicated in the name attribute before this point in the page (usually via a jsp:useBean action).
Sharmila wroteThis works fine. And note that 'jsp:useBean' is declared after 'Header.jspf' is included. Also note that in the translated result_jsp.java file, 'person' variable is declared after included code of 'Header.jspf' .
SCJP5.0, SCWCD5.0, OCEJPAD6, OCPJWSD6
Regards, Sharmila.
We will have a future if we save Nature!
presents means, there is presents in 'result.jsp'.org.apache.jasper.runtime.JspRuntimeLibrary.introspecthelper(_jspx_page_context.findAttribute("person"), "name", "bugs bunny", null, null, false);
SCJP5.0, SCWCD5.0, OCEJPAD6, OCPJWSD6
Regards, Sharmila.
We will have a future if we save Nature!
Can we start new topic? This is become very big. And by mistake i have given you wrong translated .java file.
Please let me start new topic and i will put there all things you need upfront.
SCJP5.0, SCWCD5.0, OCEJPAD6, OCPJWSD6
So i think it says the bean 'person' need to introduce before included code is run.General exception jsp:getProperty for bean with name 'person'. Name was not previously introduced as per JSP.5.3
because it is added after include directive.General exception jsp:getProperty for bean with name 'person'. Name was not previously introduced as per JSP.5.3
Regards, Sharmila.
We will have a future if we save Nature!
Note that i have added jsp:useBean added after include directive. My question is how come translator knows that jsp:useBean is available. I was expecting
General exception jsp:getProperty for bean with name 'person'. Name was not previously introduced as per JSP.5.3
because it is added after include directive.
translates it into<jsp:useBean id="person" class="foo.Employee" scope="request"/>
and it checks is there 'person' attribute present in all scopes ordering from application, session, request, page scopes and if it finds gets the 'Employee' object, and cast it with 'foo.Employee' and calls the 'getName()' on it. Here there is no 'person' attribute available. So it returns 'null'. Calling on 'null' produces 'NullPointerException'. Since our 'person' attribute was set into 'request' by our jsp:useBean after 'jsp:getProperty', here 'person' attribute was not available.out.write(org.apache.jasper.runtime.JspRuntimeLibrary.toString((((foo.Employee)_jspx_page_context.findAttribute("person")).getName())));
SCJP5.0, SCWCD5.0, OCEJPAD6, OCPJWSD6
We can use jsp:getProperty without using jsp:useBean. All we have is set the specified attribute in any one of the scopes(application, session, request, page).
Regards, Sharmila.
We will have a future if we save Nature!
The value of the name attribute in jsp:setProperty and jsp:getProperty will refer to an object that is obtained from the pageContext object through its findAttribute method.
The object named by the name must have been “introduced” to the JSP processor using either the jsp:useBean action or a custom action with an associated VariableInfo entry for this name. If the object was not introduced in this manner, the container implementation is recommended (but not required) to raise a translation error, since the page implementation is in violation of the specification.
Note – A consequence of the previous paragraph is that objects that are stored in, say, the session by a front component are not automatically visible to jsp:setProperty and jsp:getProperty actions in that page unless a jsp:useBean action, or some other action, makes them visible.
SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Regards, Sharmila.
We will have a future if we save Nature!
Chinmaya Chowdary wrote:
We can use jsp:getProperty without using jsp:useBean. All we have is set the specified attribute in any one of the scopes(application, session, request, page).
SCJP 6.0 (88%)
SCJP5.0, SCWCD5.0, OCEJPAD6, OCPJWSD6
SCJP 6.0 (88%)
Don't get me started about those stupid light bulbs. |