wood burning stoves 2.0*
The moose likes JSP and the fly likes JSP fails to read POST parameters Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "JSP fails to read POST parameters" Watch "JSP fails to read POST parameters" New topic
Author

JSP fails to read POST parameters

Aodhan Hoffman
Ranch Hand

Joined: May 21, 2004
Posts: 35

I am building a simple form to play with different JSP styles. I wanted to get POSt to work but found I couldn't.
When I submit the form to my JSP using GET, everything works. Everything fails using POST.

the page is very simple:

<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<html>
<head><title>JSP Page</title></head>
<body>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<c:if test="${pageContext.request.method=='POST'}">
<p/>Congrats, you managed to POST!
</c:if>

<c:if test="${pageContext.request.method=='GET'}">
<p/>Congrats, you got GET
</c:if>

<c:if test="${pageContext.request.method=='null'}">
<p/>WTF?
</c:if>
<table border="1" bgcolor="blue">
<tr><td>company</td><td>${param["company"]}</td><td>${company}</td>
<td>${param["company"]}</td></tr>

</table>

You entered:<br>
company <c ut value="${param.company}" /><br>
street_address: <c ut value="${param.street_address}" /><br>
Email Address: <c ut value="${param.contact_email}" /><br>
contact_email: <c ut value="${param.req_id}" /><br>
modification_date: <c ut value="${param.modification_date}" /><br>
modification_date:
<c ut value="${current}" /> 
<%= request.getParameter("modification_date")%>

</body>
</html>

this is the output:

Congrats, you managed to POST!

company
You entered:
company
street_address:
Email Address:
contact_email:
modification_date:
modification_date: � null

I get this same response wether using Safari or Firefox.
I'm using the bundled Tomcat 5.5.x server with NetBeans 4.1rc1 on OSX 10.3.
I've tried setting the form to charset=iso-8859-1 and charset=UTF-8.

Thoughts? I really want to get this working via POST.


-------<br /> Aodhan H - Ad Astra Per Aspera<br /> -------
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60766
    
  65

What does the source page with the form on it look like? Is the only difference between what's working and what's not the method attribute on the form?

Also. please use UBB code tags around your posted code to preserve the formatting.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Aodhan Hoffman
Ranch Hand

Joined: May 21, 2004
Posts: 35

Sorry abt the excess UBB codes, first time I ran into that.

Here is the only line of my html form that I change

This fails:

This works:

I've tried this as it was suggested elsewhere in this forum:
but the browser does not recognize the method and defaults to GET. ( I know this because of the IF block in my JSP. )

I've also tried different capitalization, but that had no meaningful effect. ( which it shouldn't )
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60766
    
  65

Remove the enctype attribute. It's not for settting the content type of the response as you seem to be thinking it is, but rather specifies the encoding mechanism of the parameters. if it's not the default encoding type (which is application/x-www-form-urlencoded) then the container will not parse out the parameters.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60766
    
  65

P.S. The GET works because in a GET, the paramters are not encoded as part of the request as they are in a POST.
Aodhan Hoffman
Ranch Hand

Joined: May 21, 2004
Posts: 35

Thanks for the suggestion, but no joy. I still got no data in the request object.

Here is the html of the form as it is now:


and the JSP page that processes it as it is now:


and the result:


Is there a separate object that the POST data is placed into? Is there another method I should be using to access POST data? Is there a known issue relating to MacOS implementation of Java that I haven't otherwise run into?

I appreciate your assistance.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60766
    
  65

The enctype is still there.
Aodhan Hoffman
Ranch Hand

Joined: May 21, 2004
Posts: 35

Doh! Sorry, I misunderstood your suggestion.

Bingo!

Removing the enctype did the trick, not something I would have thought of at all because I thought everything, including the POST data, was /supposed/ to be text/html.

I changed the form declaration:


This is what I get now:


Many thanks for your time and input.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JSP fails to read POST parameters
 
Similar Threads
Dynamic population of second list box based on selection of first
java. lang. IllegalStateException: Neither Binding Result nor plain target object
JSP Struts/JSTL Form problem
How to include servlet response in a JSP?
javascript error: object expected