Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Error msg : 'pageContext' cannot be resolved in tag file  RSS feed

 
saikrishna vuddagiri
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I have my web application deployed on WebSphere Application server 6.0 ,which is running fine.Now my task is to move the web application to tomcat 5.5(also included JDK 1.4 compatibility package), as the code is compiled using jdk 1.4.In one of the tag files , i have used jsp implicit object 'pageContext' , which is giving error.

Code :

pageContext.get ServletContext();

Error in tomcat:

org.apache.jasper.JasperException: Unable to compile class for JSP:

An error occurred at line: 60 in the jsp file: /WEB-INF/tags/javascriptdeclarations.tag
pageContext cannot be resolved
57: <![endif]-->
58:
59: <!-- Scripts -->
60: <%= nextgen.webui.framework.aggregator.IncludeController.createJSDeclarations((HttpServletRequest)request,pageContext.getServletContext()) %>
61:


I have been searching for any suggestions in Google ,but remained clueless.Any help would be greatly appreciated.

Thanks in advance
Saikrishna Vuddagiri
 
saurav sarkar
Ranch Hand
Posts: 180
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not very sure but could you please check if servlet.jar is in your classpath
as PageContext comes from that jar.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
saurav sarkar wrote:I am not very sure but could you please check if servlet.jar

There is no need for this. The Servlet jar is automatically provided by Tomcat. It should never be copied anywhere.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are using tag files, that means that you are using JSP 2.0. Why are you putting antiquated scriptlets in a tag file?
 
James Garyson
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[edit: commentary removed]

Unfortunately "pageContext" is not available as an implicit variable in tag files. You *do* have access to "jspContext", which implements the parent class of PageContext, however I'm afraid this isn't an option for you in this situation, as getServletContext() is not available in jspContext. You might try instead to put this code in a JSP snippet that you pull into your JSP with a <jsp:include>
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
James Garyson wrote:Unfortunately "pageContext" is not available as an implicit variable in tag files.

pageContext is available within tag files within EL expressions.

JSP 2.0 mechanisms are meant to supplant scriptlets, not work with them. Mixing tags files and other JSP 2.0 mechanisms with scriptlets is bound to create difficulties.
 
James Garyson
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:
James Garyson wrote:Unfortunately "pageContext" is not available as an implicit variable in tag files.

pageContext is available within tag files within EL expressions.

JSP 2.0 mechanisms are meant to supplant scriptlets, not work with them. Mixing tags files and other JSP 2.0 mechanisms with scriptlets is bound to create difficulties.


I should have been more clear: pageContext is not available as an implicit variable in a scriptlet, which is where the author was was trying to use it.

Since you are so knowledgeable of EL expressions, please instruct the author on the correct way to achieve the results he is looking for.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using the pageContext in the EL is the correct way to be doing it. Hence my question to the user regarding why he was not using JSP 2.0 mechanisms -- which, unfortunately, was never answered.
 
Vince Soh
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I understand that this is an old post but just want to share my found.

From eclipse IDE, when using the content assist feature, it actually have "application" object which is in ServletContext type.

So, you might want to try out "application.getServletContext()" method.

Cheers
 
Evandro Canal
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I solved the problem as follows:



<c:forEach var="a" items="${att}">
<img alt="${a}" src="${a}" />
</c:forEach>
 
Abdul Qadeer Mohammed
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
pageContext is not readily available in tag file. However PageContext is available througj jspContext( casted from Jspcontext). I usd jspContext and am able to share data between scriptlet and jstl.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!