當前位置: 首頁>>代碼示例>>Java>>正文


Java HttpServletRequest.getReader方法代碼示例

本文整理匯總了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;
    }
}
 
開發者ID:hsj-xiaokang,項目名稱:springboot-shiro-cas-mybatis,代碼行數:24,代碼來源:SamlServiceFactory.java

示例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);
}
 
開發者ID:youngMen1,項目名稱:JAVA-,代碼行數:17,代碼來源:WebUtil.java

示例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");
    }
}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:24,代碼來源:TestInputBuffer.java

示例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();
}
 
開發者ID:supersede-project,項目名稱:replan_optimizer_v2,代碼行數:15,代碼來源:ReplanApiController.java

示例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);
}
 
開發者ID:iBase4J,項目名稱:iBase4J-Common,代碼行數:26,代碼來源:WebUtil.java

示例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();
}
 
開發者ID:allure-framework,項目名稱:allure-java,代碼行數:10,代碼來源:HttpServletAttachmentBuilder.java

示例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 );
    }
}
 
開發者ID:eclipse,項目名稱:neoscada,代碼行數:35,代碼來源:JsonServlet.java

示例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();
}
 
開發者ID:thlcly,項目名稱:Dude,代碼行數:11,代碼來源:DudeController.java

示例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;
    }
}
 
開發者ID:yuweijun,項目名稱:cas-server-4.2.1,代碼行數:25,代碼來源:SamlServiceFactory.java

示例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));
}
 
開發者ID:inkss,項目名稱:hotelbook-JavaWeb,代碼行數:19,代碼來源:InsertLoginServlet.java

示例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));
    }
 
開發者ID:inkss,項目名稱:hotelbook-JavaWeb,代碼行數:28,代碼來源:InsertRoomTypeServlet.java

示例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;
    }
}
 
開發者ID:mrluo735,項目名稱:cas-5.1.0,代碼行數:19,代碼來源:SamlServiceFactory.java

示例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);
}
 
開發者ID:uavorg,項目名稱:uavstack,代碼行數:15,代碼來源:SimpleServlet.java

示例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();
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:30,代碼來源:IMSPOXRequest.java

示例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"));
    }
}
 
開發者ID:ibaca,項目名稱:autorest-streaming-example,代碼行數:6,代碼來源:Servlet.java


注:本文中的javax.servlet.http.HttpServletRequest.getReader方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。