本文整理匯總了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();
}