以下是我的动作类
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时遇到同样的问题
任何想法?请帮忙
答案 0 :(得分:1)
据我所知
Struts框架使用getParameter将数据填充到表单bean中 在调用execute方法之前,我们不能使用request.getInputStream
请纠正我的错误