This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
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


Win a copy of Java 8 in Action this week in the Java 8 forum!
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
Author

Can we use getServletConfig is JSP as we use in Servlet

Nikhil Jain
Ranch Hand

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

I am trying to get the certain values from DD.

The follow is what I specified in DD
<servlet>
<servlet-name>Basic</servlet-name>
<jsp-file>/Basic.jsp</jsp-file>
<init-param>
<param-name>mail</param-name>
<param-value>stilwalli@yahoo.com</param-value>
</init-param>
</servlet>

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
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60080
    
  65

"Shashank",

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.

Thanks!
bear
JavaRanch Sheriff


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

Joined: Apr 04, 2006
Posts: 212
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: http://aspose.com/file-tools
 
subject: Can we use getServletConfig is JSP as we use in Servlet
 
Similar Threads
get init parameter
Why this code to get Init Param in JSP not work?
init parameter from jsp
how to get init-param in jsp
access the servlet init config parameters using jspInit()