Struts Action里面处理上传文件总是不成功,连文件名都取不到?大家帮我看看吧?是怎么回事?

kangaroo 2003-11-05 03:19:28
Source Code as follows,

import com.jspsmart.upload.SmartUpload;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.jsp.PageContext;

public class SaveUploadBatAction extends Action
{
/**
* This is the main action called from the Struts framework.
* @param mapping The ActionMapping used to select this instance.
* @param form The optional ActionForm bean for this request.
* @param request The HTTP Request we are processing.
* @param response The HTTP Response we are processing.
*/
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
{
String giroNo="";
String fileName="";
if(request.getParameter("GiroNo")!=null)
{
giroNo=request.getParameter("GiroNo");
}
if(request.getParameter("FileName")!=null)
{
fileName = request.getParameter("FileName");
}
String sWaterregionoid="";
Employee employee = (Employee)request.getSession(true).getAttribute("Employee");
String sEmpoid = "";
try{
sEmpoid = String.valueOf(employee.getWaterPartyOid());
sWaterregionoid = String.valueOf(employee.getOrganization().getWaterRegionOid());
}catch(Exception ex)
{
System.out.println("Session value is null!");
}
// System.out.println(fileName);
//======取出配置文件里面的上传路径==============================
ConfigBill conf = ConfigBill.getInstance();
String uploadPath= conf.getValue("GIRO_IMPORT_PATH");

String file_name="";
ServletConfig servletconfig = this.getServlet().getServletConfig();
// PageContext pageContext = new PageContext();

SmartUpload myUpload = new SmartUpload();
// file_name ="200311041424001.txt";
try{
myUpload.initialize(servletconfig,request,response);
myUpload.upload();
file_name = myUpload.getRequest().getParameter("FileName");
// file_name = myUpload.getFiles().getFile(0).getFileName();
myUpload.save(uploadPath+file_name);

System.out.println(uploadPath+file_name);
// System.out.println(myUpload.SAVE_VIRTUAL);
//==========================================================

/* for(int i=0;i<myUpload.getFiles().getCount();i++)
{
file_name = myUpload.getFiles().getFile(0).getFileName();
myUpload.save(uploadPath+file_name);
System.out.println(uploadPath+file_name);
}
*/

}catch(Exception ex)
{
System.out.println(ex.toString());
System.out.println(uploadPath+file_name);
}

return mapping.findForward("success");
}
}

大家帮忙看看吧,我下载的是jspsmart 组件,
为什么不成功?Error Message:
com.jspsmart.upload.SmartUploadException: Unable to upload.
...全文
94 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
kangaroo 2003-11-05
  • 打赏
  • 举报
回复
hj12(12),

例子在哪里呀?你说说我应该调用哪些API,多谢了
kangaroo 2003-11-05
  • 打赏
  • 举报
回复
怎么没人来跟贴啊,急死我了
kangaroo 2003-11-05
  • 打赏
  • 举报
回复
pcdll(.net),

我页面的表单已经设置为 enctype="multipart/form-data"了,但是还是不行,取不到值,

myUpload.upload();

一执行就会报错。

hj12(12) ,先研究下目前为什么不行吧!
pcdll 2003-11-05
  • 打赏
  • 举报
回复
你在页面的表单要设置成enctype="multipart/form-data"
hj12 2003-11-05
  • 打赏
  • 举报
回复
struts有自己得上传组件!在自己带得例子里有!

67,512

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧