本文整理汇总了Java中javax.servlet.ServletRequest.getReader方法的典型用法代码示例。如果您正苦于以下问题:Java ServletRequest.getReader方法的具体用法?Java ServletRequest.getReader怎么用?Java ServletRequest.getReader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.servlet.ServletRequest
的用法示例。
在下文中一共展示了ServletRequest.getReader方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getRequestBody
import javax.servlet.ServletRequest; //导入方法依赖的package包/类
/**
* Returns with the request body as a string. Since this method is responsible to close the request reader this
* method can be invoked only once from the client.
*
* @param req
* the servlet request.
* @return the request body as a string.
* @throws IOException
* if reading the request body failed.
*/
private String getRequestBody(final ServletRequest req) throws IOException {
final StringBuilder sb = new StringBuilder();
try (final BufferedReader br = req.getReader();) {
String line = null;
while (null != (line = br.readLine())) {
sb.append(line);
}
}
return sb.toString();
}