JSTL vs JSP Scriptlets

前端 未结 6 684
面向向阳花
面向向阳花 2020-12-04 13:09

I want someone to explain some points in BlausC\'s amazing answer in this question.

He said that scriptlets had some disadvantages, which are:

  1. Reusa

6条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-04 14:07

    It depends on the pattern you're using. By using the MVC (spring, struts, ...) you should avoid the usage of scriptlets in your JSP, because it represent the view it should contain pure XHTML tags. JSTL is a declarative language some kind of XML, while scriplet isn't.

    Particularly I have used JSTL in combination with AJAX via prototype for generating RIA without needing to implement another pattern. Recently I have seen this kind of programming with ExtJS and DWR. In my case I found It was necessary to combine both JSTL and scriplets always preferring JSTL when possible.

    
    <% String signExt="jpg"; %>
    <% int r=0, iMaxRows=0, iMaxCols=0;%>
    
    
        
            
                CALL GetProfilesView('', '')
            
    
             
            <%  
            String strElements = pageContext.getAttribute("strElements").toString();
            int iElements = (int)Integer.valueOf(strElements).intValue(); 
            String to = "";
            %>
    
            
    
                <%for(int i=1, j=0, col=0; i<100; i++){%>
                
                    <%for(j=0; j<4; j++, col++){%>
                    <%=col%>               
    
                    <%}%>
                
                <%
                    if( col >= iElements){break;}
                }%>
            
    <%if( col < iElements){%> ................. ................. <% if( col < iElements-1){ to = to + pageContext.getAttribute("sMail").toString() + ","; }else{ to = to + pageContext.getAttribute("sMail").toString(); } %> <%}else{%> ............. <%}%>
    <c:out value="${dataset.rows[c].email}" />
    x
    .............

提交回复
热议问题