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?
Joined: Jul 10, 2007
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 ]
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.
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.
Joined: Jul 10, 2007
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 ]