我已将web.xml
中的参数定义为uploadDirectory
,我试图从ManagedBean
之一获取该参数。以下是web.xml
-
<!-- Primefaces file upload -->
<!-- thresholdSize specifies the maximum file size in bytes to keep uploaded
files in memory. If it exceeds this limit, it’ll be temporarily written to
disk. -->
<!-- uploadDirectory is the folder where to keep temporary files that exceed
thresholdSize. -->
<filter>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class>
<init-param>
<param-name>thresholdSize</param-name>
<param-value>51200</param-value>
</init-param>
<init-param>
<param-name>uploadDirectory</param-name>
<param-value>/opt/upload/</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<servlet-name>Faces Servlet</servlet-name>
</filter-mapping>
以下是ManagedBean
-
@ManagedBean
@ViewScoped
public class ProjectInfo implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
private static final String destination = FacesContext.getCurrentInstance()
.getExternalContext().getInitParameter("uploadDirectory");
为什么我将null
作为destination
?
答案 0 :(得分:1)
您定义的参数是过滤器的参数,因此它们在您的托管bean中不可用。例如,您可以将此Filter子类化,并添加将此参数放入请求范围的代码,并从托管bean读取此参数,或者如果要从托管bean访问此参数,其请求未被此过滤器过滤,请定义它们为<context-param>
。