Forums Register Login

Get a context-param using PageContext

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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 !
+Pie Number of slices to send: Send

Posting Error. Sorry.
+Pie Number of slices to send: Send

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"]}
Water! People swim in water! Even tiny ads swim in water:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 625 times.
Similar Threads
Scriptless JSP and config param
Doubt in ServletContextListener
I hava some question about servlet
Access application context using EL
Modifying JSP pages
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 19:36:43.