在使用s:fileupload时,提取文件总显示为空,长度为零,其他诸如filename,contenttype等也为Null.这个问题怎么办?谁知道什么原因?
我的用的jboss+seam:
web.xml:
<context-param>
<param-name>com.icesoft.faces.uploadDirectory</param-name>
<param-value>upload</param-value>
</context-param>
<context-param>
<param-name>com.icesoft.faces.uploadMaxFileSize</param-name>
<param-value>1001048576</param-value>
</context-param>
<servlet>
<servlet-name>uploadServlet</servlet-name>
<servlet-class>com.icesoft.faces.component.inputfile.FileUploadServlet</servlet-class>
<load-on-startup> 1 </load-on-startup>
</servlet>
component.xml:
<web:multipart-filter create-temp-files="false"
max-request-size="10485760"
url-pattern="/*"/>
backingbean:
@Stateless
@Name("filebean")
public class FileBean implements FileBeanInterface {
@Logger
private Log log;
@PersistenceContext
private EntityManager em;
private FileData filedata=new FileData();
private String msginfo="";
//@In(value="#{facesContext}")
FacesContext facesContext=FacesContext.getCurrentInstance();
private ExternalContext extCtx=facesContext.getExternalContext();
private List<FileData> filelist=new ArrayList();
private Long attachmentId;
public Long getAttachmentid(){
return attachmentId;
}
public void setAttachmentid(Long attachmentid){
this.attachmentId=attachmentid;
}
public String setFiledata(FileData file){
this.filedata=file;
return null;
}
public FileData getFiledata(){
return this.filedata;
}
public String getMsginfo(){
msginfo=filedata.getContentType();
return msginfo;
}
public String download(Long id){
setAttachmentid(id);
return download();
}
public String download() {
FileData attachment = em.find(FileData.class, attachmentId);
HttpServletResponse response = (HttpServletResponse)extCtx.getResponse();
response.setContentType(attachment.getContentType());
response.addHeader("Content-disposition", "attachment; filename=\"" + attachment.getName() +"\"");
try {
ServletOutputStream os = response.getOutputStream();
os.write(attachment.getData());
os.flush();
os.close();
facesContext.responseComplete();
} catch(Exception e) {
log.error("\nFailure : " + e.toString() + "\n");
}
return null;
}
public String saveFile(){
try{
em.persist(filedata);
filedata=new FileData();
}catch(Exception ex){
}
return null;
}
public String deleteFile(){
FileData to_delete=em.find(FileData.class,attachmentId);
em.remove(to_delete);
em.flush();
getFilelist();
return null;
}
public String deleteFile(Long id){
setAttachmentid(id);
return deleteFile();
}
public List<FileData> getFilelist(){
filelist=em.createQuery("select f from FileData f").getResultList();
return filelist;
}
public void setFilelist(List<FileData> filelist){
this.filelist=filelist;
}
xhtml
<h:form enctype="multipart/form-data" >
<s:fileUpload id="fileupload" accept="text/html"
data="#{filebean.filedata.data}"
contentType="#{filebean.filedata.contentType}"
fileName="#{filebean.filedata.name}"
fileSize="#{filebean.filedata.size}"/>
<br/><br/>
文件名称:<h:outputText value="#{filebean.filedata.name}"/>
<br/><br/>
内容类型:<h:outputText value="#{filebean.filedata.contentType}"/>
<br/><br/>
文件长度:<h:outputText value="#{filebean.filedata.size}"/>
<br/><br/>
<ice:commandButton value="Upload" partialSubmit="true"
action="#{filebean.saveFile}"/>
</h:form>
谁能给看一下怎么回事?
分享到:
相关推荐
Features ======== ...* … more at the [upstream's features page](http://aquantum-demo.appspot.com/file-upload#features) Requirements ============ * Django * Python Imaging Library
<s:file name="fileUpload"/> ``` - **说明**:用于创建文件上传表单元素。 22. **`<s:form>`** - 创建表单。 - **示例**: ```jsp <s:form action="submitForm"> 用户名:<s:textfield name="username"/> ...
6. 文件上传和下载标签:如`<s:file>`用于处理文件上传,`<s:fileupload>`和`<s:filedownload>`则处理文件的上传和下载。 7. 模板标签:如`<s:include>`和`<s:decorator>`允许在页面中包含其他页面或应用装饰器模式...
`<s:file>`标签用于文件上传功能,与Struts2的FileUpload拦截器配合使用。 `<s:form>`标签创建表单,它会将表单数据提交到指定的Action。 G. `<s:generator>`,`<s:iterator>`: `<s:generator>`常与`s:iterator`...
<s:file name="fileUpload" /> ``` ##### 20. `<s:form>` 标签 - **用途**:创建 HTML 的 `<form>` 表单。 - **示例**: ```xml <s:form action="submitForm" theme="simple"> <!-- 表单内容 --> </s:form> ...
<s:file name="fileUpload" /> ``` ##### 17. `<s:form action="">` - **功能**:创建表单并指定处理该表单的Action。 - **示例**: ```xml <s:form action="uploadFile"> <s:file name="fileUpload" /> <s:...
- 示例:`<s:file name="fileUpload" />` - 用途:允许用户上传文件。 ##### 3. 数据展示标签 - **`<s:iterator>`**:遍历集合数据。 - 示例:`<s:iterator value="users">` - 用途:循环显示集合中的数据项。...
该文档是关于在ASP.NET环境下使用FileUpload控件实现图片上传,并进行图片处理,包括生成缩略图以及添加文字和图片水印的功能。下面将详细解释这个过程中的关键知识点: 1. **FileUpload控件**:ASP.NET中的...
支持一次上传多个文件支持文件和字段入门npm install react-native-fileupload --save 的iOS 在XCode中的项目导航器中,右键单击your project ➜ Add Files to [your project's name] 转到node_modules react-...
// Set the servlet's response type to XML. PrintWriter out = null; String uploadDirectory = this.getServletContext().getInitParameter("UploadDirectory"); if(!uploadDirectory.contains(":")) { ...
在Flex中,用户通常通过`<mx:FileUpload>`或`<s:FileUpload>`组件来选择文件。这些组件允许用户选择一个或多个文件,并提供了监听文件选择事件的接口。例如,我们可以监听`change`事件来触发文件的预览或上传操作。 ...
在实际应用中,还需要考虑文件大小限制、文件类型检查、异常处理等问题。例如,可以设置`<filter-mapping>`中的`maxPostSize`属性限制上传文件大小,使用`FileItem`的`isFormField()`和`getFieldName()`方法检查文件...
5. **文件上传**:`s:file`标签用于实现文件上传功能,结合Struts2的FileUpload拦截器,可以处理文件上传的细节,如大小限制、类型检查等。 6. **国际化与本地化**:Struts2的标签支持国际化,可以使用`s:text`或`s...
<s:form action="fileUpload" method="POST" enctype="multipart/form-data"> <s:file name="uploadFile" label="选择文件"/> <s:submit value="上传"/> </s:form> ``` 对于多文件上传,只需要将`s:file`标签放入...
1. **依赖库**:在使用Struts2进行开发时,需要引入一系列的jar包,例如`commons-logging-1.0.4.jar`、`commons-fileupload-1.2.1.jar`、`freemarker-2.3.13.jar`、`ognl-2.6.11.jar`、`struts2-core-2.1.6.jar`和`...
Struts2是一个流行的Java Web框架,它为开发者提供了一种优雅的方式来构建可维护、结构清晰的Web应用...在实际应用中,还需要考虑文件的合法性检查、错误处理、文件重命名等问题,确保文件上传功能的健壮性和安全性。
在Struts 2中,可以使用`<s:form>`标签的`enctype="multipart/form-data"`属性创建一个文件上传表单。然后,定义一个Action类,该类需要继承`org.apache.struts2.upload.FileUploadAction`或实现`...
【标题】"Flash上传工具 修改版 FileUpload Flash"是一个针对B/S架构的文件上传解决方案,特别强调了其为修改版,意味着它可能包含了对原始版本的优化或功能增强。此工具利用Flash技术来实现文件上传,可以应用于多...