我有一个POST
请求,如下所示:
<form action="get_eD_XML" method="POST">
<input type='text' name='data'value='<ClinicalDocument xmlns="urn:hl7-org:v3" xmlns:epsos="urn:epsos-org:ep:medication" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">...</ClinicalDocument>' />
<input type="submit" value="Test" />
</form>
我正在尝试使用以下方法获取值:
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
BufferedReader in = new BufferedReader(
new InputStreamReader(request.getInputStream(), "UTF-8"));
JSONObject responseJSON = new JSONObject();
String inputLine;
String data = "";
while ((inputLine = in.readLine()) != null) {
data =inputLine.replace("data=", "");
}
System.out.println(data);
}
但是,数据内容类似于:
%3CClinicalDocument+xmlns%3D%22urn%3Ahl7-org%3Av3%22+xmlns%3Aepsos%3D%22urn%3Aepsos-org%3Aep%3Amedication%22+xmlns%3Axsi%3D%22http%3A%2F%2Fwww.w3.org%2F2001%2FXMLSchema-instance%22%3E%
您知道如何解决此问题吗?
答案 0 :(得分:2)
您可以使用request.getParameterNames()
来获取传递给该请求的参数。
其中应包含值“ data”。
调用request.getParameterValues("data")
可以获取该参数的解码值。
答案 1 :(得分:0)
您是否尝试过使用apache.commons.io?
public String convert(InputStream inputStream, Charset charset) throws IOException {
return IOUtils.toString(inputStream, charset);
}
这是POM条目
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.5</version>
</dependency>