无法读取 request.getInputStream

发布于 2024-10-22 15:37:06 字数 2216 浏览 1 评论 0原文

以下是我的操作类,

import java.io.InputStream;

import javax.servlet.ServletInputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.opensymphony.xwork2.ActionSupport;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;

public class AccessRequest extends ActionSupport implements 
                  ServletRequestAware,ServletResponseAware {

  /**
     * 
     */
    private static final long serialVersionUID = 1L;
    private HttpServletRequest request;
      private HttpServletResponse response;

     /**
     * @return the response
     */
    public HttpServletResponse getResponse() {
        return response;
    }

    /**
     * @param response the response to set
     */
    public void setResponse(HttpServletResponse response) {
        this.response = response;
    }

    /**
     * @return the request
     */
    public HttpServletRequest getRequest() {
        return request;
    }

    /**
     * @param request the request to set
     */
    public void setRequest(HttpServletRequest request) {
        this.request = request;
    }

    public void setServletRequest(HttpServletRequest request){
            this.request = request;
          }

          public HttpServletRequest getServletRequest(){
            return request;
          }

          public void setServletResponse(HttpServletResponse response){
            this.response = response;
          }

          public HttpServletResponse getServletResponse(){
            return response;
          }


  public String execute() throws Exception{
        request = ServletActionContext.getRequest();
        InputStream in = null;
        ServletInputStream si = request.getInputStream();
        System.out.println(si.available());//Getting 0
        System.out.println(request.getContentLength()); //Getting 938
        return SUCCESS;
  }

}

我得到 si.available() = 0,其中 request.getContentLength() 显示 938

为什么 struts 不读取 request.getInputstream??????

我在 Struts2 中使用 Servlet 时遇到同样的问题,

有什么想法吗?请帮忙

Following is my action class

import java.io.InputStream;

import javax.servlet.ServletInputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.opensymphony.xwork2.ActionSupport;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;

public class AccessRequest extends ActionSupport implements 
                  ServletRequestAware,ServletResponseAware {

  /**
     * 
     */
    private static final long serialVersionUID = 1L;
    private HttpServletRequest request;
      private HttpServletResponse response;

     /**
     * @return the response
     */
    public HttpServletResponse getResponse() {
        return response;
    }

    /**
     * @param response the response to set
     */
    public void setResponse(HttpServletResponse response) {
        this.response = response;
    }

    /**
     * @return the request
     */
    public HttpServletRequest getRequest() {
        return request;
    }

    /**
     * @param request the request to set
     */
    public void setRequest(HttpServletRequest request) {
        this.request = request;
    }

    public void setServletRequest(HttpServletRequest request){
            this.request = request;
          }

          public HttpServletRequest getServletRequest(){
            return request;
          }

          public void setServletResponse(HttpServletResponse response){
            this.response = response;
          }

          public HttpServletResponse getServletResponse(){
            return response;
          }


  public String execute() throws Exception{
        request = ServletActionContext.getRequest();
        InputStream in = null;
        ServletInputStream si = request.getInputStream();
        System.out.println(si.available());//Getting 0
        System.out.println(request.getContentLength()); //Getting 938
        return SUCCESS;
  }

}

I am getting si.available() = 0 where as request.getContentLength() showing 938

Why struts is not reading request.getInputstream?????

I face the same problem while using Servlet in Struts2

Any Idea? Please help

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

挥剑断情 2024-10-29 15:37:07

据我所知,

Struts 框架使用 getParameter 将数据填充到表单 bean 中
在调用execute方法之前,我们不能使用request.getInputStream,

请纠正我,如果它磨损了

As Per my knowledge

Struts framework uses the getParameter to populate data into the form beans
before calling the execute method, we cannot use the request.getInputStream

Please correct me If its worng

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文