tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 43872] New: - getMethod() always returns "GET"
Date Thu, 15 Nov 2007 14:15:59 GMT
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG·
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=43872>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND·
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=43872

           Summary: getMethod() always returns "GET"
           Product: Tomcat 5
           Version: 5.5.24
          Platform: Other
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Servlet & JSP API
        AssignedTo: tomcat-dev@jakarta.apache.org
        ReportedBy: emanuele.lombardi@casaccia.enea.it
                CC: emanuele.lombardi@casaccia.enea.it


Apache Tomcat/5.5.25
JVM 1.5.0_14-b03
Linux 2.6.16.27-0.9-smp

I found the following strange behavours:
 
1) Within servlets, getMethod() returns "GET" even if the method actually used 
in the HTML form is "post". 
2) Variable coming from HTML are all null when method="post" is used in the 
HTML form.
3) Within servlets doPost(...) is never executed.

I'm aware that this behavour is to "big" to be a bug (someone would have 
noticed it before!) but I don't find anything in docs about any strange tricks 
needed to get POSTed variables.

As a test case I wrote a servlet with both doPost(..) and doGet(..) and what 
it happens is that doGet is actually executed even if method="post" is in the 
HTML. doPost is never executed and the servlet can't receive any value form 
the HTML page when method="post".
Here it is my coding: 
   lele.html
   lele.java
   web.xml
Please run it and have a look at catalina.out. You'll see what you have typed 
into the field "var2".
Then change in lele.html method="get" to method="post", deploy and run the 
servlet again. You'll see that all variables are now null.  

lele.html  ====================================================================
<html>
<body>
<form name="work" method="get" action="/lele" >
<!-- method="get" works properly
     method="post" doesn't work as supposed, but like a "get" -->
<input type="hidden" name="azione" value="scelta">
<input type="text"   name="matricola">
<input type="submit" value="click here">
</form>
</body>
</html>

lele.java  ==================================================
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class lele extends HttpServlet {
    public void doPost (HttpServletRequest req, HttpServletResponse res) 
throws IOException, ServletException {
	try {
	    String azione    = req.getParameter("azione"); 
	    String matricola = req.getParameter("matricola"); 
	    String method    = req.getMethod(); 
	    System.out.println("doPost: method="+method);
	    System.out.println("doPost: azione="+azione);
	    System.out.println("doPost: matr="+matricola);
	} catch(Exception e) {
	    System.out.println("doPost: errore "+e.toString());
	}
	ServletContext contesto = getServletContext();
	RequestDispatcher rd = contesto.getRequestDispatcher("/lele.html");
	rd.forward(req, res);
    }
    public void doGet (HttpServletRequest req, HttpServletResponse res) throws 
IOException, ServletException {
	try {
	    String azione    = req.getParameter("azione"); 
	    String matricola = req.getParameter("matricola"); 
	    String method    = req.getMethod(); 
	    System.out.println("doGet: method="+method);
	    System.out.println("doGet: azione="+azione);
	    System.out.println("doGet: matr="+matricola);
	} catch(Exception e) {
	    System.out.println("doGet: errore "+e.toString());
	}
	ServletContext contesto = getServletContext();
	RequestDispatcher rd = contesto.getRequestDispatcher("/lele.html");
	rd.forward(req, res);
    }
}

web.xml ====================================================================
<web-app>
    <display-name>Applicazione "lele"</display-name>
     <servlet>
      <servlet-name>lele</servlet-name>
      <description>lele nostra</description>
      <servlet-class>lele</servlet-class>
     </servlet>
     <servlet-mapping>
      <servlet-name>lele</servlet-name>
      <url-pattern>/index.html</url-pattern>
     </servlet-mapping>
    <session-config>
      <session-timeout>30</session-timeout> 
    </session-config>
</web-app>

-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message