精华内容
下载资源
问答
  • 出于分页目的,我们的UI人员在Http标头中指定项目范围,如下所示:Range: items=0-15在随后的请求中,来自web的范围可以是Range: items=16-31Range: items=32-45…等…等在我的控制器SearchRequestController.java中,我...

    出于分页目的,我们的UI人员在Http标头中指定项目范围,如下所示:

    Range: items=0-15

    在随后的请求中,来自web的范围可以是

    Range: items=16-31

    Range: items=32-45

    …等…等

    在我的控制器SearchRequestController.java中,我试图提取这些范围,以便我可以将它发送到Solr服务器,通过设置开始和偏移量来返回请求的卡盘中的值.

    我正在做的如下(在SearchRequestController.java中):

    @RequestMapping("/billsSearch")

    @ResponseBody

    public SearchResult searchBills(HttpServletRequest request,@RequestBody SearchRequest searchRequest){

    String rangeRequest = request.getHeader("Range");

    //(1)Parse the rangeRequest using some mechanism

    //(2)Set the start using the first value of the range

    //(3) Add the second value to the start to get the offset

    searchRequest.setStart(startValue);

    searchRequest.setOffset(offsetValue);

    return searchHelper(request,searchRequest);

    }

    我有几个问题:

    这是从服务器以分块方式请求数据的最佳方式吗?

    如何从请求标头中提取范围?

    我假设request.getHeader(“Range”)将返回“items = 16-31”.

    正则表达式是从这个字符串中获取16和31的最佳方法吗?

    如果我决定使用正则表达式,如果我将范围标题更改为billItems = 16-31,表达式是否会中断?

    我是一个正则表达式n00b,所以我很可能以错误的方式思考这个问题.

    是否有正则表达式的替代方法可以从SpringMVC中的http标头解析这样的范围信息?

    展开全文
  • //header.jspout.println("Protocol: " + request.getProtocol() + "");out.println("Scheme: " + request.getScheme() + "");out.println("Server Name: " + request.getServerName() + "" );out.println("Server P...

    //header.jsp

    out.println("Protocol: " + request.getProtocol() + "
    ");

    out.println("Scheme: " + request.getScheme() + "
    ");

    out.println("Server Name: " + request.getServerName() + "
    " );

    out.println("Server Port: " + request.getServerPort() + "
    ");

    out.println("Protocol: " + request.getProtocol() + "
    ");

    out.println("Server Info: " + getServletConfig().getServletContext().getServerInfo() + "
    ");

    out.println("Remote Addr: " + request.getRemoteAddr() + "
    ");

    out.println("Remote Host: " + request.getRemoteHost() + "
    ");

    out.println("Character Encoding: " + request.getCharacterEncoding() + "
    ");

    out.println("Content Length: " + request.getContentLength() + "
    ");

    out.println("Content Type: "+ request.getContentType() + "
    ");

    out.println("Auth Type: " + request.getAuthType() + "
    ");

    out.println("HTTP Method: " + request.getMethod() + "
    ");

    out.println("Path Info: " + request.getPathInfo() + "
    ");

    out.println("Path Trans: " + request.getPathTranslated() + "
    ");

    out.println("Query String: " + request.getQueryString() + "
    ");

    out.println("Remote User: " + request.getRemoteUser() + "
    ");

    out.println("Session Id: " + request.getRequestedSessionId() + "
    ");

    out.println("Request URL: " + request.getRequestURL() + "
    ");

    out.println("Request URI: " + request.getRequestURI() + "
    ");

    out.println("Servlet Path: " + request.getServletPath() + "
    ");

    out.println

    展开全文
  • java获取前端请求字段的方法package test.request;import java.io.IOException;import java.io.InputStream;import java.lang.reflect.InvocationTargetException;import java.util.Enumeration;import java.util....

    java获取前端请求字段的方法

    package test.request;

    import java.io.IOException;

    import java.io.InputStream;

    import java.lang.reflect.InvocationTargetException;

    import java.util.Enumeration;

    import java.util.Map;

    import javax.servlet.ServletException;

    import javax.servlet.http.HttpServlet;

    import javax.servlet.http.HttpServletRequest;

    import javax.servlet.http.HttpServletResponse;

    import com.sun.org.apache.commons.beanutils.BeanUtils;

    //HttpServletRequest获取请求头和请求数据

    //请求数据一半来说要先检查再使用,检查非空和不是空格

    public class RequestDemo2 extends HttpServlet {

    public void doGet(HttpServletRequest request, HttpServletResponse response)

    throws ServletException, IOException {

    System.out.println("---------获取请求数据方式1-------------");

    // 获取指定的请求数据

    String value = request.getParameter("username");

    if (value != null && !value.trim().equals("")) {

    System.out.println(value);

    }

    System.out.println("---------获取请求数据方式2-------------");

    // 获取所有的请求数据

    Enumeration e = request.getParameterNames();

    while (e.hasMoreElements()) {

    String paramName = (String) e.nextElement();

    String value2 = request.getParameter(paramName);

    System.out.println(paramName + "=" + value2);

    }

    System.out.println("---------获取请求数据方式3-------------");

    // 获取所有的请求数据,同名的只能获取一次,就是第一次

    String[] values = request.getParameterValues("username");

    for (int i = 0; values != null && i < values.length; i++) {

    System.out.println(values[i]);

    }

    System.out.println("---------获取请求数据方式4-------------");

    // 这个特别实用,框架的模型驱动,这个Map的value肯定是String数组类型,因为有同名的请求数据

    // 实际开发中是不会 request.getParameter("username");用这种方式的,都是要创建一个model的

    Map map = request.getParameterMap();

    User user = new User();

    try {

    // 用map中的数据填充bean

    BeanUtils.populate(user, map);

    } catch (IllegalAccessException e1) {

    e1.printStackTrace();

    } catch (InvocationTargetException e1) {

    e1.printStackTrace();

    }

    System.out.println(user.getPassword());

    System.out.println("---------获取请求数据方式5-------------");

    // request.getInputStream();是上传文件的时候获取数据的方式

    // 普通数据是获取不到的

    InputStream in = request.getInputStream();

    int len = 0;

    byte[] buffer = new byte[1024];

    while ((len = in.read(buffer)) > 0) {

    System.out.println(new String(buffer, 0, len));

    }

    }

    // 获取请求头

    private void test1(HttpServletRequest request) {

    System.out.println("---------获取请求头方式1-------------");

    // 拿到指定的请求头

    System.out.println(request.getHeader("cache-control"));

    System.out.println("---------获取请求头方式2-------------");

    // 拿到所有指定的请求头

    Enumeration e = request.getHeaders("cache-control");

    while (e.hasMoreElements()) {

    String headValue = (String) e.nextElement();

    System.out.println(headValue);

    }

    System.out.println("---------获取请求头方式3-------------");

    // 拿到所有请求头

    Enumeration e1 = request.getHeaderNames();

    while (e1.hasMoreElements()) {

    String headerName = (String) e1.nextElement();

    String headValue = request.getHeader(headerName);

    System.out.println(headerName + "=" + headValue);

    }

    }

    public void doPost(HttpServletRequest request, HttpServletResponse response)

    throws ServletException, IOException {

    doGet(request, response);

    }

    }

    展开全文
  • 转载地址:http://blog.csdn.net/pursue168/article/details/6205105类似的方法在java代码中也能用,其中用request.getMethid()方法获取请求类型GET POST//header.jspout.println("Protocol: " + request....

    转载地址:http://blog.csdn.net/pursue168/article/details/6205105

    类似的方法在java代码中也能用,其中用request.getMethid()方法获取请求类型GET POST

    //header.jsp

    out.println("Protocol: " + request.getProtocol() + "
    ");

    out.println("Scheme: " + request.getScheme() + "
    ");

    out.println("Server Name: " + request.getServerName() + "
    " );

    out.println("Server Port: " + request.getServerPort() + "
    ");

    out.println("Protocol: " + request.getProtocol() + "
    ");

    out.println("Server Info: " + getServletConfig().getServletContext().getServerInfo() + "
    ");

    out.println("Remote Addr: " + request.getRemoteAddr() + "
    ");

    out.println("Remote Host: " + request.getRemoteHost() + "
    ");

    out.println("Character Encoding: " + request.getCharacterEncoding() + "
    ");

    out.println("Content Length: " + request.getContentLength() + "
    ");

    out.println("Content Type: "+ request.getContentType() + "
    ");

    out.println("Auth Type: " + request.getAuthType() + "
    ");

    out.println("HTTP Method: " + request.getMethod() + "
    ");

    out.println("Path Info: " + request.getPathInfo() + "
    ");

    out.println("Path Trans: " + request.getPathTranslated() + "
    ");

    out.println("Query String: " + request.getQueryString() + "
    ");

    out.println("Remote User: " + request.getRemoteUser() + "
    ");

    out.println("Session Id: " + request.getRequestedSessionId() + "
    ");

    out.println("Request URL: " + request.getRequestURL() + "
    ");

    out.println("Request URI: " + request.getRequestURI() + "
    ");

    out.println("Servlet Path: " + request.getServletPath() + "
    ");

    out.println("Created : " + session.getCreationTime() + "
    ");

    out.println("LastAccessed : " + session.getLastAccessedTime() + "
    ");

    out.println("Accept: " + request.getHeader("Accept") + "
    "); out.println("Host: " + request.getHeader("Host") + "
    "); out.println("Referer : " + request.getHeader("Referer") + "
    "); out.println("Accept-Language : " + request.getHeader("Accept-Language") + "
    "); out.println("Accept-Encoding : " + request.getHeader("Accept-Encoding") + "
    "); out.println("User-Agent : " + request.getHeader("User-Agent") + "
    "); out.println("Connection : " + request.getHeader("Connection") + "
    "); out.println("Cookie : " + request.getHeader("Cookie") + "
    "); %>

    展开全文
  • java 获取HttpRequest Header

    千次阅读 2018-07-04 17:10:05
    Enumeration<String> headerValues = request.getHeaders(headerName); while (headerValues.hasMoreElements()) {  System.out.println(headerName + ":"+ headerValues.nextElement()); } }
  • 下面小编就为大家带来一篇java 获取HttpRequest Header的几种方法(必看篇)。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
  • 本文中演示如何通过URLConnection获取Http响应Header信息1.从响应中获得Header信息URL obj = new URL("http://www.qiyadeng.com");URLConnection conn = obj.openConnection();...2.从响应Header获取Server信息...
  • 然后自己可以根据一些要求处理业务逻辑了 JSP/Java获取HTTP header信息(request)例子 //header.jsp out.println("Protocol: " + request.getProtocol() + " "); out.println("Scheme: " + request.getScheme() + " ...
  • import java.io.IOException; import java.net.URL; import java.net.URLConnection; import java.util.Map; import java.util.Set; public class CheckHttpResposneHeaders { public static void main...
  • Oracle基本操作汇总--10g 新增的表空间类型:大文件 (Bigfile) 表空间.--10g 数据库在创建的时候,会指定默认的表空间类型.如果不特殊指定的话,默认为 SMALLFILE 类型的表空间.SELECT * ...OGNL valueStack Stack...
  • java 获取HttpRequest Header 的几种方法

    万次阅读 2016-09-27 12:52:39
    再加一个方法   Spring mvc中的@RequestHeader  @RequestHeader 注解,可以把...Java代码  @RequestMapping(value = "/example", method = RequestMethod.GET)   public String g...
  • "); out.println("Scheme: " + request.getScheme() + ""); out.println("Server Name: " + request.getServerName() + "" ); out.println("Server Port: " + request.getServerPort() + ""); out.println("Protocol...
  • 在http请求中,有Header和...读取Body使用request.getReader(),但getReader获取的是BufferedReader,需要把它转换成字符串,下面是转换的方法。public class TestController {@RequestMapping("/a")protected void...
  • 在http请求中,有header和...读取body使用request.getreader(),但getreader获取的是bufferedreader,需要把它转换成字符串,下面是转换的方法。public class testcontroller {@requestmapping("/a")protected void...
  • java 获取HttpRequest Header的几种方法

    万次阅读 2018-02-02 11:33:09
    JSP/Java获取HTTP header信息(request)例子 ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 ...
  • 在http请求中,有Header和...读取Body使用request.getReader(),但getReader获取的是BufferedReader,需要把它转换成字符串,下面是转换的方法。public class TestController {@RequestMapping("/a")protected void...
  • 下面小编就为大家带来一篇java获取http请求的Header和Body的简单方法。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
  • 本文中演示如何通过URLConnection获取Http响应Header信息 1.从响应中获得Header信息 URL obj = new URL("http://www.qiyadeng.com"); URLConnection conn = obj.openConnection(); M...
  • JSP/Java获取HTTP header信息(request)例子

    千次阅读 2016-11-16 15:04:39
    转载地址:... 类似的方法在java代码中也能用,其中用request.getMethid()方法获取请求类型GET POST //header.jsp out.println("Protocol: " + request.getProtocol() + ""); out.p
  • 请问怎么通过Java获取Webservice的SOAP Header值。 我可以显示出Header,但就是获取不到具体的一个值出来。 显示出Header的代码是: SOAPHeader header = null; try { header =MessageContext....
  • 在开发过程中,我们请求后台接口时,有时需要携带一些必要的...读取Body使用request.getReader(),但getReader获取的是BufferedReader,需要把它转换成字符串,下面是转换的方法 public class TestController { @Requ
  • java获取http requestheader 的请求头大小

    千次阅读 2018-08-29 13:53:59
    Enumeration headerNames = request.getHeaderNames(); int length = 0; while (null != headerNames && headerNames.hasMoreElements()){ String key = (String)...这样就可以获取Header中所有内容的大小了 

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 875
精华内容 350
关键字:

java获取header

java 订阅