本文整理汇总了Java中javax.servlet.http.HttpServletRequest.getReader方法的典型用法代码示例。如果您正苦于以下问题:Java HttpServletRequest.getReader方法的具体用法?Java HttpServletRequest.getReader怎么用?Java HttpServletRequest.getReader使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.servlet.http.HttpServletRequest
的用法示例。
在下文中一共展示了HttpServletRequest.getReader方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getRequestBody
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
/**
* Gets the request body from the request.
*
* @param request the request
* @return the request body
*/
private String getRequestBody(final HttpServletRequest request) {
final StringBuilder builder = new StringBuilder();
try (BufferedReader reader = request.getReader()) {
if (reader == null) {
logger.debug("Request body could not be read because it's empty.");
return null;
}
String line;
while ((line = reader.readLine()) != null) {
builder.append(line);
}
return builder.toString();
} catch (final Exception e) {
logger.trace("Could not obtain the saml request body from the http request", e);
return null;
}
}
示例2: getParameter
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public static Map<String, Object> getParameter(HttpServletRequest request) {
String str, wholeStr = "";
try {
BufferedReader br = request.getReader();
while ((str = br.readLine()) != null) {
wholeStr += str;
}
if (StringUtils.isNotBlank(wholeStr)) {
return JSON.parseObject(wholeStr, Map.class);
}
} catch (Exception e) {
logger.error("", e);
}
return getParameterMap(request);
}
示例3: doPost
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
req.setCharacterEncoding("UTF-8");
Reader r = req.getReader();
resp.setCharacterEncoding("UTF-8");
resp.setContentType("text/plain");
Writer w = resp.getWriter();
try {
// Copy one character at a time
int c = r.read();
while (c != -1) {
w.write(c);
c = r.read();
}
w.close();
} catch (MalformedInputException mie) {
resp.resetBuffer();
w.write("FAILED");
}
}
示例4: requestContentAsString
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
private String requestContentAsString(HttpServletRequest request) {
StringBuffer buffer = new StringBuffer();
String line = null;
try {
BufferedReader reader = request.getReader();
while ((line = reader.readLine()) != null)
buffer.append(line);
} catch (Exception e) {
e.printStackTrace();
return null;
}
return buffer.toString();
}
示例5: getParameters
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
@SuppressWarnings({ "unchecked", "rawtypes" })
public static <T> List<T> getParameters(HttpServletRequest request, Class<T> cls) {
String str, wholeStr = "";
try {
BufferedReader br = request.getReader();
while ((str = br.readLine()) != null) {
wholeStr += str;
}
if (StringUtils.isNotBlank(wholeStr)) {
logger.info("request===>" + wholeStr);
List list = JSON.parseObject(wholeStr, List.class);
List<T> resultList = InstanceUtil.newArrayList();
for (Object map : list) {
T t = (T) InstanceUtil.transMap2Bean((Map) map, cls);
resultList.add(t);
}
request.setAttribute("iBase4J.Parameters", resultList);
return resultList;
}
} catch (Exception e) {
logger.error("", e);
}
logger.info("request===>" + JSON.toJSONString(request.getParameterMap()));
return Request2ListUtil.covert(cls, request);
}
示例6: getBody
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
public static String getBody(final HttpServletRequest request) {
final StringBuilder sb = new StringBuilder();
try (BufferedReader reader = request.getReader()) {
readBody(sb, reader);
} catch (IOException e) {
LOGGER.warn("Could not read request body", e);
}
return sb.toString();
}
示例7: doPost
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
@Override
protected void doPost ( final HttpServletRequest request, final HttpServletResponse response ) throws ServletException, IOException
{
if ( request.getPathInfo () == null )
{
send404Error ( request, response );
return;
}
if ( request.getPathInfo ().equals ( "/publish" ) || request.getPathInfo ().equals ( "/publish/" ) )
{
// read input
final BufferedReader reader = request.getReader ();
final char[] buffer = new char[4 * 1024];
int len;
final StringBuilder sb = new StringBuilder ();
while ( ( len = reader.read ( buffer, 0, buffer.length ) ) != -1 )
{
sb.append ( buffer, 0, len );
}
final Event event = EventSerializer.deserializeEvent ( sb.toString () );
this.injector.injectEvent ( event, new InjectionContext.Builder ().sourceModule ( "org.eclipse.scada.ae.server.http" ).build () );
// return output
response.setContentType ( "text/plain" );
final PrintWriter pw = new PrintWriter ( response.getOutputStream () );
pw.write ( "OK" );
pw.close ();
}
else
{
send404Error ( request, response );
}
}
示例8: _readJsonFromRequest
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
private String _readJsonFromRequest(HttpServletRequest request) throws IOException {
StringBuilder sb = new StringBuilder();
try (BufferedReader br = request.getReader()) {
String line;
while ((line = br.readLine()) != null) {
sb.append(line);
}
}
return sb.toString();
}
示例9: getRequestBody
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
/**
* Gets the request body from the request.
*
* @param request the request
* @return the request body
*/
private String getRequestBody(final HttpServletRequest request) {
final StringBuilder builder = new StringBuilder();
try (final BufferedReader reader = request.getReader()) {
if (reader == null) {
logger.debug("Request body could not be read because it's empty.");
return null;
}
String line;
while ((line = reader.readLine()) != null) {
builder.append(line);
}
return builder.toString();
} catch (final Exception e) {
logger.trace("Could not obtain the saml request body from the http request", e);
return null;
}
}
示例10: doGet
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
request.setCharacterEncoding("utf-8");
response.setContentType("application/json; charset=utf-8");
// 获取前端传递的json数据
BufferedReader reader = request.getReader();
String json = reader.readLine();
// 解析json
Gson gson = new Gson();
Login login = gson.fromJson(json, Login.class);
LoginService service = new LoginServiceImpl();
int code = service.insertLogin(login);
PrintWriter out = response.getWriter();
out.print(gson.toJson(code));
}
示例11: doGet
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
request.setCharacterEncoding("utf-8");
response.setContentType("application/json; charset=utf-8");
// 获取前端传递的json数据
BufferedReader reader = request.getReader();
String json = reader.readLine();
// 解析json
Gson gson = new Gson();
RoomType roomType = gson.fromJson(json, RoomType.class);
//主键ID没有想好暂时就用时间吧
Date day = new Date();
SimpleDateFormat df = new SimpleDateFormat("yyMMddHHmmss");
roomType.setTypeId("RT" + df.format(day));
// 调用service
RoomTypeService service = new RoomTypeServiceImpl();
PrintWriter out = response.getWriter();
int code = service.insertRoomType(roomType);
//code 1:插入成功 0:存在同名项 -1:插入失败
out.print(gson.toJson(code));
}
示例12: getRequestBody
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
/**
* Gets the request body from the request.
*
* @param request the request
* @return the request body
*/
private static String getRequestBody(final HttpServletRequest request) {
try(BufferedReader reader = request.getReader()) {
if (reader == null) {
LOGGER.debug("Request body could not be read because it's empty.");
return null;
}
return reader.lines().collect(Collectors.joining());
} catch (final Exception e) {
LOGGER.trace("Could not obtain the saml request body from the http request", e);
return null;
}
}
示例13: service
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
BufferedReader reader = req.getReader();
String str, wholeStr = "";
while ((str = reader.readLine()) != null) {
wholeStr += str;
}
System.out.println(wholeStr);
OutputStream outputStream = resp.getOutputStream();
byte[] dataByteArr = wholeStr.getBytes("UTF-8");
outputStream.write(dataByteArr);
}
示例14: loadFromRequest
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
public void loadFromRequest(HttpServletRequest request)
{
String contentType = request.getContentType();
if ( ! "application/xml".equals(contentType) ) {
errorMessage = "Content Type must be application/xml";
Log.info(errorMessage+"\n"+contentType);
return;
}
setAuthHeader(request.getHeader("Authorization"));
if ( oauth_body_hash == null ) {
errorMessage = "Did not find oauth_body_hash";
Log.info(errorMessage+"\n"+header);
return;
}
try {
Reader in = request.getReader();
postBody = readPostBody(in);
} catch(Exception e) {
errorMessage = "Could not read message body:"+e.getMessage();
return;
}
validatePostBody();
if (errorMessage != null) return;
parsePostBody();
}
示例15: read
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
public static String read(HttpServletRequest input) throws IOException {
try (BufferedReader reader = input.getReader()) {
return reader.lines().collect(Collectors.joining("\n"));
}
}