Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/389.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java org.apache.commons.fileupload.FileUploadException:处理多部分/表单数据请求失败_Java - Fatal编程技术网

Java org.apache.commons.fileupload.FileUploadException:处理多部分/表单数据请求失败

Java org.apache.commons.fileupload.FileUploadException:处理多部分/表单数据请求失败,java,Java,当我在线部署文件上传程序时,该程序在本地pc上运行良好,它给出了一个错误,即 org.apache.commons.fileupload.FileUploadException:处理 多部分/表单数据请求失败。C:\ProgramFiles(x86)\Apache 软件基础\Tomcat 5.0 \上传_4133c5ef_14e0097e702__8000_00000003.tmp(系统无法 查找指定的路径) 下面是我的代码: <%@page import="java.util.*"%&g

当我在线部署文件上传程序时,该程序在本地pc上运行良好,它给出了一个错误,即

org.apache.commons.fileupload.FileUploadException:处理 多部分/表单数据请求失败。C:\ProgramFiles(x86)\Apache 软件基础\Tomcat 5.0 \上传_4133c5ef_14e0097e702__8000_00000003.tmp(系统无法 查找指定的路径)

下面是我的代码:

<%@page import="java.util.*"%>
<%@page import="java.util.Iterator"%>
<%@page import="java.io.File"%>
<%@page import="org.apache.commons.fileupload.servlet.ServletFileUpload"%>
<%@page import="org.apache.commons.fileupload.disk.DiskFileItemFactory"%>
<%@page import="org.apache.commons.fileupload.*"%>
<%@page import="javax.servlet.ServletConfig"%>
<%@page import="java.sql.*"%>
<%@page import="java.io.*"%>
<%@page import="java.text.*"%>
<%@page import="javax.servlet.Servlet"%>
<%@page import="javax.servlet.ServletException"%>
<%@page import="javax.servlet.http.HttpServlet"%>
<%@page import="com.mmvisa.utils.ConnectionUtils"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Group file Upload</title>
<link href='http://fonts.googleapis.com/css?family=Open+Sans:400,300,300italic,700,600,800' rel='stylesheet' type='text/css' />
<link rel="stylesheet" href="../css/style.css" type="text/css" />

</head>
<body >
<div id="wrapper">

 <div id="header">

     <div id="logo">     
     <img src="../images/logo.jpg" alt="logo"  />     
     </div>    <!-- logo -->

     <div class="tittle">
      <h1> M M VISA-AID CONSULTANCY </h1>
       <p>OFFSHORE AGENT OF AUSTRALIAN GOVERNMENT <br />
Department of Immigration & Border Protection</p>

     </div>    <!-- tittle -->

  </div>   <!-- header -->


 <div class="content" style="min-height:420px;">




<br/>

<center>
<table border="2">

    <%
      ServletConfig config1 = getServletConfig();
  //    long  useridStr= 0;  
    String id = "";
    long compid = 0;

    //List<String> allfileName=new ArrayList<String>();
    String allfileName[]=new String[50];
    int counterNoOfFiles=0;
    int uid = 0;
    String year =null;
    String invalidFile=null;

      boolean isMultipart = ServletFileUpload.isMultipartContent(request);
    if (!isMultipart){

    }else{

        List items = null;
        try{

            //FileItemFactory factory = new DiskFileItemFactory();

           // ServletFileUpload upload = new ServletFileUpload(factory);
           DiskFileUpload upload = new DiskFileUpload();
            items = upload.parseRequest(request);
        }catch (FileUploadException e){
            e.printStackTrace();

        }
        Iterator itr = items.iterator();
        while (itr.hasNext()) {

                FileItem item = (FileItem) itr.next();
                if (item.isFormField()){
                    ////

                    String name = item.getFieldName();
                    String value = item.getString();
                    Long value1 = item.getSize();
                    System.out.println("dj checking field name-->"+name);
                    if(name.equals("year")){
                        year=value;
                        System.out.println("dj checking field value-->"+year);
                    }
                }else   
                {

                    try{
                        String itemName = item.getName();
                        //allfileName.add(itemName);
                        if (item.getSize() > 0){
                            File uploadedFile = null; 
                            String myFullFileName = item.getName(), myFileName = "",
                            slashType = (myFullFileName.lastIndexOf("\\") > 0) ? "\\" : "/"; // Windows or UNIX
                            //System.out.println("in multiple file upload"+slashType);
                            int startIndex = myFullFileName.lastIndexOf(slashType);
                            myFileName = myFullFileName.substring(startIndex + 1, myFullFileName.length()); 
                            System.out.println("in multiple file upload"+myFileName);
                            //uploadedFile = new File("C:\\Documents and Settings\\sys\\Desktop\\shastrogyan\\.metadata\\.plugins\\org.eclipse.wst.server.core\\tmp0\\wtpwebapps\\Hayagriva\\files\\", myFileName);
                            uploadedFile = new File(getServletContext().getRealPath("\\")+"clientfeedback", myFileName);
                            //getServletContext().getRealPath("\\")+"uploadfiles\\"
                            System.out.println("uploaded file "+uploadedFile);
                            item.write(uploadedFile);
                            allfileName[counterNoOfFiles]=itemName;
                            counterNoOfFiles++;
                        }  
                    }catch (Exception e){
                        e.printStackTrace();
                    }
                }
        }
    }
          Connection con = null;
          PreparedStatement preStat = null;
          ResultSet rs = null;
          int count=0;
              String img=" ";
                        for(int i=0;i<=counterNoOfFiles;i++)
                        {
                            System.out.println("Number of files "+counterNoOfFiles);
                            img = allfileName[i];
                            System.out.println("Image name "+img);
                        }
                        System.out.println("All Image names "+img);

            //Code for Add to database
            for(int i=0;i<counterNoOfFiles;i++){
                //System.out.println("175"+allfileName.size());

                PreparedStatement psmt=null;

                try{
                  con=ConnectionUtils.getConnection();
                String sql = "select * from clientfeedback where imagename=?";
                System.out.println(sql);
                psmt=con.prepareStatement(sql);
                psmt.setString(1, allfileName[i].toString());
                rs=psmt.executeQuery();
                if(rs.next()){
                    count++;
                }else{
                    if (psmt != null)
                        psmt.close();
                  String query = "insert into clientfeedback (imagename,year ) values(?,?)";

                System.out.println(query);
                        psmt=con.prepareStatement(query);
                        psmt.setString(1, allfileName[i].toString());
                        psmt.setString(2,year);
                        psmt.executeUpdate();
                }
                    }catch(Exception ex){
                        ex.printStackTrace();
                    }finally{

                        try {
                            if (psmt != null)
                                psmt.close();
                        } catch (Exception e2) {
                        }
                        try {
                            if (con != null)
                                con.close();
                        } catch (Exception e3) {
                        }
                }
            }
            System.out.println("checking count->"+count);
            if(count!=0){
                invalidFile="there is "+count+" duplicate file which is not save in database.other file has saved"; 
            }else{
            invalidFile="File uploading done successfully"; 
            }
   %>

</table>
</center>
<center>
<h3><%=invalidFile %></h3>
</center>
<center><a href="<%=request.getContextPath() %>/clientFeedback.do?action=list">Go to upload page</a></center>
<br/>

</div>  <!-- content -->

<div id="footer" style="margin-top:10px;">
       <table>
       <tr>
       <td width="900">Copyright, All Rights Reserved,MM VISA,2014</td>
       <td width="460">Follow us on : <a href="#"> <img src="../images/facebook.png" /> </a> <a href="#"> <img src="../images/twitter.png" /> </a>  <a href="#"> <img src="../images/utube.png" /> </a>`enter code here`
       <a href="#"> <img src="../images/blog1.png" /></a>
       <a href="#"> <img src="../images/google_plus_icon.png" /> </a>

        </td>
      </tr>
        </table>
        </div>  <!-- footer-->

</div>  <!-- wrapper -->
</body>
</html>

组文件上载
M M签证援助咨询公司
澳大利亚政府的离岸代理人
移民和边境保护部


0){ 文件uploadedFile=null; 字符串myFullFileName=item.getName(),myFileName=“”, slashType=(myFullFileName.lastIndexOf(“\\”)>0)?“\\”:“/”;//Windows或UNIX //System.out.println(“在多文件上传中”+slashType); int startIndex=myFullFileName.lastIndexOf(slashType); myFileName=myFullFileName.substring(startIndex+1,myFullFileName.length()); System.out.println(“在多文件上传中”+myFileName); //uploadedFile=新文件(“C:\\Documents and Settings\\sys\\Desktop\\shastrogyan\\.metadata\\.plugins\\org.eclipse.wst.server.core\\tmp0\\wtpwebapps\\Hayagriva\\files\\”,myFileName); uploadedFile=新文件(getServletContext().getRealPath(“\\”)+“clientfeedback”,myFileName); //getServletContext().getRealPath(\\”+“uploadfiles\\” System.out.println(“上传文件”+上传文件); item.write(上传文件); allfileName[counterNoOfFiles]=itemName; counterNoOfFiles++; } }捕获(例外e){ e、 printStackTrace(); } } } } 连接con=null; PreparedStatement preStat=null; 结果集rs=null; 整数计数=0; 字符串img=“”; 对于(int i=0;i
版权所有,保留所有权利,MM VISA,2014 跟着我们:`在这里输入代码`

任何人都可以帮我解决这个问题。谢谢你

Apache Commons FileUpload
使用
java.io.tmpdir
系统/环境变量中设置的路径作为默认上载路径。你可以更改默认上载路径。尝试查看它是否解决了问题。查看他们的文档以了解配置详细信息.

Apache Commons FileUpload
使用
java.io.tmpdir
系统/环境
变量中设置的路径作为默认上载路径。您可以更改默认上载路径。尝试查看是否解决了问题。检查他们的文档以了解配置详细信息。

如果我上载小尺寸图像,如徽标及其所有工作g好的,如果我尝试上传大尺寸的文件图像,它给出了一个问题..有什么建议吗..如果我上传小尺寸的图像,比如logo和它的所有工作都很好,如果我尝试上传大尺寸的文件图像,它给出了一个问题..有什么建议吗..如果我上传小尺寸的图像,比如logo和它的所有工作都很好,如果我尝试上传大尺寸的文件这是一个问题,有什么建议吗。。?