There are two different types of includes defined by JSP. You have made use
of the
include directive, which acts as an inline include at compile time. This
include is
actually performed before servlet compilation, and acts essentially as a
means to
externalize shared presentation code.
Since this include occurs before compilation, this means that the code that
is actually
being compiled is included below. Just looking at it, you can probably see
exactly
what is going wrong: Two instances of the language parameter within the page
directive,
two useBean tags creating the same bean, and two declarations of String
message (in fact,
there is no need to put the message in the application context at all).
Hope this helps,
-AMT
----------------------------------------------------------------------------
-----------
<%------------------------------------------------------------%>
<%@ page language="Java" %>
<%-- real.jsp --%>
<jsp:useBean id="ju" class="com.netbyte.util.JspUtils" scope="page" />
<%!
String message = "Blyech";
%>
<html>
<head>
<title>Scope Test</title>
</head>
<body>
<% application.setAttribute("blob.message", message); %>
<%------------------------------------------------------------%>
<%@ page language="Java" %>
<%-- blob.jsp --%>
<jsp:useBean id="ju" class="com.netbyte.util.JspUtils" scope="page" />
<%!
String message = (String)
application.getAttribute("blob.message");
%>
<table border=0>
<tr>
<td>
<p><big><%= message %></big></p>
</td>
<tr>
</table>> </body>
</html>
> -----Original Message-----
> From: A mailing list about Java Server Pages specification and reference
> [mailto:[EMAIL PROTECTED]]On Behalf Of Mailing Lists
> Sent: Wednesday, March 01, 2000 7:29 PM
> To: [EMAIL PROTECTED]
> Subject: scope when including
>
>
> Hi all. I hope this isn't too much of a newbie question though it is
> fundamental
> to JSP development and I may have missed something really obvious. <g>
>
> If I have a file named real.jsp and a file named blob.jsp and real.jsp
> includes
> blob.jsp to display a message with special formatting. They both
> make use of
> a
> java class. How to I impose scope upon the variables so that I don't get
> "variable
> already declared" type errors?
>
> The two files are included below. They fail on the useBean line (already
> declared)
> and on the message line (same). It's not much use if any file which may be
> included
> has to use strange essoteric variable names just to avoid
> possible conflicts
> with
> files which may include it.
>
> BTW: Is application.set/getAttribute() the best way to pass
> information to a
> file
> to be included?
>
> <%------------------------------------------------------------%>
>
> <%@ page language="Java" %>
> <%-- real.jsp --%>
> <jsp:useBean id="ju" class="com.netbyte.util.JspUtils" scope="page" />
> <%!
> String message = "Blyech";
> %>
> <html>
> <head>
> <title>Scope Test</title>
> </head>
> <body>
> <% application.setAttribute("blob.message", message); %>
> <%@ include file="blob.jsp" %>
> </body>
> </html>
>
> <%------------------------------------------------------------%>
>
> <%@ page language="Java" %>
> <%-- blob.jsp --%>
> <jsp:useBean id="ju" class="com.netbyte.util.JspUtils" scope="page" />
> <%!
> String message = (String)
> application.getAttribute("blob.message");
> %>
> <table border=0>
> <tr>
> <td>
> <p><big><%= message %></big></p>
> </td>
> <tr>
> </table>
>
> <%------------------------------------------------------------%>
>
> Zach.
>
> ==================================================================
> =========
> To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
> JSP-INTEREST".
> Some relevant FAQs on JSP/Servlets can be found at:
>
> http://java.sun.com/products/jsp/faq.html
> http://www.esperanto.org.nz/jsp/jspfaq.html
> http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
> http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets
>
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets