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