on 11-16-2006 9:46 AM
is it works fine if we use page directive and incude directive and included file is dynamic resource i.e jsp?
like this way
mutiple.jsp
<%@ page language="java" %>
<%@ include file="/one.jsp" %>
one.jsp
<%@ page language="java" %>
Hi Madan,
If you use Netweaver. 04 then this could be a problem, but this JSP will not throw exception in SAP NetWeaver Application Server, Java EE 5 Edition.
Here is the description of the problem:
You JSP includes in a static manner other resource (in this case other JSP), but you include not the result of requesting it, but the source code. So the resulting JSP is:
mutiple.jsp
<%@ page language="java" %>
<%@ include file="/one.jsp" %>
one.jsp
<%@ page language="java" %>
resulting.jsp
<%@ page language="java" %>
<%@ page language="java" %>
In JSP 1.2 specification it is written:
A translation unit (<b>JSP source file and any files included via the include
directive</b>) can contain more than one instance of the page directive, all the
attributes will apply to the complete translation unit (i.e. page directives are
position independent). However, there shall be only one occurrence of any
attribute/value defined by this directive in a given translation unit with the
exception of the import attribute; multiple uses of this attribute are cumulative
(with ordered set union semantics). <b>Other such multiple attribute/value
(re)definitions result in a fatal translation error.</b>
Here is the text in JSP 2.1 specification:
A translation unit (JSP source file and any files included via the include
directive) can contain more than one instance of the page directive, all the
attributes will apply to the complete translation unit (i.e. page directives are
position independent). An exception to this position independence is the use of the
pageEncoding and contentType attributes in the determination of the page
character encoding; for this purpose, they should appear at the beginning of the
page (see Section JSP.4.1). There shall be only one occurrence of any attribute/
value pair defined by this directive in a given translation unit, <b>unless the values for
the duplicate attributes are identical for all occurrences.</b>
This is the reason why your code throws exception on Netweaver 04 and is running on SAP NetWeaver Application Server, Java EE 5 Edition.
Best regards,
Todor
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Madan,
To include a dynamic resource like a jsp file in another jsp you can <b>definitely </b>use the <b>include directive.</b>
Refer to following link for more detail on the syntax of it,
http://java.sun.com/products/jsp/tags/11/syntaxref1112.html
An example cound be like,
<jsp:include page="/jsp/Tadmin.jsp"></jsp:include>
Hope this helps you.
Best regards,
Guru.
PS: Reward points for helpfull replies.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
<jsp:include page="scripts/login.jsp" />
<jsp:include page="copyright.html" />
<jsp:include page="/index.html" />
The <jsp:include> element allows you to include either a static or dynamic file in a JSP file. The results of including static and dynamic files are quite different. If the file is static, its content is included in the calling JSP file. If the file is dynamic, it acts on a request and sends back a result that is included in the JSP page. When the include action is finished, the JSP container continues processing the remainder of the JSP file.
Thanks,
Lohi.
Hi Lohitha
thanks for your reply ,my question is not related to with <jsp:include>
actually my question is like this
i am getting exception if i use
<%@ include file="abc.jsp"%> in jsp along with <%@ page language="java"%>
i.e
multiple.jsp[name of jsp]
<%@ page language="java"%>
<%@ include file="/abc.jsp"%>
1.the above code what i written is correct or not?
2. constraint is there using page directive and incude directive according to "sun" specfications?
Hi Madan,
Using the include file directive lead to a caching of the web pages, but if the application depends on capturing the contents of the included file at the time of each request, then an jsp include action should be used.
Also the path to the file names are relative to the current jsp file, so be carefull in that as well.
For more details use the following link,
http://javaalmanac.com/egs/javax.servlet.jsp/include.jsp.html
If you still get the exception, then post the exception and the source code for more help.
Best regards,
Guru.'
PS: Reward points for more helpfull replies.
User | Count |
---|---|
86 | |
10 | |
10 | |
9 | |
7 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.