******************* ... user name = <%= name> ***********
Originally I have only one file "First.jsp", then I feel it is too long and logically part of it can be put into a separate jsp, "Second.jsp". That's why I use "include" in "First.jsp" to include the second file. But the second.jsp need to use the var defined in first.jsp. Do I have to redefine it in second.jsp ? What's the better way to make this work ?
Originally posted by Jeanne Boyarsky: Raj, I think I remember using <%@include%> and using variables defined in another JSP. (It's been a while since I've put variables in a JSP now that I know it is bad practice.)
<%@include%> is a compile time construct which is why it works. <jsp:include /> happens at runtime which means the variables are not available since they are compiled separately.
I would use a separate jspf (jsp fragement) if the parts were logically separate or if something was being reused. Not just because the file is long. HTML tends to be long.
Even if I use <%@include%>, when it compiles "second.jsp", how can it compile ? It is a individual file and I didn't define the variable in the file.. don't I have to define it again in "second.jsp" to make it compile ?
Originally posted by Bear Bibeault: When the include directive is used, the JSP with its included files is translated as a single unit.
But I still assert that includes are a poor way to break up code that is "too long".
Thanks Bear. I can understand that "First.jsp" can be compiled well. But "Second.jsp" is a separate file. When the server compiles it, is it compiled separately ? if yes, how can the variables defind in "First.jsp" be transported to it ("First.jsp" includes "Second.jsp", but "Second.jsp" doesn't include the "First.jsp") ??