Results 1 to 7 of 7

Thread: JSP File Upload

  1. #1
    maas is offline Member
    Join Date
    Jul 2010
    Posts
    29
    Rep Power
    0

    Default JSP File Upload

    Hello All,

    I am having a problem while using the file upload in the jsp.

    It throws an error which is Null Pointer Exception.

    My code is shown below:

    XML Code:
    String cname = request.getParameter("cname"); 
      String description = request.getParameter("description"); 
      String support = request.getParameter("support"); 
      String attachment=request.getParameter("attachment"); 
      String[] userlist =request.getParameterValues("userlist"); 
      String notify = request.getParameter("notify"); 
      String vendorname = request.getParameter("vendorname"); 
      String from_dt = request.getParameter("from_dt"); 
      String to_dt = request.getParameter("to_dt"); 
      File fileNm=null; 
       
      if(attachment!=null) 
                    { 
                    fileNm = new File(attachment); 
                    } 
       
      String connectionURL = "jdbc:oracle:thin:@X.X.X.XX:XXX:test"; 
       
      Connection conn=null; 
       
      PreparedStatement ps=null; 
             
      Class.forName("oracle.jdbc.driver.OracleDriver").newInstance(); 
       
       
      if (cname != null ){ 
      try 
      { 
            conn = DriverManager.getConnection(connectionURL, "test", "test"); 
             
            for (int i=0; i<userlist.length; i++){  
             
            FileInputStream fis = new FileInputStream(fileNm); 
             
            String queryString = "INSERT INTO contract_detail(contract_name,description,support,c_from,c_to,userlist,notify,vendorname,attachment) VALUES (?,?,?,TO_DATE(?,'YYYY/MM/DD'),TO_DATE(?,'YYYY/MM/DD'),?,?,?,?)"; 
     
         ps = conn.prepareStatement(queryString);   
                     
             ps.setString(1, cname); 
             ps.setString(2, description); 
             ps.setString(3, support); 
             ps.setString(4, from_dt); 
             ps.setString(5, to_dt); 
             ps.setString(6, userlist[i]); 
             ps.setString(7, notify); 
             ps.setString(8, vendorname); 
             ps.setBinaryStream(9,fis,(int)fileNm.length()); 
     
     
             ps.executeUpdate();       
             fis.close(); 
         }        
             out.println(" The Contract is updated successfully"); 
              
      }
    Could you please help me to solve this issue and how correct is my code?

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,307
    Rep Power
    25

    Default

    throws an error which is Null Pointer Exception.
    Can you copy and post the full text of the error message here?

  3. #3
    maas is offline Member
    Join Date
    Jul 2010
    Posts
    29
    Rep Power
    0

    Default

    java.lang.NullPointerException jspservice (_contract((File name)).java:211)

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,307
    Rep Power
    25

    Default

    What is the object on line 211 that could be null?

  5. #5
    maas is offline Member
    Join Date
    Jul 2010
    Posts
    29
    Rep Power
    0

    Default

    Hello Norm

    Is my code correct to upload a file? or is there is any useful code that I can use it? since I am a beginner and need some help

  6. #6
    arun9683 is offline Member
    Join Date
    Jun 2010
    Location
    Bangalore,India
    Posts
    70
    Rep Power
    0

    Default

    Hi maas,

    In some conditions the fileNm object becoming null. So please do check that.

    Post the complete error logs which help's better analizing the problem.
    Arun K R,Bangalore,India
    :)

  7. #7
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    826
    Rep Power
    6

    Default

    1.First thing is u should not put business logic in jsp.
    2.Go to java file created for jsp and check the exact place where you got error.
    Ramya:cool:

Similar Threads

  1. Trying upload file
    By johniem in forum JavaServer Pages (JSP) and JSTL
    Replies: 4
    Last Post: 07-01-2010, 10:31 AM
  2. file upload in jsp
    By mudit222 in forum JavaServer Pages (JSP) and JSTL
    Replies: 3
    Last Post: 04-20-2010, 08:10 PM
  3. :large file upload to server(chunk upload)
    By tommy_725 in forum Networking
    Replies: 0
    Last Post: 10-16-2009, 12:21 AM
  4. how to upload a file?
    By tommy in forum JavaServer Pages (JSP) and JSTL
    Replies: 4
    Last Post: 06-30-2008, 02:50 PM
  5. file upload
    By sundarjothi in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 06-27-2008, 11:52 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •