File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSP action

 
Jayashree Mohan
Ranch Hand
Posts: 37
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 951
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic