File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes Can we use getServletConfig is JSP as we use in Servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Can we use getServletConfig is JSP as we use in Servlet" Watch "Can we use getServletConfig is JSP as we use in Servlet" New topic

Can we use getServletConfig is JSP as we use in Servlet

Nikhil Jain
Ranch Hand

Joined: May 15, 2005
Posts: 389
Hello Ranchers,

I am trying to get the certain values from DD.

The follow is what I specified in DD

now I give the following code in my JSP

<%= config.getAttribute("mail") %> (Config is the implict object which is set to getServletConfig()

But everytime it print out null
any suggessions?

SCJP 1.4, SCWCD 1.4, SCBCD 1.5, TOGAF 9, Comptia Cloud+
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63852


There aren't many rules that you need to worry about here on the Ranch, but one that we take very seriously regards the use of proper names. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

JavaRanch Sheriff

[Asking smart questions] [About Bear] [Books by Bear]
Yogendra Joshi
Ranch Hand

Joined: Apr 04, 2006
Posts: 213
Shashank ,

As Bear pointed out change your name in accordance to the Ranch's Naming Policy.

Secondly , There is something wrong which you've been doin ! First of all , its not <%= config.getAttribute("mail") %> , It should be <%=config.getInitParameter("mail")%> another thing i would like to point out just FYI. For successfully getting the parameters , You need to access the servlet and not the JSP i.e not Basic.jsp , If you access http://localhost:8080/yourwebappname/servlet/Basic , You would get the value of mail param.

You would not get correct output if you are using Basic.jsp , because the JSP
engine creates two different instances of the generated servlet class , one for accessing
it as a named servlet and one for accessing it as a JSP page and will pass each servlet
instance a different ServletConfig object. In order to be able to use the same servlet
instance and hence the same configuration when using either of the URLs mentioned, we have to explicitly map the JSP page�s URL in the deployment
descriptor file using the <servlet-mapping> element like this :

Hope this helps you..

Yogendra Joshi.

Meri Zindagi Hain Tab Tak.. Jab Tak Tera Sahara.... Har Taraf Tu Hi Tu Hain SAI Tera Hi Hain Nazara.....
I agree. Here's the link:
subject: Can we use getServletConfig is JSP as we use in Servlet
It's not a secret anymore!