2010-08-23 48 views
1

我旁邊來源:JSP的getParameter(IE問題)

<form action="relogin.jsp" method="post"> 
    <input type="text" id="authname" name="login" value="<%=login%>" tabindex="1" title="<%=bundle.getString("[Login]")%>" /> 
    <input type="password" name="pwd" id="authpass" value="" tabindex="2" title="<%=bundle.getString("[Password]")%>" /> 
    <input type="submit" name="enter" value="<%=bundle.getString("[Enter]")%>" class="proaction" tabindex="3" title="<%=bundle.getString("[Enter]")%>" /> 
</form> 

我保持我的JSP文件中的參數:

<%if (request.getContentLength() == 0) { .[IE6,7 goes here]. } else { .[Chrome and FireFox goes here]. } %> 

正如你可以看到我有維護後參數提交的表單的問題IE6,7。在Chrome和FireFox中一切正常。在這兩種情況下,我使用Apache Tomcat並且日誌文件不包含任何錯誤。

有什麼建議嗎?

+0

我本地化我的問題。我在自己的計算機上部署我的頁面(Ubuntu 10.04,JVM 1.6.0_20,Apache Tomcat 6.0.28)並且一切正常。然後我將我的Tomcat與測試頁複製到生產性服務器(Windows Server 2003,JVM 1.6.0_20,Apache Tomcat 6.0.28),並遇到我上面提到的問題。 – 2010-08-23 10:20:49

+0

我以調試模式運行頁面。我看到'request.postdata'包含值,但最終它們不被解析。 – 2010-08-23 10:39:29

回答

0

我不知道的話,也許嘗試一個測試頁面,而不request.getContentLength()在生產服務器上。與添加頁面:

<%@page contentType="text/html" pageEncoding="UTF-8" import="java.io.*, java.util.*"%> 

// adapted from: http://www.java2s.com/Code/Java/JSP/Printtherequestheadersandthesessionattributes.htm 
    Enumeration enames = request.getHeaderNames(); 
    Enumeration pnames = request.getParameterNames(); 
    Map map = new TreeMap(); 

    while (enames.hasMoreElements()) { 
     String name = (String) enames.nextElement(); 
     String value = request.getHeader(name); 
     map.put(name, value); 
    } 
    while(pnames.hasMoreElements()) { 
     String name = (String) pnames.nextElement(); 
     String value = request.getParameter(name); 
     map.put(name, value); 
    } 

    out.println(createTable(map, "Request Headers")); 

有了:

private static String createTable(Map map, String title) 
    { 
    StringBuffer sb = new StringBuffer(); 

    // Generate the header lines 

    sb.append("<table border='1' cellpadding='3'>"); 
    sb.append("<tr>"); 
    sb.append("<th colspan='2'>"); 
    sb.append(title); 
    sb.append("</th>"); 
    sb.append("</tr>"); 

    // Generate the table rows 

    Iterator imap = map.entrySet().iterator(); 
    while (imap.hasNext()) { 
    Map.Entry entry = (Map.Entry) imap.next(); 
    String key = (String) entry.getKey(); 
    String value = (String) entry.getValue(); 
    sb.append("<tr>"); 
    sb.append("<td>"); 
    sb.append(key); 
    sb.append("</td>"); 
    sb.append("<td>"); 
    sb.append(value); 
    sb.append("</td>"); 
    sb.append("</tr>"); 
    } 

    // Generate the footer lines 

    sb.append("</table><p></p>"); 

    // Return the generated HTML 

    return sb.toString(); 

}

查看生產服務器返回的標題。

+0

鉻: 接受\t應用/ XML,應用/ XHTML + xml的,text/html的; Q = 0.9,文本/無格式; Q = 0.8,圖像/ PNG,*/*; Q = 0.5 接收字符集\t windows-1251,utf-8; q = 0.7,*; q = 0.3 accept-encoding \t gzip,deflate,sdch accept-language \t ru-RU,ru; q = 0。8,的en-US; Q = 0.6,連接; Q = 0.4 緩存控制\t最大年齡= 0 連接\t保活 內容長度內容類型\t應用/ X WWW的形狀配合urlencoded cookie \t ITEMS_PER_PAGE = 10; selectedLocale = RU; JSESSIONID = 131935136616541FC92889E4E2C38116 輸入\t b 登錄\t aasf PWD \t BASF – 2010-08-23 11:09:48

+0

IE: 接受圖像/ GIF,圖像/ X-xbitmap,圖像/ JPEG,圖像/ PJPEG,\ */\ * 接受編碼的gzip ,放氣 接受語言RU 授權NTLM TlRMTVNTUAABAAAAB4IIogAAAAAAAAAAAAAAAAAAAAAFAs4OAAAAD2 == 緩存控制無緩存 連接保持活動 內容長度0 內容類型application/x-WWW窗體-urlencoded 餅乾JSESSIONID = 65314A008A7B82B5DD33BE6939CA0D23 – 2010-08-23 11:11:29

+0

你有在IE中配置的代理服務器嗎? (我問,因爲授權NTLM)。 也許這是造成這個問題? – user406632 2010-08-23 11:17:03

0

我只是嘗試這樣做,無法複製的問題(我在FF4測試,IE6和IE8測試):

<% out.print("Content Length: " + request.getContentLength());%> 
    <h1>Content Length Test</h1> 

    <form action="test.jsp" method="post"> 
     <input type="text" id="authname" name="login" value="a" tabindex="1" title="" /> 
     <input type="password" name="pwd" id="authpass" value="b" tabindex="2" title="" /> 
     <input type="submit" name="enter" value="b" class="proaction" tabindex="3" title="" /> 
    </form> 

你可以嘗試:

<%if (request.getContentLength() > 0) { .. } else { .[Chrome and FireFox goes here], [IE6,7 should go here]. } %> 

注:我還只是測試在Chrome瀏覽器中,所有瀏覽器處理都會在request.getContentLength()中返回相同的值。您確定在relogin.jsp上調用函數getContentLength嗎?

+0

我用你的例子,仍然有同樣的問題。它在IE 6,7中打印「內容長度:0」,在FF和Chrome中打印值> 0。 下面是示例我使用: \t \t \t \t \t [你的榜樣] – 2010-08-23 09:56:10

+0

嗯...我將部署這個JSP到tomcat上你自己的電腦正如你所說,一切正常。 生產配置爲:Win 2003 server SP1,Apache Tomcat 5.5.20,JVM 1.6.0_20。 我想我有一些問題與tomcat。有任何想法嗎? – 2010-08-23 10:07:42

+0

你有什麼配置(OS,JVM,Tomcat)? – 2010-08-23 10:28:39