First example:
INCLUDE-FILE-TEST-1.Jsp:
<% @ page contenttype = "text / html; charset = GBK"%>
<%! String dec_str = "dec_str";%>
<% = DEC_STR%>
<% @ include file = "include-file-test-2.jsp"%>
<% = DEC_STR%>
INCLUDE-file-test-2.jsp:
<% @ page contenttype = "text / html; charset = GBK"%>
<%
DEC_STR = "SCR_STR"; // Eclipse shows an error.
%>
result:
DEC_STR
SCR_STR
Conclusion: The example variable (or part variable) defined in File1, file2 can be referenced and changed. But directly accessing file2 will be wrong.
Second example:
INCLUDE-FILE-TEST-1.Jsp:
<% @ page contenttype = "text / html; charset = GBK"%>
<% SCR_STR = "Hello" SCR_STR;%>
<% @ include file = "include-file-test-2.jsp"%>
<% = SCR_STR%>
<% Temp = "Hello" TEMP;%>
<% = Temp%>
INCLUDE-file-test-2.jsp:
<% @ page contenttype = "text / html; charset = GBK"%>
<%! String Scr_Str = "SCR_STR";%>
<% String Temp = "TEMP";%>
View File1 corresponding to servlet:
Package org.apache.jsp.jsp_002dsyntax_002dtest;
Import ...;
PUBLIC FINAL CLASS INCLUDE_002DFILE_002DTEST_002D1_JSP ... {
String SCR_STR = "SCR_STR";
Private static java.util.vector _jspx_dependants;
STATIC {
_jspx_dependants = new java.util.vector (1);
_jspx_dependants.add ("/ jsp-syntax-test / include-file-test-2.jsp");
}
Public java.util.list getDependants () {
Return_Jspx_Dependants;
}
Public void _jspservice (httpservletRequest Request, httpservletResponse response)
Throws java.io.ioException, servletexception {
......
Try {
......
Response.setContentType ("text / html; charSet = GBK"); ......
Scr_Str = "Hello" SCR_STR;
String Temp = "TEMP";
......
OUT.PRINT (SCR_STR);
Temp = "Hello" TEMP;
......
Out.print (TEMP);
} catch (throwable t) {
......
} finally {
......
}
}
}
result:
Hello SCR_STR
Hello Temp
Conclusion: The example variables defined in File2, file1 can be referenced and changed before <% @ include file = ""%> command (or later).
The partial variables defined in File2 must be referenced and changed after the <% @ include file = ""%> command.
Third example:
INCLUDE-FILE-TEST-1.Jsp:
<% @ page contenttype = "text / html; charset = GBK"%>
<%!
String str1 = "str1";
%>
<%
String str4 = str1 str2 str3;
%>
<% @ include file = "include-file-test-2.jsp"%>
<% = STR4%>
INCLUDE-file-test-2.jsp:
<% @ page contenttype = "text / html; charset = GBK"%>
<%!
String str2 = "str2";
String str3 = STR1 STR2;
%>
File1 corresponds to servlet:
Package org.apache.jsp.jsp_002dsyntax_002dtest;
IMPORT ...
PUBLIC FINAL CLASS INCLUDE_002DFILE_002DTEST_002D1_JSP ... {
String str1 = "str1";
String str2 = "str2";
String str3 = STR1 STR2;
......
Public void _jspservice (httpservletRequest Request, httpservletResponse response)
Throws java.io.ioException, servletexception {
......
Try {
......
Response.setContentType ("text / html; charset = GBK");
......
String str4 = str1 str2 str3;
......
Out.print (STR4);
} catch (throwable t) {
......
}
result:
STR1 STR2 STR1 STR2