Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

About pageContext.setAttribute problem  RSS feed

 
lyo Yashnoo
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone:
I have seen the struts-exercise-taglib example and it puzzle me.In html-link.jsp there is the code:
///////////////////////////////////////////////////////////////////////////////
String newValue = "New string lyo value";
pageContext.setAttribute("newValue", newValue); //
java.util.HashMap newValues = new java.util.HashMap();
newValues.put("floatProperty", new Float(444.0));
newValues.put("intProperty", new Integer(555));
newValues.put("stringArray", new String[]
{ "Value 5", "Value 2", "Value 3" });
pageContext.setAttribute("newValues", newValues);
////////////////////////End code////////////////////////////////////////////
Why it use the method "pageContext.setAttribut" twice?I think the code should like this:

java.util.HashMap newValues = new java.util.HashMap();
newValues.put("floatProperty", new Float(444.0));
newValues.put("intProperty", new Integer(555));
newValues.put("stringArray", new String[]
{ "Value 5", "Value 2", "Value 3" });
pageContext.setAttribute("newValues", newValues);
////////////////////////////////////////////////////////////////////////////
I means that the code "String newValue = "New string lyo value" is uselessful.Right?
It is set the pageContext's Attribute one time only.Why does write in that way? :roll:
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
NewValues and newValue are different attribute keys.
bear
 
lyo Yashnoo
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you
Can I delete the code "String newValue = "New string lyo value";
pageContext.setAttribute("newValue", newValue); "? I can put the "float,Integer,String" variable to the HashMap directly and use the method "pageContext.setAttribute" later.Is it any useness to use "pageContext.setAttrubute" before I put variable to the HashMap? :roll:
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!