• Post Reply Bookmark Topic Watch Topic
  • New Topic

jsp include file can't access bean from main file  RSS feed

 
Mike Ottinger
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I have an index.jsp file that includes a header.jsp file. At the top of the index.jsp I have a <jsp:usebean...> call to bring in a bean. I want this bean to obviously be available throughout the index.jsp file, but also available within the header.jsp file as well. Well, in tomcat, this isn't a problem, but in bea, I keep getting errors in the header file that the bean doesn't exist. I've tried everything I could think of, I tried and no luck. I also tried changing the scope in the usebean call to every other scope value. I also did <jsp:usebean calls in both the index and header files. This got rid of the error but it caused the app to throw a null pointer exception when I ran it. Has anybody had problems like this? It's frustrating that tomcat implements such a lax jsp specification and bea such a strict one. any ideas is greatly appreciated...

- Mike
 
Julian Kennedy
Ranch Hand
Posts: 823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As your header is dynamic the correct form of include to use here is <jsp:include page="header.jsp">. This action sends a request to header.jsp and then includes the generated content in its containing page. Bearing that in mind I don't see why it would know about your bean unless you explicitly declare it in header.jsp. (I could be wrong about that - if I were in your position I'd read the spec (Chapter SRV.14.2 of Servlet 2.4 and chapter JSP.1.10 of JSP 2.0 - I've not read it, btw ))

I would suggest that you proceed by trying to resolve your NullPointerException in Weblogic, as you seem to be on the right track.

Jules
 
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
When using <jsp:include>, the useBean action must appear in both files since each file is processed as a separate JSP (but ultimately producing a single response). Since <% include %> is a translation-time include, you do not repeat it.

How you got away with it under Tomcat is an interesting puzzle.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!