Originally posted by Jayashree Mohan:
Which of the given statements are correct regarding the following JSP page code?
<jsp:useBean id="mystring" class="java.lang.String" />
<jsp:setProperty name="mystring" property="*" />
<%=mystring%>
Assume that the request for this page contains a parameter mystring=hello.
In the jdiscuss exam, the answer is 'It will print "" '.
How is this possible?
The answer is right. The useBean will create the bean mystring. As the
String have a no-arg public constructor, there is no problem with this statement. The mystring will point to empty string.
The setProperty is using property="*" to set the properties of mystring. It will not found any property from the request parameters to set in the string object. So, it will not set anything in the mystring string object.
The third expression will print the string to the browser. The String mystring have value "" (Empty string) as it is created as new String(). So it will pring nothing.
Hope it help you.
Thanks
Narendra Dhande
SCJP 1.4,SCWCD 1.4, SCBCD 5.0, SCDJWS 5.0, SCEA 5.0