How to send hashmap with a file using Servlet in GWT

471 views
Skip to first unread message

learning coding

unread,
Jun 6, 2012, 9:47:32 AM6/6/12
to Google Web Toolkit
I want to know or some code sample which will help me to send the file
and the hashmap to the server.

To upload a file to GWt server i use formpanel and a HttpServlet. this
is working fine.

i have a hashmap

private static Map<String, List<Customproperties>> docClass =
new HashMap<String, List<Customproperties>>();


which holds the property of document according to its classname.

I know how to do with RPC to send hashMap. but i want to do with
servlet.As i have to upload a file which i have done with servlet. And
every Hashmap is related to file .and this file with its property(in
HashMap) will send to external repository.

Please help.

Thad

unread,
Jun 6, 2012, 3:23:22 PM6/6/12
to google-we...@googlegroups.com
First thought: Convert the map to an com.google.gwt.json.client.JSONObject on the client and send that as a String via POST to the servlet. On the server side turn that string into an org.json.JSONObject (http://www.json.org/) and from that recreate the map.

Joseph Lust

unread,
Jun 6, 2012, 7:30:03 PM6/6/12
to google-we...@googlegroups.com
Or, if possible, use GWT-RPC and send as many HashMaps through a basic Async interface as you like.

Sincerely,
Joseph

learning coding

unread,
Jun 7, 2012, 5:01:10 AM6/7/12
to Google Web Toolkit
Hi,
thanks for you reply.
Do you think its agood practice to mix JSON with AJAX.
I made my AJAX front End in the JAVA programming Language.
and also my back end is also Java.
> server side turn that string into an org.json.JSONObject (http://www.json.org/) and from that recreate the map.- Hide quoted text -
>
> - Show quoted text -

learning coding

unread,
Jun 7, 2012, 5:07:18 AM6/7/12
to Google Web Toolkit
I know how to use RPC in GWT, but i have file and the hashmap has a
property of that file.

this file with the property is send to server with and after that to
external repository.

for sending the file i created servlet. but dont know how to pass the
hashmap at the same time to the server.

Thad

unread,
Jun 7, 2012, 11:44:03 AM6/7/12
to google-we...@googlegroups.com
On Thursday, June 7, 2012 5:01:10 AM UTC-4, learning coding wrote:
Hi,
thanks for you reply.
Do you think its agood practice to mix JSON with AJAX.
I made my AJAX front End in the JAVA programming Language.
and also my back end is also Java. 

Someone else will have to answer that for you. I'm using GWT RPC almost exclusively. When I use JSON it's as I described--send a JSONObject as a string, parse it back to a JSONObject, and process. There are places in my project that it's the handiest format available.
 
On Jun 6, 9:23 pm, Thad <thad.humphr...@gmail.com> wrote:
> On Wednesday, June 6, 2012 9:47:32 AM UTC-4, learning coding wrote:
>
> > I want to know or some code sample which will help me to send the file
> > and the hashmap to the server.
>
> > To upload a file to GWt server i use formpanel and a HttpServlet. this
> > is working fine.
>
> > i have a hashmap
>
> >     private static Map<String, List<Customproperties>> docClass =
> >  new HashMap<String, List<Customproperties>>();
>
> > which holds the property of document according to its classname.
>
> > I know how to do with RPC to send hashMap. but i want to do with
> > servlet.As i have to upload a file which i have done with servlet. And
> > every Hashmap is related to file .and this file with its property(in
> > HashMap) will send to external repository.
>
> > Please help.
>
> First thought: Convert the map to an com.google.gwt.json.client.JSONObject
> on the client and send that as a String via POST to the servlet. On the
> server side turn that string into an org.json.JSONObject (http://www.json.org/) and from that recreate the map.- Hide quoted text -
>
> - Show quoted text -

Reply all
Reply to author
Forward
0 new messages