public class FileUploadBean {
public void uploadListener(UploadEvent event) {
//获取传过来的items,3.2.2之前版本不支持getUploadItems方法
List itemList = event.getUploadItems();
for(int i=0 ; i<itemList.size() ; i++){
try {
UploadItem item = (UploadItem) itemList.get(i);
File file = new File("d:\\"+UUID.randomUUID().toString()+".jpg");
//大小不能超过4M
if(item.getFileSize() <= 4000000){
FileInputStream fis = new FileInputStream(item.getFile());
FileOutputStream out = new FileOutputStream(file);
int bytes = 0;
byte[] bteFile = new byte[1024];
while ((bytes = fis.read(bteFile)) != -1) {
out.write(bteFile, 0, bytes);
}
fis.close();
out.close();
}
} catch (Exception e) {
}
}
}
}
<%@page pageEncoding="UTF-8"%>
<%@taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%@taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
<%@ taglib uri="http://richfaces.org/a4j" prefix="a4j"%>
<%@ taglib uri="http://richfaces.org/rich" prefix="rich"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<f:view>
<h:form>
<h:panelGroup>
<h:outputText value="上传头像"></h:outputText>
<rich:spacer height="3" />
<rich:fileUpload fileUploadListener="#{fileUploadBean.uploadListener}"
maxFilesQuantity="5"
autoclear="false"
addControlLabel="添加图片"
uploadControlLabel="上传"
clearAllControlLabel="清除所有"
clearControlLabel="清除"
cancelEntryControlLabel="取消"
stopControlLabel="停止"
stopEntryControlLabel="停止" noDuplicate="true"
listHeight="400"
listWidth="515"
style="height:100;"
id="upload"
acceptedTypes="jpg, gif, png, bmp">
</rich:fileUpload>
<h:outputText value="支持 JPG、JPEG、GIF、BMP 和 PNG 文件格式,最大4M。">
</h:outputText>
</h:panelGroup>
</h:form>
</f:view>
</body>
</html>
分享到:
相关推荐
primefaces中用<p:fileUpload组件来上传文件
ondatabinding="FileUpload1_DataBinding"></asp:FileUpload> <asp:Button ID="Button1" runat="server" Text="分离样式" onclick="Button1_Click" /> <asp:LinkButton runat="server" ID="download" Text="下载...
JSF+rich 实现 fileUpload java代码实现上传文件和图片,代码已经测试过,架包完整,下载后可以直接运行
FileUpload控件的基本用法 .
NULL 博文链接:https://windywindy.iteye.com/blog/413582
<param-value>client</param-value> </context-param> <!-- Context Listener creates and sets the application handler --> <!-- Faces Servlet --> <servlet> <servlet-name>Faces Servlet</...
5.2.3、第三种Scriptlet:<%=%> 5.3、Scriptlet标签 5.4、page指令 5.4.1、设置页面的MIME 5.4.2、设置文件编码 5.4.3、错误页的设置 5.4.4、数据库连接操作 5.5、包含指令 5.5.1、静态包含 5.5.2、动态...
5.2.3、第三种Scriptlet:<%=%> 5.3、Scriptlet标签 5.4、page指令 5.4.1、设置页面的MIME 5.4.2、设置文件编码 5.4.3、错误页的设置 5.4.4、数据库连接操作 5.5、包含指令 5.5.1、静态包含 5.5.2、动态...
5.2.3、第三种Scriptlet:<%=%> 5.3、Scriptlet标签 5.4、page指令 5.4.1、设置页面的MIME 5.4.2、设置文件编码 5.4.3、错误页的设置 5.4.4、数据库连接操作 5.5、包含指令 5.5.1、静态包含 5.5.2、动态...
5.2.3、第三种Scriptlet:<%=%> 5.3、Scriptlet标签 5.4、page指令 5.4.1、设置页面的MIME 5.4.2、设置文件编码 5.4.3、错误页的设置 5.4.4、数据库连接操作 5.5、包含指令 5.5.1、静态包含 5.5.2、动态...
5.2.3、第三种Scriptlet:<%=%> 5.3、Scriptlet标签 5.4、page指令 5.4.1、设置页面的MIME 5.4.2、设置文件编码 5.4.3、错误页的设置 5.4.4、数据库连接操作 5.5、包含指令 5.5.1、静态包含 5.5.2、动态...
5.2.3、第三种Scriptlet:<%=%> 5.3、Scriptlet标签 5.4、page指令 5.4.1、设置页面的MIME 5.4.2、设置文件编码 5.4.3、错误页的设置 5.4.4、数据库连接操作 5.5、包含指令 5.5.1、静态包含 5.5.2、动态...
5.2.3、第三种Scriptlet:<%=%> 5.3、Scriptlet标签 5.4、page指令 5.4.1、设置页面的MIME 5.4.2、设置文件编码 5.4.3、错误页的设置 5.4.4、数据库连接操作 5.5、包含指令 5.5.1、静态包含 5.5.2、动态...
5.2.3、第三种Scriptlet:<%=%> 5.3、Scriptlet标签 5.4、page指令 5.4.1、设置页面的MIME 5.4.2、设置文件编码 5.4.3、错误页的设置 5.4.4、数据库连接操作 5.5、包含指令 5.5.1、静态包含 5.5.2、动态...
基于extjs的.NET3.5控件Coolite 1.0.0.34580 (Preview预览版), *************************************************** * Version 1.0.0 升级日志 *... configured in the <Items> property of <ext:CompositeField>.
多个用|分隔,如gif|jpg|png <br>Size 上传文件大小 (KB) 默认256KB <br>TimeOut 上传超时设置 (秒), 默认30秒 <br>CallBack Js回调函数名<br><br>例:<hn:FileUpload ID="ajaxUpload" IsMuch="true" runat="server...
ID="FileUpload1" runat="server" />请上传案例的封面图片</div> </td> </tr> <div id="preview_wrapper" > <div id="preview_fake"> <img id="preview" /> </div> </div> <img id="preview_size_fake" /> ...
<title>FileUpload上传文件示例-Mzwu.com</title> </head> <body> <form id="form1" runat="server"> <div> <asp:FileUpload ID="FileUpload1" runat="server" /> <asp:Button ID="Button1" runat="server" _...
<servlet-name>Connector</servlet-name> <servlet-class> com.FCKeditor.connector.ConnectorServlet </servlet-class> <init-param> <param-name>baseDir</param-name> <param-value>/upload/</param-value...
asp 的swfupload上传例子 SWFUpload_ASP.rar