Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

code

 
Dilshan Edirisuriya
Ranch Hand
Posts: 299
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Problem

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.


Options

Select 1 correct option.

1. It will print "".


2. It will print "hello"


3. It will not compile.


4. It will throw exception at runtime.

The answer is 1 can some one tell me why is that?
 
Dinuka Arsakularatne
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i think that because setProperty is not given inside the <jsp:useBean></jsp:useBean> tags, it basically creates a new property named myString and assigns it an empty string.

Dinuka Arseculeratne
 
Dilshan Edirisuriya
Ranch Hand
Posts: 299
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In HFSJ(page 349) it says that "if the bean is already existed,my jsp will reset the existing bean's property value"
So it has to be "hello"
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This code searches for a attribute named mystring in page scope. It wont find it (because mystring came as a parameter). So it creates a new String class under page scope. The set property standard action then tries to set all the properties of the String class from the available params. Thus the option 1 would have to be the answer.
 
Dilshan Edirisuriya
Ranch Hand
Posts: 299
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you John I got it
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic