Author Topic: JSP help  (Read 1256 times)

ober

  • Ashton Shagger
  • Ass Wipe
  • Posts: 14305
  • Karma: +73/-790
  • mini-ober is taking over
    • Windy Hill Web Solutions
JSP help
« on: February 28, 2011, 02:54:32 PM »
So I'm used to PHP and here's what I don't get: if I include one JSP inside of another one, why wouldn't I have access to the same objects inside the included JSP?  Example:

Code: [Select]
<% if(report.getWriterConfiguration().contains("Gauge")) { %>
    <jsp:include page="writer/outGauge.jsp" />
    <%
    }   
    else {

But if I try to do anything with the report object in outGauge.jsp, it says it can't resolve 'report'.  WTF?

Perspective

  • badfish
  • Jackass In Charge
  • Posts: 4635
  • Karma: +64/-22
    • http://jeff.bagu.org
Re: JSP help
« Reply #1 on: February 28, 2011, 03:09:15 PM »
Quote
The include directive, <%@ include file="filename.inc" %>, includes the content of the specified file during the translation phase--when the page is converted to a servlet. The main page and the included file are simply merged. This means that scripting variables declared in one file (using scripting elements or an action element like <jsp:useBean>) are visible in all files and must have unique names. Some containers detect changes in files included with the directive, but the specification doesn't require it. Therefore, changes you make to the included file in a running system may not be reflected immediately; you may have to update the main JSP page, or remove the class file generated for the main page in order to see the change.

The include action, <jsp:include page="pagename.jsp" flush="true" />, includes the response generated by executing the specified page (a JSP page or a servlet) during the request processing phase--when the page is requested by a user. As opposed to the include directive, the page name can be specified as a so-called request-time attribute value, so which page to include can be decided when the main page is requested. Since it's the response generated by the page that is included, not the content of the page itself, scripting variables declared in one file are not available to the other files. To share an object between the pages you must instead place it in one of the following JSP scopes: request, session or application scope. If you change a page included with the include action, the change always takes effect immediately.

stolen from http://www.oreillynet.com/pub/a/oreilly/java/news/jsptips_1100.html

ober

  • Ashton Shagger
  • Ass Wipe
  • Posts: 14305
  • Karma: +73/-790
  • mini-ober is taking over
    • Windy Hill Web Solutions
Re: JSP help
« Reply #2 on: February 28, 2011, 03:15:22 PM »
Thanks.  Yeah, I found that about a minute ago.  I was just including it using the wrong method.  I hate Java.  Too many ways to fuck up.

hans

  • Guitar Addict
  • Jackass In Charge
  • Posts: 3523
  • Karma: +46/-18
Re: JSP help
« Reply #3 on: February 28, 2011, 04:49:10 PM »
Whatcha doing with Java Ober? I agree JSPs aren't much fun, but Grails makes Java life wonderful.
« Last Edit: February 28, 2011, 05:48:30 PM by tgm »
This signature intentionally left blank.

ober

  • Ashton Shagger
  • Ass Wipe
  • Posts: 14305
  • Karma: +73/-790
  • mini-ober is taking over
    • Windy Hill Web Solutions
Re: JSP help
« Reply #4 on: February 28, 2011, 04:54:43 PM »
I've moved fully into R&D where I work.  My first task task for our next maintenance release is to enhance our core platform reporting engine with Google's Visualization API outputs.

We don't use Grails here (yet).  It was developed back in the late 90's.  We release new features but some of the core needs to be rewritten with an actual framework.  I think there is a good object structure but then again I haven't done Java since college so I'm still re-learning.