gwt FormPanel & servlet integration

545 views
Skip to first unread message

hbaydarov

unread,
Oct 29, 2010, 2:24:57 AM10/29/10
to Google Web Toolkit
I'm just writing a simple FormPanel and a servlet that handle it.
However, there is a problem while getting parameter from FormPanel.
What I want to say :

formPanel = new FormPanel();
formPanel.setAction(ACTION_URL);
formPanel.setEncoding(FormPanel.ENCODING_MULTIPART);
formPanel.setMethod(FormPanel.METHOD_POST);

absolutePanel = new AbsolutePanel();
formPanel.setWidget(absolutePanel);
absolutePanel.setSize("348px", "100%");

nameField = new TextBox();
absolutePanel.add(nameField, 94, 50);
nameField.getElement().setId("name");
nameField.setName("name");
When I tried to get the name value from the servlet it returns null :

protected void doPost(HttpServletRequest req, HttpServletResponse
resp)
throws ServletException, IOException {

System.out.println(req.getParameter("name")); // null! why?
}

What is the problem with that code? How can I get the value from gwt
FormPanel in servlet?

Thanks,

//http://stackoverflow.com/questions/4049312/gwt-formpanel-servlet-
integration

David Chandler

unread,
Oct 29, 2010, 11:07:51 AM10/29/10
to google-we...@googlegroups.com
hbaydarov,

How are you submitting the form?

> --
> You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
> To post to this group, send email to google-we...@googlegroups.com.
> To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
>
>

--
David Chandler
Developer Programs Engineer, Google Web Toolkit
http://googlewebtoolkit.blogspot.com/

Thomas Broyer

unread,
Oct 29, 2010, 11:45:47 AM10/29/10
to Google Web Toolkit


On 29 oct, 08:24, hbaydarov <hbayda...@gmail.com> wrote:
> I'm just writing a simple FormPanel and a servlet that handle it.
> However, there is a problem while getting parameter from FormPanel.
> What I want to say :
>
>     formPanel.setEncoding(FormPanel.ENCODING_MULTIPART);
>     formPanel.setMethod(FormPanel.METHOD_POST);

[...]

> protected void doPost(HttpServletRequest req, HttpServletResponse
> resp)
>         throws ServletException, IOException {
>
>     System.out.println(req.getParameter("name")); // null! why?

getParameter only works when data is sent in application/x-www-form-
urlencoded (as multipart/form-data might be very big and contain
attached files, it would cost too much to parse it ahead from a
getParameter(), and getParameter won't give you the uploaded files).
You have to use something like Apache Commons FileUpload to read/
decode a multipart/form-data payload: http://commons.apache.org/fileupload/
Reply all
Reply to author
Forward
0 new messages