温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

关于x:inputFileUpload

发布时间:2020-08-10 14:09:41 来源:ITPUB博客 阅读:139 作者:darmee 栏目:编程语言

inputFileUpload是myfaces里的一个组件,用来上传文件的。本人这几天一直试着使用这个组件,结果均以失败告终。上网搜查资料,结果是千篇一律,更加郁闷。

几经尝试,终于发现为什么这组件失效。

第一点:在里需加上enctype="multipart/form-data"

第二点:需在web.xml文件中加上以下东东:


extensionsFilter
org.apache.myfaces.component.html.util.ExtensionsFilter

uploadMaxFileSize
100m



uploadThresholdSize
100k





extensionsFilter
*.faces

如果你像我一样为这个组件困扰的话,按照上面的试试,应该就可以成功了。

附上本人的测试样例,详细请进入收看。

[@more@]

jsp文件:

<%@ page language="java" pageEncoding="GBK"%>
<%@ taglib uri="
http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="
http://java.sun.com/jsf/core" prefix="f" %>
<%@ taglib uri="
http://myfaces.apache.org/extensions" prefix="x"%>












backbean文件:

package zc.bb;

import org.apache.myfaces.custom.fileupload.UploadedFile;
import java.io.*;

public class InputFileBB {
private UploadedFile upfile;
private String test;
public String loadFile()
{
System.out.println( "test***********darmee" + test );
System.out.println( "name***********darmee" + upfile.getName() );
try
{
InputStream is = upfile.getInputStream();
String filename = getFileName( upfile.getName() );
FileOutputStream fos = new FileOutputStream( "D:" + filename );
int temp;
while ( (temp = is.read())!= -1 )
fos.write(temp);
is.close();
fos.close();
}
catch ( Exception e )
{

}
return null;
}
protected String getFileName(String fileAbsoluteName) {
String fileName = null;
int index = fileAbsoluteName.lastIndexOf("");
if (index > 0) {
fileName = fileAbsoluteName.substring(index + 1);
} else {
fileName = fileAbsoluteName;
}
return fileName;
}
public UploadedFile getUpfile() {
return upfile;
}
public void setUpfile(UploadedFile upfile) {
this.upfile = upfile;
}
public String getTest() {
return test;
}
public void setTest(String test) {
this.test = test;
}
}

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI