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

Get a context-param using PageContext

 
Hebert Taype
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everybody, i just started my preparation for taking the SCWCD exam, i have a doubt therefore i need some help

I have declared a context-param (declared in the Deployment Descriptor off-course) like this:
<web-app id="WebApp_ID" ...
><context-param>
<param-name>email</param-name>
<param-value>hebertway@gmail.com</param-value>
</context-param>
...
</web-app>


I was wonfering why it's not possible to get this parameter "email" using this sentence <%=pageContext.getAttribute("email",PageContext.APPLICATION_SCOPE)%> in a normal jsp page.

Thanks in advance
 
Lee Kian Giap
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

May I know whether have you set the context param to the Attribute of Context scope ?

If not, you can only use getInitParameter("email") method to retrieve value from DD.

For you to make the parameter in Attribute of Context scope, you might write the code to getInitParameter("email") and setAttribute("email", object ) inside the overriden no-arg init() method.

Hope the explanation help you to solve it !
 
Michael Rios
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Posting Error. Sorry.
 
Michael Rios
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

You should read about the difference of Attribute and Initialization Parameters.

Attributes:
1. It is an object.
2. It can be retrieved using getAttribute() of an object depending on the scope and which part of application you are going to access it.
3. Better read HF chapter about attributes theres a lot of rules regarding this matter.

InitParam
1. Application scoped initialization parameter can be accessed using <%=application.getInitParameter("email")%> replace your code with this one.
2. when using EL ${initParam.email} or ${initParam["email"]}
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic