2013-05-04 79 views
2

我已經搜索了這個問題,有一些答案,但不完全如我的問題。所以這裏是我的JSP代碼:如何在JSP中包含HTML?

<body> 
    <% 
     if (manager.isValid(request.getParameter("username"),request.getParameter("password"))){ 
      out.print("<h1> Welcome "); 
      out.print(request.getParameter("username") + "</h1>"); 
     } else { 
      out.print("<h1> Please Try Again </h1> <br />"); 
      out.print("Either your username or password is incorrect. Please Try again <br /> <br />"); 
         } 
    %> 
    <%@ include file="LoginForm.html" %> 

但不是這樣,我想只包括在「其他」塊「loginForm.html」。 我該怎麼做? 當然,這並不工作,但你會想我想要的東西:

<% 
     if (manager.isValid(request.getParameter("username"),request.getParameter("password"))){ 
      out.print("<h1> Welcome "); 
      out.print(request.getParameter("username") + "</h1>"); 
     } else { 
      out.print("<h1> Please Try Again </h1> <br />"); 
      out.print("Either your username or password is incorrect. Please Try again <br /> <br />"); 
      include file="LoginForm.html" ; 
     } 
    %> 

回答

15

我想向您展示的方式,嘗試像下面。你可以用if來代替它。

<body> 
     <% 
      int x = 10; 
      if(x>10) { 
     %> 
     <%@include file="some.html" %> 
     <% 
      } 
     %> 

</body> 
+0

謝謝,它工作:) – 2013-05-04 16:27:27