Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSP fails to read POST parameters

 
Aodhan Hoffman
Ranch Hand
Posts: 35
Java MyEclipse IDE Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65225
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Aodhan Hoffman
Ranch Hand
Posts: 35
Java MyEclipse IDE Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65225
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65225
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 35
Java MyEclipse IDE Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65225
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The enctype is still there.
 
Aodhan Hoffman
Ranch Hand
Posts: 35
Java MyEclipse IDE Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic