FormFile类型如何转换为String
uploadFfile.jsp
<……>
<html:form action="/uploadTest" enctype="multipart/form-data">
图片上传 : <html:file property="enterprise.logo" />
<html:submit />
<html:cancel />
</html:form>
<……>
================================
struts-config.xml
<……>
<struts-config>
<data-sources />
<form-beans >
<form-bean name="uploadForm" type="com.test.forms.UploadForm" />
</form-beans>
<global-exceptions />
<global-forwards />
<action-mappings >
<action
name="uploadForm"
path="/uploadTest"
input="/uploadFfile.jsp"
scope="request"
type="com.test.actions.UploadAction" />
</action-mappings>
<……>
</struts-config>
====================================
UploadForm
<……>
public class UploadForm extends ActionForm {
private Enterprise enterprise = new Enterprise();
public void setEnterprise(Enterprise enterprise){
this.enterprise = enterprise;
}
public Enterprise getEnterprise(){
return enterprise;
}
}
<……>
==========================
下边是EnterpriseDto
public class EnterpriseDto{
private String logo; //logo地址
public void setLogo(String logo){
this.logo= logo;
}
public String getLogo(){
return logo;
}
}
=======================================
UploadAction
public class UploadAction extends Action {
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
UploadForm uploadForm = (UploadForm )form;
FormFile logo = uploadForm.getEnterprise().getLogo();//在报的错是不能从String转化为FormFile
//我要在这得到Enterprise中的String logo保存在数据库中该如何写??急急急
}
}
<……>
<html:form action="/uploadTest" enctype="multipart/form-data">
图片上传 : <html:file property="enterprise.logo" />
<html:submit />
<html:cancel />
</html:form>
<……>
================================
struts-config.xml
<……>
<struts-config>
<data-sources />
<form-beans >
<form-bean name="uploadForm" type="com.test.forms.UploadForm" />
</form-beans>
<global-exceptions />
<global-forwards />
<action-mappings >
<action
name="uploadForm"
path="/uploadTest"
input="/uploadFfile.jsp"
scope="request"
type="com.test.actions.UploadAction" />
</action-mappings>
<……>
</struts-config>
====================================
UploadForm
<……>
public class UploadForm extends ActionForm {
private Enterprise enterprise = new Enterprise();
public void setEnterprise(Enterprise enterprise){
this.enterprise = enterprise;
}
public Enterprise getEnterprise(){
return enterprise;
}
}
<……>
==========================
下边是EnterpriseDto
public class EnterpriseDto{
private String logo; //logo地址
public void setLogo(String logo){
this.logo= logo;
}
public String getLogo(){
return logo;
}
}
=======================================
UploadAction
public class UploadAction extends Action {
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
UploadForm uploadForm = (UploadForm )form;
FormFile logo = uploadForm.getEnterprise().getLogo();//在报的错是不能从String转化为FormFile
//我要在这得到Enterprise中的String logo保存在数据库中该如何写??急急急
}
}
...全文
相关推荐
struts的[图片]文件上传和类型转换
,例如:```javaprivate String title;private FormFile myfile;// setter 和 getter 方法public String getTitle()
控制上传的文件的大小
我们可以通过自定义一个ActionForm类,包含一个FormFile类型的属性来处理文件上传。然后,在表单提交时,我们可以在`validate()`方法内检查文件大小。
SSH实现上传下载
(FormFile uploadFile) { this.uploadFile = uploadFile; } } ``` - **处理上传**:在对应的Action类中处理文件的保存操作,这通常涉及到将文件数据转换为
java文件上传方法
- `String name = String.valueOf(date.getTime());` 获取当前时间的时间戳并转换为字符串。2.
struts包
= form.getPicture();String picName = formFile.getFileName();if (picName !


Web 开发
