posts - 35,  comments - 7,  trackbacks - 0
          關于網站開發中連接的可移植性總結

          網絡主機地址http://localhost:
          8080/

          1. 相對于根目錄的連接,形如: "/another.jsp"
           
           /DIR/目錄下的
           <a href
          ="/another.jsp">Link</a>
           <html:link href
          ="/another.jsp">Link</html:link>
           <html:link page
          ="/another.jsp">Link</html:link> 
           在默認ROOT應用中
          ,分別連接到地址:
           http://localhost:
          8080/another.jsp
           http://localhost:
          8080/another.jsp
           http://localhost:
          8080/another.jsp 
           在應用test中
          ,分別連接到地址:
           http://localhost:
          8080/another.jsp
           http://localhost:
          8080/another.jsp
           http://localhost:
          8080/test/another.jsp 
           
          2. 相對于當前目錄的連接,形如: "./another.jsp" 或 "another.jsp"
           
           /DIR/目錄下的
           <a href
          ="./another.jsp">Link</a> 
           <html:link href
          ="./another.jsp">Link</html:link>
           <html:link page
          ="./another.jsp">Link</html:link> 
           在默認ROOT應用中
          ,都分別連接到地址:
           http://localhost:
          8080//DIR/another.jsp
           http://localhost:
          8080//DIR/another.jsp
           http://localhost:
          8080//DIR/another.jsp  
           在應用test中
          ,分別連接到地址:
           http://localhost:
          8080//DIR/another.jsp
           http://localhost:
          8080//DIR/another.jsp
           http://localhost:
          8080/test./another.jsp   錯誤連接(而且與DIR無關,都連接到此地址)
            
           /DIR/目錄下的
           <a href
          ="another.jsp">Link</a> 
           <html:link href
          ="another.jsp">Link</html:link> 
           <html:link page
          ="another.jsp">Link</html:link> 
           在默認ROOT應用中
          ,都分別連接到地址:
           http://localhost:
          8080//DIR/another.jsp
           http://localhost:
          8080//DIR/another.jsp
           http://localhost:
          8080//DIR/another.jsp   
           在應用test中
          ,分別連接到地址:
           http://localhost:
          8080//DIR/another.jsp
           http://localhost:
          8080//DIR/another.jsp
           http://localhost:
          8080/testanother.jsp       錯誤連接(而且與DIR無關,都連接到此地址)
           
          3總結
           由于在網站開發時經常不使用默認的WEB應用,而可能把一個模塊開發成一個WEb應用(可能多人合作),
           但是在發布的時候要把所有模塊發布為一個WEB應用,并通常是默認的WEB應用,為了使URL不依賴于Web應用
           和是否是默認WEB應用,建議如下
            a.對于相對于WEB應用根目錄的連接
          ,形如: "/another.jsp"
              使用<html:link page
          ="/..">Link </html:link>
            b.對于相對于當前目錄的連接,形如: 
          "./another.jsp" 或 "another.jsp"
              使用<html:link href
          ="./another.jsp">Link </html:link>
                  <a href
          ="./another.jsp">Link </a>或        
                  <html:link href
          ="another.jsp">Link </html:link>
                  <a href
          ="another.jsp">Link </a>
              不要使用<html:link page
          ="./another.jsp">Link </html:link>
                      <html:link page
          ="another.jsp">Link </html:link> 此二者不可移植
            c.建議使用struts的html標簽庫<html:link..標簽,因為當用戶關閉Cookie時會自動重寫URL,所以概括
              兩句話:相對應用根目錄用<html:link page
          ="/.."  
                      相對當前的目錄用<html:link href
          ="./XXXXX.jsp"   或 <html:link href="XXXXX.jsp"  
           
           
          4.補充
            還有一個標簽<html:link forward
          ="forwardname"> Link </html:link> 上面沒有提到,現做以說明。
            
            forward屬性和struts配置文件<global-forwards>中的一個<forward>元素匹配,不能和<action>中<forward>匹配。
            
            例子:<global-forwards>
                   <forward name
          ="forwardname" path="//another.jsp"/>
                 </global-forwards>
                 
                 <html:link forward
          ="forwardname"> Link </html:link>
                 相當于<html:link page
          ="//another.jsp"> Link </html:link>
            需要注意的是:<global-forwards>中<forward>的path要使用相對于WEB應用的根目錄路徑,包括<action>中也是。
            
            在struts1.1多應用模塊時<html:link forwad. 有時不好使,不知道為什么????(好像是模塊切換狀態
            不對)所以最好不用。
            替代方法;
            網頁中用連接
              <html:link page
          ="/forwardaction.do">forward</html:link>
            在action-mapping配置如下action
               <action  path
          ="/forwardaction"  forward="/index.jsp" />
            
          posted on 2006-02-06 20:58 java小記 閱讀(210) 評論(0)  編輯  收藏

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           

          <2006年2月>
          2930311234
          567891011
          12131415161718
          19202122232425
          2627281234
          567891011

          常用鏈接

          留言簿(1)

          隨筆分類

          隨筆檔案

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 江北区| 石泉县| 东宁县| 无极县| 江安县| 西贡区| 冀州市| 沙坪坝区| 从化市| 福州市| 平昌县| 西宁市| 托克托县| 北流市| 海林市| 台前县| 科尔| 南皮县| 永康市| 永兴县| 康定县| 涪陵区| 黄石市| 宿州市| 突泉县| 安康市| 罗江县| 含山县| 安徽省| 弥渡县| 平山县| 阳朔县| 克山县| 嵊州市| 周宁县| 淳化县| 新乡市| 昭苏县| 菏泽市| 沿河| 金门县|