I have a Filter that receives th开发者_如何学Pythone HttpServletRequest and the request is a POST that consists of an xml that I need to read into my filter method. What is the best way to get the posted xml from the HttpServletRequest object.
That depends on how the client has sent it.
If it's been sent as the raw request body, then use ServletRequest#getInputStream()
:
InputStream xml = request.getInputStream();
// ...
If it's been sent as a regular application/x-www-form-urlencoded
request parameter, then use ServletRequest#getParameter()
:
String xml = request.getParameter("somename");
// ...
If it's been sent as an uploaded file in flavor of a multipart/form-data
part, then use HttpServletRequest#getPart()
.
InputStream xml = request.getPart("somename").getInputStream();
// ...
That were the ways supported by the standard servlet API. Other ways may require a different or 3rd party API (e.g. SOAP).
精彩评论