这个例子是通过用Struts的FormFile来写入到MySQL中。用户通过选一个图片,然后按submit就可以存入数据库中,其中先要建立一个表:
create table test (name varchar(20), pic blob );
在MySQL的test库中
<%@ page language="java"%>
<%@ taglib uri=
"http://jakarta.apache.org/struts/tags-bean"
prefix="bean"%>
<%@ taglib uri=
"http://jakarta.apache.org/struts/tags-html"
prefix="html"%>
<html>
<head>
<title>JSP for multiForm form</title>
</head>
<body>
<html:form action="/multi"
enctype="multipart/form-data">
一定要用enctype=“multipart/form-data“
不然就提交之后就会有抛出异常
file : <html:file property="file"/>
<html:errors property="file"/></br>
name : <html:text property="name"/>
<html:errors property="name"/></br>
<html:submit/><html:cancel/>
</html:form>
</body>
</html>
2. 相对应的ActionForm:
//Created by MyEclipse Struts
// XSL source (default):
platform:/plugin/com.genuitec.eclipse.
cross.easystruts.eclipse_3.8.1
/xslt/JavaClass.xsl
package saoo.struts.form;
import org.apache.struts.action.ActionForm;
import org.apache.struts.upload.FormFile;
/**
* MyEclipse Struts
* Creation date: 08-24-2004
*
* XDoclet definition:
* @struts:form name="multiForm"
*/
public class MultiForm extends ActionForm
{
// ----------------
Instance Variables
/** file property */
private FormFile file;
/** name property */
private String name;
// -----------------
Methods
/**
* Returns the file.
* @return FormFile
*/
public FormFile getFile()
{
return file;
}
/**

