This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Soft Skills and have John Sonmez on-line!
See this thread for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes JSP action Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "JSP action" Watch "JSP action" New topic
Author

JSP action

Jayashree Mohan
Ranch Hand

Joined: Nov 23, 2005
Posts: 37
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?
Narendra Dhande
Ranch Hand

Joined: Dec 04, 2004
Posts: 950
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JSP action