Java 为什么我没有在Struts2操作中获取初始化HttpServletRequest对象?

Java 为什么我没有在Struts2操作中获取初始化HttpServletRequest对象?,java,struts2,Java,Struts2,我面临struts2框架的问题。我想从html表单中获取Action类中excel文件的数据。但是我能够找到HttpServletRequest对象来获取该请求的inputStream。 我还在Struts2的Action类中实现ServletRequestAware接口。我的代码显示在请 import com.opensymphony.xwork2.Action; import com.opensymphony.xwork2.ActionSupport; import java.io.IOE

我面临struts2框架的问题。我想从html表单中获取Action类中excel文件的数据。但是我能够找到
HttpServletRequest
对象来获取该请求的inputStream。 我还在Struts2的Action类中实现
ServletRequestAware
接口。我的代码显示在请

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionSupport;

import java.io.IOException;

import javax.servlet.ServletInputStream;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts2.interceptor.ServletRequestAware;

import jxl.*;
import jxl.read.biff.BiffException;

public class UpdateZflexRecordsAction extends ActionSupport implements ServletRequestAware{
/**
 * 
 */
private static final long serialVersionUID = 1L;
private boolean result = false;
private String status = null;
private String msg = null;
private ServletInputStream inputStream = null; 
private HttpServletRequest request = null;

public String getStatus() {
    return status;
}
public void setStatus(String status) {
    this.status = status;
}


public String getMsg() {
    return msg;
}
public void setMsg(String msg) {
    this.msg = msg;
}

public String execute()
{   
    try {
        inputStream = getServletRequest().getInputStream();

        byte[] junk = new byte[1024];
        int bytesRead = 0;
        // strip off the HTTP information from input stream
        // the first four lines are request junk
        bytesRead = inputStream.readLine(junk, 0, junk.length);
        bytesRead = inputStream.readLine(junk, 0, junk.length);
        bytesRead = inputStream.readLine(junk, 0, junk.length);
        bytesRead = inputStream.readLine(junk, 0, junk.length);

        // create the workbook object from the ServletInputStream
        Workbook workbook = Workbook.getWorkbook(inputStream);
        Sheet sheet = workbook.getSheet(0);
        Cell cell = null;
        System.out.println(sheet.getName());



    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (BiffException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    if (result) {
        this.setStatus("Success");
        this.setMsg("Congratulation ! Your request has been accepted.");
    } else {
        this.setStatus("Failled");
        this.setMsg("Sorry ! Your request has not been accepted.");
    }
    return Action.SUCCESS;
}

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

}
public HttpServletRequest getServletRequest() {
    return this.request;
}
}
我对如何获取
HttpServletRequest
对象实例的问题非常困惑,我在控制台上遇到了另一个错误-

INFO: Unable to find 'struts.multipart.saveDir' property setting. Defaulting to javax.servlet.context.tempdir
下面显示了strut.xml文件-

<?xml version="1.0" encoding="UTF-8" ?>  
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">  
<struts>  
<constant name="struts.devMode" value="true" /> 
<constant name="struts.multipart.maxSize" value="10000000" />

<package name="default" extends="struts-default, json-default" namespace="/">

<action name="downloadZflexFormat" class="sadagi.my.pro.action.RootMapper" method="downloadZflexFormatAction">  
<interceptor-ref name="accessRequired"/>
<interceptor-ref name="scope" />
<result name="login" type="redirect">/</result>  

/  

请给出任何建议来解决它。
感谢给您的imp时间。

您需要将操作配置为包括
defaultStack

<action name="downloadZflexFormat" class="sadagi.my.softhuman.action.RootMapper" method="downloadZflexFormatAction">  
<interceptor-ref name="accessRequired"/>
<interceptor-ref name="scope" />
<interceptor-ref name="defaultStack" />
<result name="login" type="redirect">/</result> 

/ 

由于您的操作已实现
ServletRequestAware
,因此操作实例将填充
HttpServletRequest
对象实例

但问题仍然存在请给我建议HttpServletRequest对象实例HttpServletRequest对象实例由拦截器注入,如果您实现
ServletRequestAware
。您需要一个
defaultStack
来包含这些拦截器。