Struts Action里面处理上传文件总是不成功,连文件名都取不到?大家帮我看看吧?是怎么回事?
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.