This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Problem with the <c:out> that provides a default attribute Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Problem with the <c:out> that provides a default attribute" Watch "Problem with the <c:out> that provides a default attribute" New topic
Author

Problem with the <c:out> that provides a default attribute

Swagato Bhatta
Ranch Hand

Joined: Nov 08, 2008
Posts: 72
I am just trying to print a default value when the user does not input any values in the form (of page index.jsp).


In the Bert's book of 2nd edition, it states that

This value is output if the value attribute evaluates to null. And, the above should render as




Here is the jsp page that does the c : out testing with default.


Here is the index.jsp page


I do not get the default value printed when there is no input in the form. I expected the default guest value should get printed!


Working on my SCWCD so I can be a J2EE consultant earning millions of dollars and showing everyone I can
Frits Walraven
Creator of Enthuware JWS+ V6
Bartender

Joined: Apr 07, 2010
Posts: 1529
    
  22

Hi Swagato,

Because you are submitting a parameter with the name "name" it will handle it as an empty String, and therefore outputing an empty String instead of your default value. If you remove <input type="text" name="name"> from your jsp it should work as you had expected.

Regards,
Frits
Swagato Bhatta
Ranch Hand

Joined: Nov 08, 2008
Posts: 72
Frits Walraven wrote:Hi Swagato,

Because you are submitting a parameter with the name "name" it will handle it as an empty String, and therefore outputing an empty String instead of your default value. If you remove <input type="text" name="name"> from your jsp it should work as you had expected.

Regards,
Frits


So, not providing any data in the form basically means an "empty string". Whereas no input type means null? AM i right?
Swagato Bhatta
Ranch Hand

Joined: Nov 08, 2008
Posts: 72
Frits Walraven wrote:Hi Swagato,

Because you are submitting a parameter with the name "name" it will handle it as an empty String, and therefore outputing an empty String instead of your default value. If you remove <input type="text" name="name"> from your jsp it should work as you had expected.

Regards,
Frits


Thanks
 
 
subject: Problem with the <c:out> that provides a default attribute
 
Similar Threads
Object does not support property error!
JSP attendance management project error
<jsp:forward ...> not acting the way it should.
javascript error: object expected
Using JSTL Data Displayed In Browser Is Getting Fixed To 24576 Bytes(24 KB)