• Post Reply Bookmark Topic Watch Topic
  • New Topic

Cannot retrieve init parameter through JSP file  RSS feed

 
sudipto shekhar
Ranch Hand
Posts: 826
Chrome Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
  • 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 ]
 
Marimuthu Madasamy
Ranch Hand
Posts: 72
Java Monad Scala
  • Mark post as helpful
  • send pies
  • 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
Chrome Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
  • 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 ]
 
Bosun Bello
Ranch Hand
Posts: 1511
  • Mark post as helpful
  • send pies
  • 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
Chrome Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
  • 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 ]
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!