Struts2请求为空

Struts2请求为空,struts2,request,actioncontext,Struts2,Request,Actioncontext,我有一个非常奇怪的错误,当我试图访问它时,我得到的请求是空的。我总是用同样的方法得到它,但现在我有这个错误 我的动作如下: package com.deveto.struts.actions; import com.deveto.hibernate.mappings.Slider; import com.opensymphony.xwork2.ActionContext; import com.opensymphony.xwork2.ActionSupport; import java.uti

我有一个非常奇怪的错误,当我试图访问它时,我得到的请求是空的。我总是用同样的方法得到它,但现在我有这个错误

我的动作如下:

package com.deveto.struts.actions;

import com.deveto.hibernate.mappings.Slider;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.util.ServletContextAware;


/**
 *
 * @author denis
 */
public class ContentAction extends ActionSupport implements ServletContextAware {

HttpServletRequest request = (HttpServletRequest) ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);
HttpServletResponse response = (HttpServletResponse) ActionContext.getContext().get(ServletActionContext.HTTP_RESPONSE);
ActionContext ac = ActionContext.getContext();
ServletContext sc = (ServletContext) ac.get(ServletActionContext.SERVLET_CONTEXT);

@Override
public String execute() throws Exception {

    System.out.println("request: " + request);

    return SUCCESS;
}

public ActionContext getAc() {
    return ac;
}

public void setAc(ActionContext ac) {
    this.ac = ac;
}

public HttpServletRequest getRequest() {
    return request;
}

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

public HttpServletResponse getResponse() {
    return response;
}

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

public ServletContext getSc() {
    return sc;
}

public void setSc(ServletContext sc) {
    this.sc = sc;
}

public void setServletContext(ServletContext sc) {
    this.sc = sc;
}
}
现在我什么也做不了,请求总是空的

 request: null

实现
ServletRequestAware
接口,并在那里设置
request
变量,而不是在构建过程中进行设置

但是通常您不需要访问请求,因为struts的params拦截器完成了请求对象所需的所有工作

ServletRequestAware
-接口的文档中: 所有想要访问servlet请求对象的操作都必须实现此接口

只有在servlet环境中使用该操作时,此接口才相关


请注意,使用此接口会使操作绑定到servlet环境,因此应尽可能避免,因为单元测试之类的事情会变得更加困难。

谢谢,我会的。我发现了问题,问题出在web.xml中。