如何从java servlet中的POST数据中分离查询字符串参数 [英] How do I separate out query string params from POST data in a java servlet

查看:309
本文介绍了如何从java servlet中的POST数据中分离查询字符串参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当您在servlet中获得doGet或doPost调用时,您可以使用 getparameterxxx()在一个简单的位置获取查询字符串或发布数据。 >
如果调用是GET,则从url / query字符串中获取数据。

如果调用是POST,则会获得所有已解析的发布数据。

When you get a doGet or doPost call in a servlet you can use getparameterxxx() to get either the query string or the post data in one easy place.
If the call was a GET, you get data from the url/query string.
If the call was a POST, you get the post data all parsed out for you.

除非事实证明,如果您未在表单调用中添加action属性。
如果为动作参数指定一个完全限定或部分合格的URL,一切都很好,如果你没有,浏览器将调用与上一页提交相同的URL,如果恰好是在那里查询字符串数据,你会得到它以及POST数据,并且没有办法区分它们。

Except as it turns out, if you don't put an 'action' attribute in your form call. If you specify a fully qualified or partially qualified url for the action param everything works great, if you don't, the browser will call the same url as it did on the previous page submit, and if there happens to be query string data there, you'll get that as well as POST data, and there's no way to tell them apart.

或者在那里?
我正在查看请求对象,我看到后期数据的来源,我只是想弄清楚GET数据的来源,所以我可以在post调用和擦除时擦除GET数据如果可能的话,在GET调用之前解析它的帖子数据。

Or is there? I'm looking through the request object, I see where the post data comes from, I'm just trying to figure out where the GET data comes from, so I can erase the GET data on a post call and erase the post data on a GET call before it parses it out if possible.

知道这样做的安全方法是什么?

Any idea what the safe way to do this is?

并猜测:你从未尝试过在表单标签中放置动作字段。 : - )

And lemme guess: you never tried to not put an action field in a form tag. :-)

推荐答案

在HTML中,操作是 REQUIRED ,所以我猜客户端的行为会有所不同。

In HTML, action is REQUIRED, so I guess the behavior will vary among clients.

这篇关于如何从java servlet中的POST数据中分离查询字符串参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆