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