无法读取 request.getInputStream
以下是我的操作类,
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
据我所知,
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