...
前台用Struts标签:[html:file /]
具体代码:
JSP:
-
[html:form action="/eqPertainDoc.do?method=save" method="post" enctype="multipart/form-data"]文档内容:
-
[html:file property="docContent" styleClass="formDetailTxt" size="30"/]
-
[/html:form]
FormBean:
-
private byte[] document;
- private FormFile docContent;
- public byte[] getDocument() {
-
return document;
-
}
- public void setDocument( byte[] document) {
-
this.document = document;
-
}
- public FormFile getDocContent() {
-
return docContent;
-
}
- public void setDocContent(FormFile docContent) {
-
this.docContent = docContent;
-
}
其中document为数据库中类型为BLOB大字段,而docContent为自己定义的用于存JSP页面的一个属性!
Action:
-
Form form1 = (EqFrom)form;
- try {
-
form1.setDocument(form1.getDocContent().getFileData()); //得到文件数据
-
}catch (FileNotFoundException e) {
-
e.printStackTrace();
-
}
XXX.hbm.xml文件中原来(就是由MyEclipse自动生成的为)document属性为String:
- "document" type="String">
- "DOCUMENT" />
-
现在改为:
- "document" type="org.springframework.orm.hibernate3.support.BlobByteArrayType">
- "DOCUMENT" />
-
相应的XXX.java还有AbstractXXX.java文件也要将String 转换成byte[];