Bryan

            BlogJava :: 首頁 :: 聯系 :: 聚合  :: 管理
            37 Posts :: 3 Stories :: 24 Comments :: 0 Trackbacks

          最近在做的一個項目,前臺依然是使用displaytag,由于項目需要,需要對記錄進行排序和導出報表,因為數據不允許分頁,提交過來的參數信息又較多,所以在Displaytag中,默認取request中的數據再次導出報表和排序,就導致URL 過長,導致導出和排序失敗.

          WWW FAQs: What is the maximum length of a URL?

          2006-10-13: Although the specification of the HTTP protocol does not specify any maximum length, practical limits are imposed by web browser and server software.

          Microsoft Internet Explorer (Browser)

          Microsoft states that the maximum length of a URL in Internet Explorer is 2,083 characters, with no more than 2,048 characters in the path portion of the URL. In my tests, attempts to use URLs longer than this produced a clear error message in Internet Explorer.

          Firefox (Browser)

          After 65,536 characters, the location bar no longer displays the URL in Windows Firefox 1.5.x. However, longer URLs will work. I stopped testing after 100,000 characters.

          Safari (Browser)

          At least 80,000 characters will work. I stopped testing after 80,000 characters.

          Opera (Browser)

          At least 190,000 characters will work. I stopped testing after 190,000 characters. Opera 9 for Windows continued to display a fully editable, copyable and pasteable URL in the location bar even at 190,000 characters.

          在其他的瀏覽器都正常.因為DisplayTag在處理導出報表和排序默認是Get處理請求的,沒辦法,到google搜了一下,發現有人解決了這個問題.見(http://jira.codehaus.org/browse/DISPL-377)

          試著修改這個類,,因為處理為Form Post提交數據,一切正常.但是想想source code被修改了,會給以后帶來一定的風險.想個1天也沒什么辦法.感覺只能post才能處理大量的數據.

          postForm.append("<form name=\"form" + uid
                 + "\" method=\"post\" action=\""
                 + sortHref.getBaseUrl() + "\">");
               for (int idx = 0; idx < mapKey.length; idx++) {
                String value = "";
                // Modified by Indicia 07-mar-2007 - Begin
                if (sortHref.getParameterMap().get(mapKey[idx]) instanceof Object[]) {
                 Object[] values = (Object[])sortHref.getParameterMap().get(mapKey[idx]);
                 for(int j=0; j < values.length; j++) {
                  value = ((Object)values[j]).toString();
                  try {
                   postForm.append("<input type=\"hidden\" name=\""
                     + mapKey[idx] + "\" value=\"" + URLDecoder.decode(value, "ISO-8859-1") + "\">");
                  } catch (UnsupportedEncodingException ignore) {}
                 }
                } else {
                 value = sortHref.getParameterMap().get(
                   mapKey[idx]).toString();
                 try {
                  postForm.append("<input type=\"hidden\" name=\""
                    + mapKey[idx] + "\" value=\"" + URLDecoder.decode(value, "ISO-8859-1") + "\" title=\""+value+"\"/>");
                 } catch (UnsupportedEncodingException ignore) {}
                }      
                // Modified by Indicia 07-mar-2007 - End
               }
               postForm.append("</form>");
               Href postExportHerf = (Href) sortHref.clone();
               postExportHerf.setFullUrl("javascript:document.forms['form" + uid
                 + "'].submit();");

          本來想這個樣子,反正解決了問題,但是想想,好象默認的Session中的數據不會出現在displaytagUrl后面,就試著改了下代碼,發現果然可行.把較長的數據放在session中,然后在displaytag前臺中使用excludedParams="datasubmit去除那些需要長的需要再次提交給后臺的數據.結果發現果然導出報表和排序正常了.

            //first get it from request
            //if is null get from the session
            String dataSubmit=request.getParameter("datasubmit");
            if(dataSubmit==null)
            {
                 dataSubmit=(String)request.getSession().getAttribute("datasubmit");
            }
            
            request.getSession().setAttribute("datasubmit", dataSubmit);

          <display:table name="states" sort="list" defaultsort="1" id="element" requestURI="state.html"  excludedParams="datasubmit">
            <display:column property="id" title="ID" sortable="true" sortName="id" />
            <display:column property="country_id" sortable="true" sortName="country_id" title="First Name" />
          </display:table>

          posted on 2008-06-09 10:34 Life is no respector of any genius. 閱讀(817) 評論(0)  編輯  收藏

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


          網站導航:
          博客園   IT新聞   Chat2DB   C++博客   博問  
           
          主站蜘蛛池模板: 泽普县| 武汉市| 哈密市| 舟山市| 鸡西市| 且末县| 句容市| 祁阳县| 环江| 温宿县| 东至县| 南乐县| 乳山市| 三台县| 天全县| 临夏县| 西和县| 阿瓦提县| 巧家县| 博白县| 望城县| 青阳县| 麦盖提县| 黔西县| 莒南县| 台东县| 宁阳县| 阿拉尔市| 石渠县| 高安市| 阿克苏市| 肇源县| 武陟县| 景洪市| 齐齐哈尔市| 尼勒克县| 孟津县| 衡东县| 舞钢市| 沙坪坝区| 名山县|