关于x:inputFileUpload

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

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

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

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


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

uploadMaxFileSize
100m



uploadThresholdSize
100k





extensionsFilter
*.faces

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

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

[@more@]

jsp文件:


http://java.sun.com/jsf/html" prefix="h" %>
http://java.sun.com/jsf/core" prefix="f" %>
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;
}
}

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/789181/viewspace-911411/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/789181/viewspace-911411/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值