關(guān)于瀏覽器地址欄的一些遐想

          在blogjava查看別人的文章的時候出現(xiàn)的是www.aygfsteel.com/XXX/XXXX.html
          對于這個html自己總是感覺是個靜態(tài)的網(wǎng)頁,
          后來詢問別人才了解到這是用了URL重寫的技術(shù),
          于是便查找相關(guān)資料。
          jsp的URL重寫可參看http://www.aygfsteel.com/zs7456/RecentComments.html


          今天看書的時候看到了兩個另外隱藏用戶輸入的辦法。

          一個是使用隱藏域,還有個一個就是使用cookie。

          使用隱藏域的方法也算是簡單吧。

          如你如以前的頁面代碼為

          <intput type="text" name="firstname" size="40">

          <input type="submit" value="submit">

          <input type="reset" value="clear">

          只需要在第一行前加入

          <input type="hidden" name="accountnumber" value="1234">

          方法很簡單,理解就可以使用,不過這只能在保持少量的信息需求的時候才這樣做,盡管很簡單使用隱藏域很簡單。但是如果程序中需要大量的會話狀態(tài)的時候,可能會引發(fā)性能問題。因為在會話期間,會話狀態(tài)必須包括在每個送往瀏覽器的頁面上,而不管會話狀態(tài)是否在頁面上扮演一個很活躍的角色。


          ============================================================
          以前的想法。
          用戶寫完一篇文章在存儲的時候就將其轉(zhuǎn)換為靜態(tài)的網(wǎng)頁。
          或來想了一下,

          這么大的一個blog至少有幾十萬的文章,不可能全部用靜態(tài)的網(wǎng)頁。
          那樣服務(wù)器的檢索將會是一件難以想象的事情。
          再說啦,這樣做也不利于管理啦。
          生成的靜態(tài)網(wǎng)站如果說用戶換了一個風(fēng)格的話,那么該怎么辦呢?
          說說url重寫的好處吧,首先在一個地址欄上不用重寫技術(shù)的話,人們就可以看到用戶所提交的檢索信息,
          如www.aygfsteel.com/duduli/java?id=xxxx 這樣的話xxxx就是提交檢索的信息,
          其余的都不說就從安全方面就加強了。
          還是把別人的寫的重點拿過來吧。

          -----------------------------------------------------------------------------------------------
          原帖:

          在網(wǎng)上看到了一則URL重寫的貼子,感覺比較適合我這樣的情況,應(yīng)用起來簡單。然后自己試著寫了一個例子,居然成功了,而在Struts里不知道怎么實現(xiàn),實現(xiàn)轉(zhuǎn)發(fā)的時候好象沒什么用了。*.do好象不能實現(xiàn)映射
          以下是相關(guān)代碼,若有不正之處,歡迎大家指正!

          首先要去下載一個urlrewritefilter-2.6.zip,然后把它解壓到WEB-INF下,然后配置一下web.xml

           1<?xml version="1.0" encoding="UTF-8"?>
           2<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.4" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee   http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
           3  <filter>
           4    <filter-name>UrlRewriteFilter</filter-name>
           5    <filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
           6    <init-param>
           7      <param-name>logLevel</param-name>
           8      <param-value>WARN</param-value>
           9    </init-param>
          10  </filter>
          11  <filter-mapping>
          12    <filter-name>UrlRewriteFilter</filter-name>
          13    <url-pattern>/*</url-pattern>
          14  </filter-mapping>
          15  <servlet>
          16    <servlet-name>action</servlet-name>
          17    <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
          18    <init-param>
          19      <param-name>config</param-name>
          20      <param-value>/WEB-INF/struts-config.xml</param-value>
          21    </init-param>
          22    <init-param>
          23      <param-name>debug</param-name>
          24      <param-value>3</param-value>
          25    </init-param>
          26    <init-param>
          27      <param-name>detail</param-name>
          28      <param-value>3</param-value>
          29    </init-param>
          30    <load-on-startup>0</load-on-startup>
          31  </servlet>
          32  <servlet-mapping>
          33    <servlet-name>action</servlet-name>
          34    <url-pattern>*.do</url-pattern>
          35  </servlet-mapping>
          36</web-app>


          然后再隨便建立幾個jsp頁面,如:
          MyJsp.jsp

          <%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
          <%
          String path = request.getContextPath();
          String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
          %>

          <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
          <html>
            
          <head>
              
          <base href="<%=basePath%>">
              
              
          <title>My JSP 'MyJsp.jsp' starting page</title>
              
              
          <meta http-equiv="pragma" content="no-cache">
              
          <meta http-equiv="cache-control" content="no-cache">
              
          <meta http-equiv="expires" content="0">    
              
          <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
              
          <meta http-equiv="description" content="This is my page">
              
          <!--
              <link rel="stylesheet" type="text/css" href="styles.css">
              
          -->

            
          </head>
            
            
          <body>
            
          <% 
                
          String a = request.getParameter("id");
            
          %>
              
          <%=basePath %> <br>
              
          <%
                  
          if(a.equals("123"))
                  {
                      out.println(
          "哈哈");
                  }
                  
          else
                  {
                      out.println(
          "再試一次!");
                  }
               
          %>
            
          </body>
          </html>

          接著在urlrewrite.xml里配置一下路徑

          <?xml version="1.0" encoding="utf-8"?>
          <!DOCTYPE urlrewrite PUBLIC "-//tuckey.org//DTD UrlRewrite 2.6//EN"
                  "http://tuckey.org/res/dtds/urlrewrite2.6.dtd"
          >

          <!--

              Configuration file for UrlRewriteFilter
              http://tuckey.org/urlrewrite/

          -->
          <urlrewrite>

              
          <rule>
                  
          <note>
                      The rule means that requests to /test/status/ will be redirected to /rewrite-status
                      the url will be rewritten.
                  
          </note>
                  
          <from>/test/status/</from>
                  
          <to type="redirect">%{context-path}/rewrite-status</to>
              
          </rule>


              
          <outbound-rule>
                  
          <note>
                      The outbound-rule specifies that when response.encodeURL is called (if you are using JSTL c:url)
                      the url /rewrite-status will be rewritten to /test/status/.

                      The above rule and this outbound-rule means that end users should never see the
                      url /rewrite-status only /test/status/ both in thier location bar and in hyperlinks
                      in your pages.
                  
          </note>
                  
          <from>/rewrite-status</from>
                  
          <to>/test/status/</to>
              
          </outbound-rule>
                  
          <rule>
                      
          <from>/test/([0-9]+)</from>
                      
          <to>/MyJsp.jsp?id=$1</to>
                  
          </rule>
          </urlrewrite>


          啟動服務(wù)器,然后輸入http://localhost:8080/test/123 ,那么就可以顯示了,而實際上讀取的路徑是http://localhost:8080/MyJsp.jsp?id=123

          ==============================================================================
          在此聲明,此文章大部分為http://www.aygfsteel.com/zs7456/RecentComments.html    在此只作為自己的筆記,以后學(xué)習(xí)之用。

          posted on 2009-01-08 15:16 duduli 閱讀(489) 評論(0)  編輯  收藏 所屬分類: java

          <2009年1月>
          28293031123
          45678910
          11121314151617
          18192021222324
          25262728293031
          1234567

          導(dǎo)航

          統(tǒng)計

          公告

          welcome to my place.

          常用鏈接

          留言簿(5)

          我參與的團隊

          隨筆分類

          隨筆檔案

          新聞分類

          石頭JAVA擺地攤兒

          搜索

          積分與排名

          最新評論

          閱讀排行榜

          評論排行榜

          @duduli
          主站蜘蛛池模板: 平谷区| 公主岭市| 钟祥市| 淮滨县| 淮安市| 沽源县| 塔河县| 和平区| 元朗区| 秦安县| 莱阳市| 庄河市| 陇西县| 确山县| 开化县| 澎湖县| 天门市| 鄂尔多斯市| 凉山| 义乌市| 桑植县| 怀仁县| 阜宁县| 遵义县| 麟游县| 航空| 南昌县| 菏泽市| 宜章县| 商水县| 大英县| 西畴县| 岑溪市| 乌兰县| 保山市| 保靖县| 广德县| 正镶白旗| 镇安县| 贵港市| 尚志市|