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. 阅读(809) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航: