This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

doubt upon "useBean" standard action

 
koteswararao arvapalli
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Problem:
<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.

what is output for this problem and how?

Thanks & Regards,
KOTI.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you tried running this in an actual JSP page?
It's much easier and faster to run something like this than to post it to a forum and wait for an answer.

If after running it (or trying to), you have a more specific question about its output or the error messages that you encountered, come back and ask.
 
koteswararao arvapalli
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
if i run that problem i would get only answer, but my intention is to know how we got that answer means exact explanation by experts.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In this case, the answer you would get would be an exception.
By working through the exceptions, you would learn a lot about how this works and probably come up with much more specific question for the forum.

The useBean action has a lot of neat features and variations.
It would take a while for someone to explain the whole thing on a forum.
This, of course wouldn't be an efficient use of anyone's time because it's already been spelled out quite clearly in the JSP spec.

There is a link to the JSP spec in my signature.
I would start by reading the section on useBean.
 
koteswararao arvapalli
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I do not think it will throw exception.
please any one justify this. if it giving exception,can i get explanation upon it

Thanks & Regards,
koti.
 
koteswararao arvapalli
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
then output should give ""(blank). not exception... right
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If propertyName is set to * then the tag will iterate over the current ServletRequest parameters, matching parameter names and value type(s) to property names and setter method type(s), setting each matched property to the value of the matching parameter. If nothing matches, nothing happens.
 
Asif
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
write the exception here !!
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Asif",
Welcome to the ranch. You may not be aware of the ranch Naming Policy. Please read it carefully and change your name accordingly (you need to set both first and last names). Thank you.
 
Sandeep Vaid
Ranch Hand
Posts: 392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey java.lang.String doesn't contain any property called mystring.
The code will not run. It may throw Exception related to not a property!!!
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Read my post. property="*" is different from property="hello". It will not throw an exception.
 
Raghavan Muthu
Ranch Hand
Posts: 3381
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just to re-iterate, look at the OP's question.




Assume that the request for this page contains a parameter mystring=hello.


In that case, he has mistaken with the "mystring" here. The "mystring" in the "name" attribute of the <jsp:setProperty> does refer to the "id" property of the "useBean" tag and NOT the name of the request parameter.

Now, as others (Christopher) said, it will look for the matching properties and it will set if it finds any. Otherwise, it does not complain and rather sits idle!
[ March 31, 2008: Message edited by: Raghavan Muthu ]
 
Raghavan Muthu
Ranch Hand
Posts: 3381
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just to add one more info.

Let's assume you pass a request parameter as "YourPage.jsp?mystring=hello", it does not do anything as the corresponding class "java.lang.String" does NOT have any such matching property / variable of this name.

so, nothing happens again!

No exception as well.
[ March 31, 2008: Message edited by: Raghavan Muthu ]
 
Raghavan Muthu
Ranch Hand
Posts: 3381
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One more to add.

As what Ben said, it would indeed throw an exception when you try to use <jsp:getProperty> instead of <jsp:setProperty> as it would try to read a value from the specified property "mystring" in the class "java.lang.String".

The error message would obviously be



Hope it clears!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic