JSP getParameter (IE problem)

3

I have next from:

<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,但日志文件在这两种情况下都没有包含任何错误。

有什么建议吗?


我定位了我的问题。我在自己的电脑上部署了页面(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),并遇到了上述问题。 - Xupypr MV
我以调试模式运行页面。我发现 request.postdata 包含值,但最终它们没有被解析。 - Xupypr MV
2个回答

1

我不确定,也许可以在您的生产服务器上尝试一个没有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();

}

查看生产服务器返回的头信息。


Chrome:接受 application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,/;q=0.5 接受字符集 windows-1251,utf-8;q=0.7,*;q=0.3 接受编码 gzip,deflate,sdch 接受语言 ru-RU,ru;q=0.8,en-US;q=0.6,en;q=0.4 缓存控制 max-age=0 连接 keep-alive 内容长度 27 内容类型 application/x-www-form-urlencoded Cookie ITEMS_PER_PAGE=10; selectedLocale=ru; JSESSIONID=131935136616541FC92889E4E2C38116 输入 b 登录 aasf 密码 basf - Xupypr MV
接受image/gif、image/x-xbitmap、image/jpeg、image/pjpeg、*/* 接受编码gzip, deflate 接受语言ru 授权NTLM TlRMTVNTUAABAAAAB4IIogAAAAAAAAAAAAAAAAAAAAAFAs4OAAAAD2== 不要缓存cache-control no-cache 连接Keep-Alive 内容长度0 内容类型application/x-www-form-urlencoded cookie JSESSIONID=65314A008A7B82B5DD33BE6939CA0D23 - Xupypr MV
你在IE中配置了代理服务器吗?(我问这个是因为授权NTLM)。也许这就是问题的原因? - user406632
嗯...问题比我想象的要难。IE中的代理设置是正确的。我在我的应用程序中使用NTLM身份验证,并希望用户可以重新登录。因此,我添加了重新登录页面,但在IE中无法正常工作(我认为这是因为它保存了有关先前NTLM设置的某些信息)。 - Xupypr MV
1
太棒了!问题已经解决。我创建了一个过滤器来删除“Authorization”头。 - Xupypr MV
显示剩余2条评论

0

我刚刚尝试了一下,但无法复制这个问题(我在FF4 Beta、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函数吗?

我使用了你的示例,但仍然存在相同的问题。在IE 6、7中打印出“Content Length: 0”,而在FF和Chrome中打印出大于0的值。这是我使用的示例:<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> </head> <body> [你的示例] </body> </html> - Xupypr MV
嗯...我将这个JSP部署到了我的电脑上的Tomcat,一切正常,正如你所说的那样。生产环境配置是:Win 2003服务器SP1,Apache Tomcat 5.5.20,JVM 1.6.0_20。我认为我在Tomcat方面遇到了一些问题。有什么想法吗? - Xupypr MV
你所配置的是什么(操作系统,JVM,Tomcat)? - Xupypr MV

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接