代码之家  ›  专栏  ›  技术社区  ›  Deepak Garg

将一个jsp方法拆分为多个斯克里普,以便在其间包含html代码

  •  0
  • Deepak Garg  · 技术社区  · 11 年前

    我正在JSP中编写一个方法,用于转储表中的行:

    <%!  
        void dumpRows(List<MyClass> obList){  
            int a = 10;  
            for(int i = 0; i<100; i++){  
    %>  
       //lots of HTML code which uses the variables from the dumpRows method  
       <td> <%=a*i%> </td>  
    <%  
            }//for loop ends  
        }//method ends  
    %>  
    

    但它正在出错。JSP语法有问题。请帮助我如何实现这一目标

    2 回复  |  直到 11 年前
        1
  •  2
  •   SpringLearner    11 年前
    <%!  
        void dumpRows(List<MyClass> obList){  
            int a = 10;  
            for(int i = 0; i<100; i++){  
    %>  
       //lots of HTML code which uses the variables from the dumpRows method  
       <td> <%=a*i%> </td>                 //here problem
    <%  
            }//for loop ends  
        }//method ends  
    %>
    

    用这种方式打印<%=a*i%>

        2
  •  1
  •   Alex    11 年前

    我认为问题是你在混 <%! , <% <%= .
    如果您将业务逻辑和视图分开,它将更加容易和清晰。
    您可以使用JSTL标记 <c:forEach> 以输出您的html表。