Asp包含和Jsp包括

时间:2015-04-17 11:09:29

标签: java jsp asp-classic

我引用http://www.valtara.com/csc123/whitepaper/aspbestpractices.htm

For all server side notations e.g. #INCLUDE are processed before any of the
script on the page, hence the following code will not have the results one 
might expect: 

If blnLogedIn Then
%><!-- #INCLUDE FILE='IsCust.Asp' --><%
 Else
%><!-- #INCLUDE FILE='DoLogin.Asp' --><%
 End If

Both files are included and then the script is processed!

在这个例子中,java和jsp不会发生这种情况:

index.jsp

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>JSP Page</title>
</head>
<body>
    <%

        int test = 2;
        if(test == 1){
            %> <jsp:include page="test1.jsp" /> <%
        }else{
            %> <jsp:include page="test2.jsp" /> <%
        }

    %>
 </body>
</html>

jsp的内容包括:

test1.jsp

<%@page contentType="text/html" pageEncoding="UTF-8"%>
    <h1>Hello Test1!</h1>

<%
System.out.println("Im in test1");
%>

test2.jsp

<%@page contentType="text/html" pageEncoding="UTF-8"%>
    <h1>Hello Test2!</h1>

<%
System.out.println("Im in test2");
%>

运行项目时,结果为Hello Test2!,问题是:为什么? Weren的两个文件都被包括在内? java如何对asp进行包含?

0 个答案:

没有答案