开发者

JSP getParameter (IE problem)

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]")%>" /> 
  <i开发者_StackOverflow社区nput 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>

I maintain parameters in my jsp file:

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

As you can see I have a problem to maintain post parameters posted form IE6,7. In Chrome and FireFox everything works fine. I use Apache Tomcat and log file doesn't contain any errors in both cases.

Any suggestions?


I am not sure then, maybe try a test page on your production server without request.getContentLength().. add a page with:

<%@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"));

With:

   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();

}

To see what headers the production server is returning.


I just tried this and could not replicate the issue (I tested in FF4 Beta, IE6 and 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>

Can you try:

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

Note: I also just tested in Chrome.. all browsers handle return the same value in request.getContentLength().. are you sure you are calling the function getContentLength on relogin.jsp ?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜