File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes IDEs, Version Control and other tools and the fly likes A page knowledge of its include Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » IDEs, Version Control and other tools
Bookmark "A page knowledge of its include" Watch "A page knowledge of its include" New topic
Author

A page knowledge of its include

Sverre Moe
Ranch Hand

Joined: Jul 10, 2007
Posts: 110
Can I page that has been included obtain a knowledge that it has been included in some page? Perhaps by sending it a value when it is being included

My front page is a simple service selector form with a drop down menu list.

When a user selects something from that list a new form is displayed, but I also want to show the drop down menu list. Here comes the problem.

When I include the service selector I end up with a file with two sets of <html><body></body></html> tags.

I need a way for the service selector to only be a fragment if included or a complete web page when not.

Is there a way I could do this without maintaining two sets of file with much of the same content?
Sverre Moe
Ranch Hand

Joined: Jul 10, 2007
Posts: 110
I have tried a workaround. Created a index.jsp which will be the start page. This includes the service selector. The service selector is now a jsp fragment.

However. I need to use a variable in the fragmented file which exists in the page that included it.

Using
<jsp:include flush="true" page="service.jspf">
<jsp:param name="myVariable" value="<%=myVariable%>"></jsp:param>
</jsp:include>
Does not work. I get an error message that "response is already committed"

Far as I know <%@ include file=""%> can't pass variables this way.

The strange thing is if I change my fragment file from jspf to jsp the <jsp:include.. works..
[ July 16, 2007: Message edited by: Sverre Moe ]
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

We have a FAQ entry on the difference between the static "<%@ include.." directive and the runtime "<jsp:include.." action.
You can read it here.

Hopefully this will clear things up for you.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Sverre Moe
Ranch Hand

Joined: Jul 10, 2007
Posts: 110
Most of it I already knew.

Though it does not say why <jsp:include ...> with a page.jsp worked, but not with a page.jspf, even though the jspf and the jsp file was the same. Maybe it was written between the lines.

From any source I have read it seems like the directive is the way to go when you are adding fragments. Though the following:

Scriptlet variables declared in the parent page can be accessed in the included page

I have a problem with this. I receive a "cannot be resolved" in eclipse when I try to use a scriptlet variable from the parent page. However I do not receive this problem while using a scriptlet variable in parent page which is defined in the included page.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by Sverre Moe:
Though it does not say why <jsp:include ...> with a page.jsp worked, but not with a page.jspf, even though the jspf and the jsp file was the same. Maybe it was written between the lines.


With the JSP include action (<jsp:include ..) the included page is executed at run time. This means that it has to be capable of running as a standalone JSP page. JSPs must have and extension of ".jsp". It also means that the page has no access to the scripting variables of the page that included it.

With the include directive, the code to the included page is merged before the including page is compiled into servlet code. It is the equivalent to cutting and pasting the code into one JSP file. In this case, the JSP compiler never sees your include page so you can use any extension you like.
It also means that the code in the included page will have access to any scripting variables declared in the including page.
Sverre Moe
Ranch Hand

Joined: Jul 10, 2007
Posts: 110
Originally posted by Ben Souther:

...
It also means that the code in the included page will have access to any scripting variables declared in the including page.


Yes I got that. But I think my problem lies with eclipse.
When I directive included a page with a scriptlet variable the parent page was aware of the variable(so was eclipse), but when I have a scriptlet variable in the parent page, then I cannot access it in the included page(eclipse gives a "cannot be resolved" because it cannot find it). I cannot run in my container before I get eclipse to see this varible. I could get eclipse to ignore this, but then it would ignore all "cannot be resolve" and that would go wrong.
[ July 16, 2007: Message edited by: Sverre Moe ]
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

This is starting to sound like more of an Eclipse issue than a JSP issue.
I'm going to move it to our IDEs forum.
Someone there might have run into the same problem.
A copy will remain here.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18136
    
    8

As far as I know (I haven't downloaded the absolute latest version) Eclipse doesn't come with anything that understands JSPs. So perhaps you are using some Eclipse plugin that you haven't mentioned?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: A page knowledge of its include
 
Similar Threads
JSP logic separation
Java code in jsp:include
!!!!....PROBLEM ...!!!! in opener window form update.
conditional axis web service - sample nowhere
pass the value to next form