You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Ivo Pletikosic <iv...@benetech.org> on 2004/09/30 20:20:03 UTC

RE: Handling POST in VelocityServlet (RESOLVED)

Hello all,

So the problem is that the form specifies encoding
type:

<form method="post" action="http://127.0.0.1:8181"
enctype="multipart/form-data">

If I remove the encoding:

<form method="post" action="http://127.0.0.1:8181">

then the code previously submitted works.

This is a problem since without specifying the
encoding I cannot use Jakarta Commons FileUpload
(http://jakarta.apache.org/commons/fileupload/) to
process uploads so I need to patch one or the other to
move forward.

Regards,

Ivo



> -----Original Message-----
> From: ivo 
> Sent: Thursday, September 30, 2004 9:47 AM
> To: velocity-user@jakarta.apache.org
> Subject: RE: Handling POST in VelocityServlet
(UPDATED)
> 
> 
> > Hi Ivo,
> 
> Hi Shinobu,
> 
> Thanks for taking the time to clear this up for me.
> 
> > Could you provide us the minimal information to
> reproduce this?
> 
> I am using Jetty 4.2 as a server
> (http://jetty.mortbay.org/jetty/index.html) and
> Velocity 1.4 for servlet and templating. I've
attached
> three files that show the behavior I described.
> 
> ServletServer.java: Creates the Jetty server and the
> adds the VelocityServlet.
> 
> PresentationServlet.java: extends VelocityServlet
and
> implements doPost(), doGet() and handleRequest() to
> all print out the parameters of the request.
> 
> testForm.html: A basic form that submits to
> PresentationServlet .
> 
> On testForm.html, if I have action="GET" then the
> servlet prints out the parameters, if I switch the
> form to action="POST" then nothing is printed. Same
> behavior happens if I comment out doPost() & doGet()
> in the servlet and handleRequest() is uncommented.
> 
> I am sure I am overlooking something very basic.
> 
> Regards,
> 
> Ivo

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: Handling POST in VelocityServlet (RESOLVED)

Posted by Shinobu Kawai <sh...@gmail.com>.
Hi.

> > Hi, I don't think this is a Velocity bug. In your doPost methdd, you
> > need to check
> > FileUpload.isMultipartContent(request). If it's true,  you need to use
> > DiskFileUpload.parseRequest to get the form parameters and file name
> > etc. If not, you can use request.getParameters. This is documented in
> > FileUpload usage.
> Yes, it looks more like a servlet issue.  Check here for other solutions:
>    http://www.magelang.com/faq/view.jsp?EID=1045507
A bit more detail.

If you look in the Java Servlet Specification, under "SRV.4.1.1 When
Parameters Are Available", you will see:

<excerpt>
The following are the conditions that must be met before post form data
will be populated to the parameter set:
1. The request is an HTTP or HTTPS request.
2. The HTTP method is POST.
3. The content type is application/x-www-form-urlencoded.
4. The servlet has made an initial call of any of the getParameter
family of methods on the request object.
</excerpt>

Item #3 says, that if you set any other enctype, they will not be
available via the getParameter methods.

So this is not a bug at all, but a good sign that Jetty is following the
specs.

Best regards,
-- Shinobu Kawai

--
Shinobu Kawai <sh...@gmail.com>


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: Handling POST in VelocityServlet (RESOLVED)

Posted by Shinobu Kawai <sh...@gmail.com>.
Hi.

> Hi, I don't think this is a Velocity bug. In your doPost methdd, you
> need to check
> FileUpload.isMultipartContent(request). If it's true,  you need to use
> DiskFileUpload.parseRequest to get the form parameters and file name
> etc. If not, you can use request.getParameters. This is documented in
> FileUpload usage.
Yes, it looks more like a servlet issue.  Check here for other solutions:
   http://www.magelang.com/faq/view.jsp?EID=1045507

Best regards,
-- Shinobu Kawai

-- 
Shinobu Kawai(shinobu.kawai@gmail.com)

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: Handling POST in VelocityServlet (RESOLVED)

Posted by Howard Lin <xu...@gmail.com>.
Hi, I don't think this is a Velocity bug. In your doPost methdd, you
need to check
FileUpload.isMultipartContent(request). If it's true,  you need to use
DiskFileUpload.parseRequest to get the form parameters and file name
etc. If not, you can use request.getParameters. This is documented in
FileUpload usage.

Howard

On Thu, 30 Sep 2004 11:20:03 -0700 (PDT), Ivo Pletikosic
<iv...@benetech.org> wrote:
> Hello all,
> 
> So the problem is that the form specifies encoding
> type:
> 
> <form method="post" action="http://127.0.0.1:8181"
> enctype="multipart/form-data">
> 
> If I remove the encoding:
> 
> <form method="post" action="http://127.0.0.1:8181">
> 
> then the code previously submitted works.
> 
> This is a problem since without specifying the
> encoding I cannot use Jakarta Commons FileUpload
> (http://jakarta.apache.org/commons/fileupload/) to
> process uploads so I need to patch one or the other to
> move forward.
> 
> Regards,
> 
> Ivo
> 
> > -----Original Message-----
> > From: ivo
> > Sent: Thursday, September 30, 2004 9:47 AM
> > To: velocity-user@jakarta.apache.org
> > Subject: RE: Handling POST in VelocityServlet
> (UPDATED)
> >
> >
> > > Hi Ivo,
> >
> > Hi Shinobu,
> >
> > Thanks for taking the time to clear this up for me.
> >
> > > Could you provide us the minimal information to
> > reproduce this?
> >
> > I am using Jetty 4.2 as a server
> > (http://jetty.mortbay.org/jetty/index.html) and
> > Velocity 1.4 for servlet and templating. I've
> attached
> > three files that show the behavior I described.
> >
> > ServletServer.java: Creates the Jetty server and the
> > adds the VelocityServlet.
> >
> > PresentationServlet.java: extends VelocityServlet
> and
> > implements doPost(), doGet() and handleRequest() to
> > all print out the parameters of the request.
> >
> > testForm.html: A basic form that submits to
> > PresentationServlet .
> >
> > On testForm.html, if I have action="GET" then the
> > servlet prints out the parameters, if I switch the
> > form to action="POST" then nothing is printed. Same
> > behavior happens if I comment out doPost() & doGet()
> > in the servlet and handleRequest() is uncommented.
> >
> > I am sure I am overlooking something very basic.
> >
> > Regards,
> >
> > Ivo
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> 
>

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org