Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2088381
  • 博文数量: 1647
  • 博客积分: 80000
  • 博客等级: 元帅
  • 技术积分: 9980
  • 用 户 组: 普通用户
  • 注册时间: 2008-10-13 15:15
文章分类

全部博文(1647)

文章存档

2011年(1)

2008年(1646)

我的朋友

分类:

2008-10-28 18:27:44

      创建动态Web页面的最基本的办法是为每个页面创建独立的JSP文件。图16-2和图16-3分别为tilestaglibs应用的主页index.jsp和产品页面product.jsp。

本节介绍的tilestaglibs应用的源程序位于配套光盘的sourcecode/tilestaglibs/version1/tilestaglibs目录下。如果要在Tomcat上发布这个应用,只要把version1目录下的整个tilestaglibs子目录拷贝到CATALINA_HOME/webapps目录下即可。


图16-2 tilestaglibs应用的主页index.jsp


图16-3 tilestaglibs应用的产品页面product.jsp

例程16-1和例程16-2分别为index.jsp和product.jsp的源代码。例程16-1 index.jsp
    例程16-1 index.jsp

 <%@ page contentType="text/html; charset=UTF-8" %>

  
      TilesTaglibs Sample
  
  
      <%-- One table lays out all of the content for this page --%>
     
        
            <%-- Sidebar--%>
           
            <%-- Main content--%>
           
        
     

              
                 
                     <%-- Sidebar top --%>
                    
                 
                 
                     <%-- Sidebar bottom --%>
                    
                 
              

                       
                          

                       
                          

                     

                        Links


                        Home

                        Products

                        Hot Link1

                        Hot Link2

                        Hot Link3


                    


           

              
                 
                     <%-- Header--%>
                    
                 
                
                     <%-- Content--%>
                    
                 
                 
                     <%-- Footer--%>
                    
                 
              

                        Welcome to ABC Inc.
                       

                    

                        Page-specific content goes here
                    

                       

                        Thanks for stopping by!
                    

           

  

例程16-2 product.jsp

 <%@ page contentType="text/html; charset=UTF-8" %>

  
      TilesTaglibs Sample
  
  
      <%-- One table lays out all of the content for this page --%>
     
        
            <%-- Sidebar--%>
           
            <%-- Main content--%>
           
        
     

              
                 
                     <%-- Sidebar top --%>
                    
                 
                 
                     <%-- Sidebar bottom --%>
                    
                 
              

                       
                          

                       
                          

                     

                         Links


                        Home

                        Products

                        Hot Link1

                        Hot Link2

                        Hot Link3

                    


           

              
                 
                     <%-- Header--%>
                    
                 
                
                     <%-- Content--%>
                    
                 
                 
                     <%-- Footer--%>
                    
                 
              

                        Welcome to ABC Inc.
                       

                    

                        Products


            

  • product1


  •                        
  • product2


  •                        
  • product3


  •                     

                           

                            Thanks for stopping by!
                        

               

      

    由例程16-1和例程16-2可以看出,在index.jsp和product.jsp文件中,仅仅粗体字标识的代码块不是重复代码,其余部分均为重复代码。如果网页的相同部分发生需求变更,必须手工修改所有的JSP文件。可见,采用基本的JSP语句来编写上述网页,会导致JSP代码的大量冗余,增加开发与维护成本。

    【责编:Ken】

    --------------------next---------------------
     <%@ page contentType="text/html; charset=UTF-8" %>

      
          TilesTaglibs Sample
      
      
          <%-- One table lays out all of the content for this page --%>
         
            
                <%-- Sidebar--%>
               
                <%-- Main content--%>
               
            
         

                  
                     
                         <%-- Sidebar top --%>
                        
                     
                     
                         <%-- Sidebar bottom --%>
                        
                     
                  

                           
                              

                           
                              

                         

                             Links


                            Home

                            Products

                            Hot Link1

                            Hot Link2

                            Hot Link3

                        


               

                  
                     
                         <%-- Header--%>
                        
                     
                    
                         <%-- Content--%>
                        
                     
                     
                         <%-- Footer--%>
                        
                     
                  

                            Welcome to ABC Inc.
                           

                        

                            Products


                

  • product1


  •                        
  • product2


  •                        
  • product3


  •                     

                           

                            Thanks for stopping by!
                        

               

      

    --------------------next---------------------

    阅读(212) | 评论(0) | 转发(0) |
    给主人留下些什么吧!~~