2010-08-23 47 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