Steve's reply is a little misleading. Declaring a variable in a <%! %> tag does not give it request scope: it gives it page scope. So it's right to say that <%! %> declarations will be like member variables (to be precise, they _are_ member variables in the generated servlet), but wrong to suggest they're available as part of the request. You can access them from anywhere within your page, including within any methods you may define, but you will not be able to access them from within a page included using the <jsp:include .../> method. The best way to work out how all the different tags behave and how includes are going to interact is often just to take a look at the generated servlets in <tomcat-home>/work/<host>/ -- the generated code is surprisingly readable, and can be easily analysed to determine exactly what's going on.
-----Original Message----- From: A mailing list about Java Server Pages specification and reference [mailto:[EMAIL PROTECTED]]On Behalf Of Steve Curd Sent: Friday, November 16, 2001 2:28 PM To: [EMAIL PROTECTED] Subject: Re: <jsp:include> question The problem is that the way you have defined retval in userfunc.jsp means the variable only has page scope which means only the page that created the variable can see it (like a local variable). If you define it using the declaration tag <! int retval = 0 ; %>, then the variable should have request scope which means any page that has access to the request can see the variable (like a member variable). -----Original Message----- From: Papo Napolitano [mailto:[EMAIL PROTECTED]] Sent: Friday, November 16, 2001 2:55 PM To: [EMAIL PROTECTED] Subject: Re: <jsp:include> question I tried with this alternatives: <%@ include file="userfunc.jsp" %> <jsp:include page="userfunc.jsp"></jsp:include> <jsp:include page="userfunc.jsp" flush="true"></jsp:include> after the include a try: <%=retval%> The variable retval is defined in the userfunc.jsp file with this instruction: int retval = 0 ; The server returns this error: [EmbeddedCatalinaServiceSX] StandardWrapperValve[jsp]: Servlet.service() for servlet jsp threw exception org.apache.jasper.JasperException: Unable to compile class for JSP An error occurred at line: 3 in the jsp file: /dev/useradd.jsp Generated servlet error: /usr/JBoss-2.4.2_Tomcat-4.0/catalina/work/localhost/bcu/dev/useradd$jsp.java :138: Undefined variable: retval out.print(retval); ^ 1 error at org.apache.jasper.compiler.Compiler.compile(Unknown Source) at org.apache.jasper.servlet.JspServlet.loadJSP(Unknown Source) at org.apache.jasper.servlet.JspServlet$JspServletWrapper.loadIfNecessary(Unkno wn Source) at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(Unknown Source) at org.apache.jasper.servlet.JspServlet.serviceJspFile(Unknown Source) at org.apache.jasper.servlet.JspServlet.service(Unknown Source) at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Unknown Source) at org.apache.catalina.core.ApplicationFilterChain.doFilter(Unknown Source) at org.apache.catalina.core.StandardWrapperValve.invoke(Unknown Source) at org.apache.catalina.core.StandardPipeline.invokeNext(Unknown Source) at org.apache.catalina.core.StandardPipeline.invoke(Unknown Source) at org.apache.catalina.core.ContainerBase.invoke(Unknown Source) at org.apache.catalina.core.StandardContextValve.invoke(Unknown Source) at org.apache.catalina.core.StandardPipeline.invokeNext(Unknown Source) at org.apache.catalina.valves.CertificatesValve.invoke(Unknown Source) at org.apache.catalina.core.StandardPipeline.invokeNext(Unknown Source) at org.apache.catalina.core.StandardPipeline.invoke(Unknown Source) at org.apache.catalina.core.ContainerBase.invoke(Unknown Source) at org.apache.catalina.core.StandardContext.invoke(Unknown Source) at org.apache.catalina.core.StandardHostValve.invoke(Unknown Source) at org.apache.catalina.core.StandardPipeline.invokeNext(Unknown Source) at org.apache.catalina.core.StandardPipeline.invoke(Unknown Source) at org.apache.catalina.core.ContainerBase.invoke(Unknown Source) at org.apache.catalina.core.StandardEngineValve.invoke(Unknown Source) at org.apache.catalina.core.StandardPipeline.invokeNext(Unknown Source) at org.apache.catalina.core.StandardPipeline.invoke(Unknown Source) at org.apache.catalina.core.ContainerBase.invoke(Unknown Source) at org.apache.catalina.connector.http.HttpProcessor.process(Unknown Source) at org.apache.catalina.connector.http.HttpProcessor.run(Unknown Source) at java.lang.Thread.run(Thread.java:484) I'm Using JBoss 2.4.2 with Tomcat 4.0 Cheers, Papo =========================================================================== To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST". For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST". Some relevant FAQs on JSP/Servlets can be found at: http://archives.java.sun.com/jsp-interest.html http://java.sun.com/products/jsp/faq.html http://www.esperanto.org.nz/jsp/jspfaq.jsp http://www.jguru.com/faq/index.jsp http://www.jspinsider.com =========================================================================== To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST". For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST". Some relevant FAQs on JSP/Servlets can be found at: http://archives.java.sun.com/jsp-interest.html http://java.sun.com/products/jsp/faq.html http://www.esperanto.org.nz/jsp/jspfaq.jsp http://www.jguru.com/faq/index.jsp http://www.jspinsider.com
