tags:

views:

79

answers:

2
> var xhrArgs = {
>              url: '/mum/proxy/http/localhost:8080/DemoProject/MyServlet',
>              postData:' MyDataToBeSend',
>              handleAs: 'text',
>              load: function(data) { },
>              error: function(error) {alert(error);}}; var ret =
> dojo.xhrGet(xhrArgs);

Hi All,

I have written the above code in Javascript to send data to a servlet. But I am not understanding how to get the postData in the servlet.

A: 

Hi all, I am trying to receive the data ('myDataToBeSend') in the servlet, but still no success. Kindly help me out.

Regards, Snell

snell
A: 
> try {
>              PrintWriter out = response.getWriter();  
>              InputStream is = request.getInputStream();
>              BufferedReader reader = null;
>               reader = new BufferedReader(new InputStreamReader(is));
>               String text = null;
>                            Writer writer = null;
>               File file = new File("c:\\logMine.txt");
>               writer = new BufferedWriter(new FileWriter(file, true));
>               while ((text = reader.readLine()) != null) {
>                       writer.write("FUNCTION : " +text + "\n");
>                       }
>               writer.flush();
>               writer.close();
>               } 
>               catch (FileNotFoundException e) {
>               e.printStackTrace();
>               } catch (IOException e) {
>               e.printStackTrace();            }

Got it working by useing request.getInputStream. :)

snell