This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can we use getServletConfig is JSP as we use in Servlet

Nikhil Jain
Ranch Hand
Posts: 389
  • Mark post as helpful
  • send pies
  • 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

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?
Bear Bibeault
Author and ninkuma
Posts: 65225
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Yogendra Joshi
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
  • 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.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic