First example:
File1:
<%
String str = "aaaaa";
%>
<% = STR%>
File2:
<%
Str = STR "BBBBB";
%>
result:
An error occurred while accessing file1, prompting the variable Str in File2.
analysis:
When requested File1, Tomcat first converts two JSP files to servlet (.java) files. Then try to compile the two into .class files, when File1 is compiled normally; File2 cannot be compiled by compilation.
in conclusion:
Unlike the incrude-file instructions to compile the two files into a servlet file, JSP-Include requires two files to be relatively independent, complete.
Second example:
File1:
<% @ page contenttype = "text / html; charset = GBK"%>
<%
Request.setttribute ("Str", "Aaaaaaaaaaaaaaaa");
%>
File2:
<% @ page contenttype = "text / html; charset = GBK"%>
<%
String str = (String) Request.getaTribute ("str");
Out.println (STR);
%>
result:
AAAAAAAAAAAAAAAAAAAAAAA
analysis:
Due to the relatively independent of the two pages, requests can be delivered. That is, when requesting file1, File1 will automatically request file2.
in conclusion:
Two pages using JSP-Include are a request relationship instead of a relationship. This is different from the include-file.
Third example:
File1:
<% @ page contenttype = "text / html; charset = GBK"%>
<%
Request.setttribute ("Str", "Aaaaaaaaaaaaaaaa");
%>
<%
String str = (String) Request.getaTribute ("str");
Out.println (STR);
%>
File2:
<% @ page contenttype = "text / html; charset = GBK"%>
<%
String str = (String) Request.getaTribute ("str");
Request.setttribute ("Str", Str "Bbbbbbbbbbbb");
%>
result:
Aaaaaaaaaaaaaaabbbbbbbbbbbbbbb
Conclusion: The request relationship between the two pages is two-way.