页面部分
<s ileUpload id="uploadProcess" data="#{sysBulletinHome.bulletinAttchment.content}"
fileName="#{sysBulletinHome.bulletinAttchment.fileName}" contentType="#{sysBulletinHome.bulletinAttchment.contentType}"
fileSize="#{sysBulletinHome.bulletinAttchment.filesize}"/>
<h:commandButton value="上传文件" action="#{sysBulletinHome.upload}" >
</h:commandButton>
上面的标签中contentType的属性大家要注意一下,如文件是07版的office文件 文件类型并不是我们想象的.docx或.xlsx ,而是application/vnd.openxmlformats-officedocument.wordprocessingml.document或application/vnd.openxmlformats-officedocument.spreadsheetml.sheet 在 数据库设计的时候要注意contentType的大小
java代码
上传的时候先把上传的文件缓存在set中,在提交保存或更新的时候会持久化到数据库。
public void upload() {
bulletinAttchment.setSysBulletin(getInstance());
this.getInstance().getSysBulletinAttchments().add(bulletinAttchment);
bulletinAttchment = new SysBulletinAttchment();
}
Conponents.xml
<!-- 上传组件-->
<component class="org.jboss.seam.web.MultipartFilter">
<property name="createTempFiles">true</property>
<property name="maxRequestSize">10000000</property>
</component>
web.xml
<filter> <filter-name>Seam Filter</filter-name> <filter-class>org.jboss.seam.servlet.SeamFilter</filter-class></filter><filter-mapping> <filter-name>Seam Filter</filter-name> <url-pattern>/*</url-pattern></filter-mapping>
<s ileUpload id="uploadProcess" data="#{sysBulletinHome.bulletinAttchment.content}"
fileName="#{sysBulletinHome.bulletinAttchment.fileName}" contentType="#{sysBulletinHome.bulletinAttchment.contentType}"
fileSize="#{sysBulletinHome.bulletinAttchment.filesize}"/>
<h:commandButton value="上传文件" action="#{sysBulletinHome.upload}" >
</h:commandButton>
上面的标签中contentType的属性大家要注意一下,如文件是07版的office文件 文件类型并不是我们想象的.docx或.xlsx ,而是application/vnd.openxmlformats-officedocument.wordprocessingml.document或application/vnd.openxmlformats-officedocument.spreadsheetml.sheet 在 数据库设计的时候要注意contentType的大小
java代码
上传的时候先把上传的文件缓存在set中,在提交保存或更新的时候会持久化到数据库。
public void upload() {
bulletinAttchment.setSysBulletin(getInstance());
this.getInstance().getSysBulletinAttchments().add(bulletinAttchment);
bulletinAttchment = new SysBulletinAttchment();
}
Conponents.xml
<!-- 上传组件-->
<component class="org.jboss.seam.web.MultipartFilter">
<property name="createTempFiles">true</property>
<property name="maxRequestSize">10000000</property>
</component>
web.xml
<filter> <filter-name>Seam Filter</filter-name> <filter-class>org.jboss.seam.servlet.SeamFilter</filter-class></filter><filter-mapping> <filter-name>Seam Filter</filter-name> <url-pattern>/*</url-pattern></filter-mapping>