JiveJdon Community Forums
在线385人   首页   主题表   培训咨询   标签   精华   查搜   注册    登陆 RSS
首页 » 论坛 » 开源项目大家谈
???en_US.forumThreadPrev.name??? 上一主题
  Go back to the topic 返回本主题   Go back to the topic listing返回主题列表
???en_US.forumThreadNext.name??? 下一主题
Go 总共有 1 回复 / 1
 发表新帖子   回复该主题贴
aronfb

悄悄话
发表文章: 6
注册时间: 2003年04月01日 16:13
如果form里面有file标签,对应的formbean怎么写? 2003年04月09日 15:32 到本帖网址 加入本帖到收藏夹 发送到手机 回复该主题
标签列表
如题,项目中有这个需求。
需要提交一个文件到服务器端,那么Struts里面formbean中怎么办?
banq

悄悄话
发表文章: 9524
注册时间: 2002年08月03日 17:08
Re: 如果form里面有file标签,对应的formbean怎么写? 2003年04月10日 13:10 到本帖网址 加入本帖到收藏夹 发送到手机 回复该主题



JSP页面:
<%@page language="java">
<%@taglib
uri=
"/WEB-INF/struts-html.tld"
prefix=
"html">

<html:form action=
"uploadAction.do" enctype="multipart/form-data">

Please Input Text: <html:text property=
"myText">
Please Input The File You Wish to Upload: <html:file property=
"myFile">

<html:submit />

</html:form>


ActionForm bean:



import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.upload.FormFile;

public class UploadForm extends ActionForm {

protected String myText;
protected FormFile myFile;

public void setMyText(String text) {
myText = text;
}

public String getMyText() {
return myText;
}

public void setMyFile(FormFile file) {
myFile = file;
}

public FormFile getMyFile() {
return myFile;
}

}



Look at the Javadocs for FormFile to see the methods it exposes to manipulate files in file uploading. Also look at the Javadocs for ActionServlet and ActionMapping for the various parameters you can specify to change how files are uploaded.

Basically in your execute method in your action class you would call ((UploadForm) form).getMyFile() to retrieve the FormFile and do what you want with it.


http://jakarta.apache.org/struts/api/org/apache/struts/upload/FormFile.html
这个主题有 1 回复 / 1Go
???en_US.forumThreadPrev.name??? 上一主题
  Go back to the topic 返回本主题   Go back to the topic listing返回主题列表    返回页首返回页首
???en_US.forumThreadNext.name??? 下一主题
热点TAG: AOP cache 缓存 DDD EJB 集群 设计模式 Hibernate IOC JiveJdon OO RBAC Seam Spring Struts
正在读取,请等待...
google yahoo 新浪ViVi 365Key网摘 天极网摘 CSDN网摘 添加到百度搜藏 POCO网摘 博采网摘
查询本论坛内 回复超过的热门帖子
     回复该主题贴
标题
 
粗体 斜体 下划线 插入图片 插入代码 插入url链接 插入附件
内容
  每2分种自动备份发贴内容Ctrl-V粘贴取出,提问题前先查询标签列表

RSS 手机阅读 add to google add to yahoo
解惑之道在J道 ,打造中国最具影响力的的企业软件社区
OpenSource JIVEJDON v3.0 Powered by JdonFramework Code © 2002-08 jdon.com

anti spam