wood burning stoves 2.0*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes HFSJ pg 445 c:set Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "HFSJ pg 445 c:set" Watch "HFSJ pg 445 c:set" New topic
Author

HFSJ pg 445 c:set

Mukunthan Shanmuganathan
Ranch Hand

Joined: Jul 24, 2007
Posts: 32
Hi Gentlemen!

In order to check the <c:set var...> I wrote like as follows,

Servlet



JSP



I do believe that I should get:

"The Name is: Thiri"

But I get:

"The name is: Cowboy" !!!

Why?

Thank You!


Dare to know!
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16


First, you are setting a session attribute called userLevel in your servlet. Then, you are forwarding to a JSP. In this JSP, you are overwriting the session attribute userLevel, by setting its value to "Cowboy". What did you expect it to be "Thiri" if you overwrite it with "Cowboy" ?


[My Blog]
All roads lead to JavaRanch
Mukunthan Shanmuganathan
Ranch Hand

Joined: Jul 24, 2007
Posts: 32
Dear Christophe Verre!

Thank you, But, the same result comes when I use with body! i.e.

servlet as the same but the JSP as follows



Why?

Dose it mean that <c:set> with body won't act as conditional! as like <jsp:setProperty> ?


Thank you!

:roll:
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Both syntax above should give the same result. What do you mean by "the same result comes when I use with body!" ?
Mukunthan Shanmuganathan
Ranch Hand

Joined: Jul 24, 2007
Posts: 32
Dear Christophe Verre!

What I meant by saying "same result" was,

The session scope attribute "userLevel" set by the <c:set...> in the JSP was displayed!

Where as the HFSJ says that "If there's NOT a session-scoped attribute named "userLevel", this tag creates one ..."

If so, If there IS a session-scoped attribute named "userLevel" !

What will happen?

Won't skip the <c:set> like we studied with <jsp:setProperty> ?

:roll:

Thank you.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

What will happen?

It will overwrite the previous value. There is no notion of "do it or not" with the c:set tag.
Mukunthan Shanmuganathan
Ranch Hand

Joined: Jul 24, 2007
Posts: 32
Hi Christophe Verre!



Thank You!

 
It is sorta covered in the JavaRanch Style Guide.
 
subject: HFSJ pg 445 c:set
 
Similar Threads
InitialContext Lookup returns the same Stateful Session Bean Reference everytime ...
Servlet problems on Orion
how to invoke applet from servlet
Problem regarding to Cookies with EL, HFSJ pg 386
jsp:useBean