当前位置: 首页>>代码示例>>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;未经允许,请勿转载。