• 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

Cannot retrieve init parameter through JSP file

 
Ranch Hand
Posts: 826
Eclipse IDE Oracle Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

Again i face a problem and have tried out all possibilities to solve this....

my web.xml file is as follows:


The JSP code through which I am trying to retrive the init parameter is:


This JSP file is named as TestJsp.jsp.

The servlet TestServlet retrieves the value from the DD and displays it well.
But when I try to retrive the value from the JSP i am not able to and get a null value.
Where am i wrong?
Is it the web.xml file where i am mistaken?
Please help.
[ November 12, 2008: Message edited by: Sudipto Shekhar ]
 
Ranch Hand
Posts: 72
Scala Monad Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If the request passes through that servlet (TestServlet), the servlet init parameters will be accessible through ServletConfig.

So for this http://localhost:8080/webappName/TestServlet, the init parameters will be available.

for http://localhost:8080/webappName/TestJsp.jsp, the init parameters will not be available. If you still want those init parameters with this URL, change the servlet-mapping url-pattern element in web.xml to 'TestJsp.jsp'.
[ November 13, 2008: Message edited by: Marimuthu Madasamy ]
 
sudipto shekhar
Ranch Hand
Posts: 826
Eclipse IDE Oracle Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok i understood that.It worked.
I have one more similar doubt.
I have two JSP files, where in one i set the page scoped attribute and in the second I try to retrieve the value.
The code are as follows:

index.jsp


The other jsp file TestAtt.jsp is as follows:


It prints null when i retrieve the value of the attribute.
Where am I wrong?
Please help.
[ November 13, 2008: Message edited by: Sudipto Shekhar ]
 
Ranch Hand
Posts: 1514
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your attribute is set on the page scope. And not available to the other jsp. You need to set it on session scope or request scope. In the case of the latter, you will need to forward it to the other jsp via requestDispatcher.
 
sudipto shekhar
Ranch Hand
Posts: 826
Eclipse IDE Oracle Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok so page scope is for the particular page.
In RequestDispatcher as far as i know the forwarded page is given the request and the response object,right? So from my JSP index.jsp, suppose, i forward the request and response object to another page , say TestAtt.jsp. So how will the forwarded page will get the pageContext attribute?
And also we can use the pageContext to set and get the session-scoped or application scope or request scope attributes.how does those work?
When pageContext is for the same page only then how does this work:


Please help...

Any links too would be very helpful.


[ November 13, 2008: Message edited by: Sudipto Shekhar ]
[ November 14, 2008: Message edited by: Sudipto Shekhar ]
 
Sunglasses. AKA Coolness prosthetic. This tiny ad doesn't need shades:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic