如何获取servlet中通过dojo.xhrPost发送的数据

发布于 2024-09-06 03:22:57 字数 439 浏览 4 评论 0原文

> 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);

大家好,

我已经用 Javascript 编写了上述代码,用于将数据发送到 servlet。但我不明白如何在 servlet 中获取 postData。

> 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

知你几分 2024-09-13 03:22:57
> 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();            }

通过使用 request.getInputStream 让它工作。
:)

> 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.
:)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文