Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubts

 
NDP Prasad
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1.what is the difference between the pageContext.APPLICATION AND application.

2.where do we use pageContext.APPLICATION and pageContext.APPLICATION_SCOPE?
why there is no SetAttribute,getAttribute ..etc in pageContext.APPLICATION ?
 
Rancy Chadha
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Prasad,
I am attempting to answer your question here and this is how it goes:
1.what is the difference between the pageContext.APPLICATION AND application.

The difference is: APPLICATION is acutally a field of PageContext class and it is the name used to store ServletContext in PageContext name table and application is the jsp implicit object of class javax.servlet.ServletContext. You can consider APPLICATION as an attribute whose value is ServletContext object and application is the implicit object it is obtained from getServletContext() of PageContext.

2.where do we use pageContext.APPLICATION and pageContext.APPLICATION_SCOPE? why there is no SetAttribute,getAttribute ..etc in pageContext.APPLICATION ?

pageContext.APPLICATION can be used in places where you want to retrieve the servlet context and how it can be used? In this way: pageContext.getAttribute(PageContext.APPLICATION). PageContext.APPLICATION_SCOPE is the field which has an integer assigned to it and it is mostly used when PageContext object is used to retrieve attributes in all the scopes. For e.g. if I want to retrieve attribute 'name' defined in session scope using pagecontext, I would do it this way: pageContext.getAttribute("name", PageContext.SESSION_SCOPE);

I hope now it is clear to you what pageContext.APPLICATION, pageContext.APPLICATION_SCOPE and application means and where they are used.
 
NDP Prasad
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Ranchy.

Iam confused about using it inside EL and the customtag class. Now iam clear abt the customtag class.

The pageContext.getAttribute is present in the customtag class but not in the EL.
PageContext in the customtag class
and pageContext in the EL(small p).

Now, I want to get the username coming form the a.jsp, which i included in the b.jsp class.
How can i access request parameter apart from
${param.username}.(from b.jsp)
Iam getting [Ljava.lang.String;@1c9ce70 when i use following EL
${pageContext.request.parameterMap.username}

I want equivalent of <%=request.getParameter("company")%> in EL through request?
 
NDP Prasad
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Ranchy.

Iam confused about using it inside EL and the customtag class. Now iam clear abt the customtag class.

The pageContext.getAttribute is present in the customtag class but not in the EL.
PageContext in the customtag class
and pageContext in the EL(small p).

Now, I want to get the username coming form the a.jsp, which i included in the b.jsp class.
How can i access request parameter apart from
${param.username}.(from b.jsp)
Iam getting [Ljava.lang.String;@1c9ce70 when i use following EL
${pageContext.request.parameterMap.username}

I want equivalent of <%=request.getParameter("username")%> in EL through request?

sorry correction not company username
 
Rancy Chadha
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Prasad,
I want to get the username coming form the a.jsp, which i included in the b.jsp class.

I want to see code of your both the jsps a.jsp and b.jsp. Can you paste the code here, so it will be easier for me to find the resolution.
 
Hendy Setyo Mulyo
Ranch Hand
Posts: 219
Firefox Browser Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Rancy Chadha:
Hi Prasad,
I am attempting to answer your question here and this is how it goes:

pageContext.APPLICATION can be used in places where you want to retrieve the servlet context and how it can be used? In this way: pageContext.getAttribute(PageContext.APPLICATION). PageContext.APPLICATION_SCOPE is the field which has an integer assigned to it and it is mostly used when PageContext object is used to retrieve attributes in all the scopes. For e.g. if I want to retrieve attribute 'name' defined in session scope using pagecontext, I would do it this way: pageContext.getAttribute("name", PageContext.SESSION_SCOPE);

I hope now it is clear to you what pageContext.APPLICATION, pageContext.APPLICATION_SCOPE and application means and where they are used.


Hi Rancy,

So does it mean like this?
ServletContext servletContext = ( ServletContext ) pageContext.getAttribute(PageContext.APPLICATION);
 
Rancy Chadha
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes Hendy you are right.
 
NDP Prasad
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
a.jsp



b.jsp


Thank you.
 
NDP Prasad
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please explain me detail about the use of

pageContext.request
pageContext.requestScope
parameterMap

Correction from the above:
Not the combination of request and requestScope, rather use of requestScope when compare with the request.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A hint :
getParameterMap()
Returns:
an immutable java.util.Map containing parameter names as keys and parameter values as map values. The keys in the parameter map are of type String. The values in the parameter map are of type String array.


How can i access request parameter apart from ${param.username

May I ask why ?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
pageContext.requestScope

No such thing. Look at the PageContext class API for all details.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic