• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • 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: 1512
  • 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 ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic