两个方法不能同时用的
只能用一个
用了QueryString,参数只能自己截了。

解决方案 »

  1.   

    问题是我要用完整的QueryString做一些数据处理,后面别的人还要调用getParameter()来查询参数。前后是两个人实现的,后面的人可能并没有意识到我的存在。
      

  2.   

    ServletRequest的getReader()方法及其getInputStream()方法均只能被调用一次,而且前者与后者也是冲突的,调用了前者就不能再调用后者,如Servlet的document:
    --------------------------------------------------------------------------------getInputStream
    public ServletInputStream getInputStream()
                                      throws java.io.IOExceptionRetrieves the body of the request as binary data using a ServletInputStream. Either this method or getReader() may be called to read the body, not both.
    Returns:
    a ServletInputStream object containing the body of the request
    Throws:
    java.lang.IllegalStateException - if the getReader() method has already been called for this request
    java.io.IOException - if an input or output exception occurred--------------------------------------------------------------------------------getReader
    public java.io.BufferedReader getReader()
                                     throws java.io.IOExceptionRetrieves the body of the request as character data using a BufferedReader. The reader translates the character data according to the character encoding used on the body. Either this method or getInputStream() may be called to read the body, not both.
    Returns:
    a BufferedReader containing the body of the request
    Throws:
    java.io.UnsupportedEncodingException - if the character set encoding used is not supported and the text cannot be decoded
    java.lang.IllegalStateException - if getInputStream() method has been called on this request
    java.io.IOException - if an input or output exception occurred
    See Also: 
    getInputStream()
      

  3.   

    两个方法不能同时使用
    FORM的提交方法决定servlet的接收方法
      

  4.   

    参考http://www.meetchinese.com/earticles/xr_html/articles/114/2421.html
      

  5.   

    多谢楼上各位的解答!我现在有两种解决方案:
    1、先调用getParameterNames(),得到所有的参数名称,再依次调用getParameterValues(Name)得到与名称对应的参数值,最后手工组合出完整的QueryString。只要参数名字的次序对了,得到的结果就和调用getQueryString()得到的相同,这样也不会影响到后续getParameter()的正常调用;
    2、调用Request的getReader()函数,直接得到完整的QueryString。然后用得到的QueryString构造一个HttpServletRequestWraper对象,实现HttpServletRequest接口,模拟HttpServletRequest接口中所有函数的行为。这样的一个对象,就可以完全取代doPost()中作为参数传入的request了。我参考了Sun的原代码实现了HttpServletRequestWraper类,初步测试没有问题,但是实在没有把握在所有的环境中都没有问题。哪位还有没有更好的解决方法?
      

  6.   


    import javax.servlet.http.HttpServletRequest;
    import java.util.Enumeration;public class myRedirect 
    {

    public static String dealurl(HttpServletRequest request)
    {
    String url = "";
    url = request.getRequestURL()+"?";
    Enumeration param = request.getParameterNames();
    while(param.hasMoreElements())
    {
    String pname = param.nextElement().toString();
    url += pname+"="+request.getParameter(pname)+"&";
    }
    if(url.lastIndexOf("&")==url.length()-1)
    {
    url = url.substring(0,url.lastIndexOf("&"));
    }
    if(url.indexOf("&")>-1)
    url=url.replaceAll("&","@#@");
    return url;
    }
    public static String geturl(String url)
    {
    if(url.indexOf("@#@")>-1)
    url=url.replaceAll("@#@","&");
    //url = "http://mms.nettoo.com.cn"+url.substring(url.indexOf("/mov"));
    return url;
    }
    }比较好 同时支持get和post
      

  7.   

    to jfy3d(剑事)你上面的方法构造出来的QueryString(dealurl)至少有两个问题:1、与直接从Request中读取的结果不相同了,因为request.getParameterNames()返回的Names已经不是html中原来的次序;2、你没有考虑一个name对应多个value的情况。不过还是非常感谢!
      

  8.   

    你有什么更复杂的应用
    需要参数排序?
    还有什么情况下需要name对应多个value?
      

  9.   

    有很多的理由可能需要排序。至于一个name对应多个value,那不是需要不需要的问题,而是有没有这种可能,html里面是否允许,只要html里面认可,我就得处理,因为是否需要不是我能决定的。