• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Can we use getServletConfig is JSP as we use in Servlet

 
Ranch Hand
Posts: 393
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"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
 
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Thank you my well lotioned goddess! Here, have my favorite tiny ad!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic