日期:2014-05-18  浏览次数:20706 次

文件上传javaBean这么写?
问题一:
<form   action= "uploadimage.jsp "   method= "post "   enctype= "multipart/form-data "   name= "form1 ">
<input   type= "file "   name= "file ">
<input   type= "submit "   name= "Submit "   value= "上传 "   >
</form>

在javabean中这么接受请求?    


问题二:

在javabean中这么写引进smartupload包?




------解决方案--------------------
问题一

什么意思

问题二

直接导入import 就可以 然后吧smart的jar放到web-inf/lib
------解决方案--------------------
没用过html的这个标签用的struts的 <html:file/> ,如果需要的话可以给你参考一下
------解决方案--------------------
一、应该在Action里面接收;
org.apache.struts.upload.FormFile zipFile = (FormFile) form.get( "file ");
二、....
------解决方案--------------------
我也不明白如何在javabean里面接收,

不过你可以在jsp里面用org.apache.struts.upload.FormFile file = (FormFile) request.getAttribute( "file ");
然后把
file.getFileData()传递给javabean进行处理。
------解决方案--------------------
现在大多数上传处理都是写成jsp文件 其中用了smartupload包

<%@ page contentType= "text/html;charset=GBK " %>
<html>
<head>
<title> 文件上传 </title>
<meta http-equiv= "Content-Type " content= "text/html; charset=gb2312 ">
</head>
<body>
<FORM METHOD= "POST " ACTION= "action_upload.jsp " ENCTYPE= "multipart/form-data ">
<p> 请选择要上传的文件
<p> <input type= "FILE " name= "FILE1 " size= "30 ">
<p> <input type= "FILE " name= "FILE2 " size= "30 ">
<p> <input type= "FILE " name= "FILE3 " size= "30 ">
<p> <input type= "FILE " name= "FILE4 " size= "30 ">
<p> <input type= "submit " value= "上传 ">
</FORM>
</body>
</html>

<%@ page contentType= "text/html;charset=GBK " %>
<html>
<head>
<title> 文件上传处理页面 </title>
<meta http-equiv= "Content-Type " content= "text/html; charset=gb2312 ">
</head>

<body>
<jsp:useBean id= "su " scope= "page " class= "com.jspsmart.upload.SmartUpload " />
<%
su.initialize(pageContext);
su.upload();
int count = su.save( "/upload ", su.SAVE_VIRTUAL);
out.println(count+ "个文件上传成功! <br> ");
for (int i=0;i <su.getFiles().getCount();i++)
{
com.jspsmart.upload.File file = su.getFiles().getFile(i);
if (file.isMissing()) continue;
out.println( " <br> 文件名: " + file.getFileName()+ " 长度: "+file.getSize());
}
%>
</body>
</html>


我的意思是这样 action_upload.jsp 文件写成javaBean

upload.html文件写成upload.jsp

其中
<jsp:useBean id= "upload " scope= "page " class= "upload " />

上传文件

这问题该有普遍实用意义

请个位老大动动脑 谢谢了


------解决方案--------------------