- Timestamp:
- Aug 8, 2008, 12:12:25 PM (14 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/config/dist/web.xml
r4319 r4384 37 37 <location>/exception/exception.jsp</location> 38 38 </error-page> 39 40 <!-- 41 If BASE Javascript encounters an URL that is longer than 42 specified by this setting when assigning it to for example 43 location.href = url, BASE will instead try to rewrite the document 44 to generate a POST request instead. This is to avoid problem with 45 web servers that doesn't accept URL:s longer than a specified size 46 For example, Apache has a default max length of 8190. If this setting 47 is 0, the rewrite functionality is disabled. 48 --> 49 <context-param> 50 <param-name>max-url-length</param-name> 51 <param-value>8000</param-value> 52 </context-param> 39 53 40 54 <!-- -
trunk/src/clients/web/net/sf/basedb/clients/web/taglib/Head.java
r4187 r4384 171 171 sb.append("\t\t\treturn '").append(sc == null ? "" : sc.getId()).append("';\n"); 172 172 sb.append("\t\t}\n"); 173 if (page.getMaxUrlLength() != null) 174 { 175 sb.append("\t\tfunction getMaxUrlLength()\n"); 176 sb.append("\t\t{\n"); 177 sb.append("\t\t\treturn '").append(page.getMaxUrlLength()).append("';\n"); 178 sb.append("\t\t}\n"); 179 } 173 180 sb.append("\t</script>\n"); 174 181 } -
trunk/src/clients/web/net/sf/basedb/clients/web/taglib/Page.java
r4095 r4384 28 28 import net.sf.basedb.core.SessionControl; 29 29 import net.sf.basedb.clients.web.Base; 30 import net.sf.basedb.util.Values; 30 31 31 32 import javax.servlet.jsp.PageContext; … … 163 164 */ 164 165 private static String BASE_VERSION = null; 166 167 private static String MAX_URL_LENGTH = null; 165 168 166 169 /** … … 221 224 { 222 225 return ROOT; 226 } 227 /** 228 @since 2.8 229 */ 230 public String getMaxUrlLength() 231 { 232 return MAX_URL_LENGTH; 223 233 } 224 234 public String getServerName() … … 246 256 { 247 257 super.setPageContext(pageContext); 248 if (ROOT == null) ROOT = ((HttpServletRequest)pageContext.getRequest()).getContextPath()+"/"; 258 if (ROOT == null) 259 { 260 ROOT = ((HttpServletRequest)pageContext.getRequest()).getContextPath()+"/"; 261 int maxUrlLength = Values.getInt(pageContext.getServletContext().getInitParameter("max-url-length")); 262 MAX_URL_LENGTH = maxUrlLength > 0 ? String.valueOf(maxUrlLength) : null; 263 } 249 264 try 250 265 { -
trunk/www/include/scripts/main.js
r4314 r4384 91 91 url += '&warnIfOpen=0'; 92 92 } 93 window.newWindow = window.open(url, name, options); 94 window.newWindow.isOld = true; 93 newWin.isOld = true; 94 window.newWindow = newWin; 95 Main.safeSetLocation(url, newWin, true); 95 96 setTimeout("window.newWindow.focus()", 100); 96 97 } … … 510 511 i++; 511 512 } 512 theWindow.location.href = url;513 Main.safeSetLocation(url, theWindow); 513 514 } 514 515 } … … 540 541 i++; 541 542 } 542 theWindow.location.href = url;543 Main.safeSetLocation(url, theWindow); 543 544 } 544 545 } … … 581 582 url += '&item_type='+itemType+'&item_id='+itemId; 582 583 if (extraUrl) url += extraUrl; 583 location.href = url;584 } 585 586 this.getIdFromLocation = function( )584 Main.safeSetLocation(url); 585 } 586 587 this.getIdFromLocation = function(url) 587 588 { 588 589 var findId = /ID=([0-9a-f]*)/; 589 var ID = location.search.match(findId)[1]; 590 return ID; 590 if (!url) url = location.search; 591 var matches = url.match(findId); 592 return matches && matches.length > 1 ? matches[1] : null; 591 593 } 592 594 … … 625 627 } 626 628 627 628 this.viewSource = function() 629 { 629 /* 630 Safely set the location of a document using as if 631 win.document.location.href = url or win.document.replace(url) 632 had been used. If the url is longer 633 than specified by getMaxUrlLength() function the url will 634 be re-written to a <form> using hidden fields to submit 635 query values. 636 @param url The url to set 637 @param win The window to set the location on, if not given, 638 the current window is assumed 639 @param replace If given, use location.replace() instead of location.href 640 (only if url is not too long) 641 */ 642 this.safeSetLocation = function(url, win, replace) 643 { 644 if (!url) return; 645 if (!win) win = window; 646 var postform; 647 if (window.getMaxUrlLength && url.length > window.getMaxUrlLength()) 648 { 649 postform = this.convertToPostForm(url, win); 650 } 651 if (postform) 652 { 653 document.body.appendChild(postform); 654 postform.submit(); 655 } 656 else if (replace) 657 { 658 win.document.location.replace(url); 659 } 660 else 661 { 662 win.document.location.href = url; 663 } 664 } 665 666 /* 667 Convert an URL to a HTML form using POST and write it to 668 a document. This method extract all query parameters from the 669 URL (except ID) and generate a <form> tag with hidden input fields. 670 The method returns an unattached Form object. To post it, 671 do: document.body.appendChild(form); form.submit(); 672 @param url The url to convert 673 @param win The window the form should post to, if no window is given 674 or if it doesn't have a name the form is posted to the current 675 window. 676 */ 677 this.convertToPostForm = function(url, win) 678 { 679 var i = url.indexOf('?'); 680 if (i < 0) return null; 681 682 var query = url.substring(i+1); 683 if (!query) return null; 684 685 url = url.substring(0, i); 686 var ID = Main.getIdFromLocation(query); 687 if (ID) url += '?ID=' + ID; 688 689 var frm = document.createElement('form'); 690 frm.setAttribute('action', url); 691 frm.setAttribute('method', 'post'); 692 if (win && win.name) frm.setAttribute('target', win.name); 693 694 var options = query.split('&'); 695 for (var i = 0; i < options.length; i++) 696 { 697 var pair = options[i].split('='); 698 var name = pair[0]; 699 var value = decodeURIComponent(pair[1]); 700 if (name && name != 'ID') 701 { 702 Forms.createHidden(frm, name, value, document); 703 } 704 } 705 return frm; 706 } 707 708 this.viewSource = function(doc) 709 { 710 if (!doc) doc = document; 630 711 this.openPopup('', 'ViewSource', 800, 800); 631 var html = doc ument.body.parentNode.innerHTML;712 var html = doc.body.parentNode.innerHTML; 632 713 html = html.replace(/\</g, '<'); 633 714 html = html.replace(/\>/g, '>'); … … 1692 1773 @param name The name of the hidden element 1693 1774 @param value The value of the hidden element 1694 */ 1695 this.createHidden = function(frm, name, value) 1696 { 1697 var hidden = document.createElement('input'); 1775 @param doc The document to create the element in, if not given 1776 uses the global 'document' object 1777 */ 1778 this.createHidden = function(frm, name, value, doc) 1779 { 1780 if (!doc) doc = document; 1781 var hidden = doc.createElement('input'); 1698 1782 hidden.setAttribute('type', 'hidden'); 1699 1783 hidden.setAttribute('name', name);
Note: See TracChangeset
for help on using the changeset viewer.