Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6076137
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:34:25+00:00 2026-05-23T10:34:25+00:00

I am using the following 2 codes to upload a file using JSP…. but

  • 0

I am using the following 2 codes to upload a file using JSP…. but I don´t get any error, but the file does not get uploaded…. do you know why?

Please help

Thanks
Sheeyla

<%@ page import="java.io.*" %>
<html>


<head><title>Documents Upload</title></head>

<body bgcolor=#F5F5F5>
<%
    //to get the content type information from JSP Request Header
    String contentType = request.getContentType();
    //here we are checking the content type is not equal to Null and
 //as well as the passed data from mulitpart/form-data is greater than or
 //equal to 0
    if ((contentType != null) && (contentType.indexOf("multipart/form-data") >= 0))
 {
        DataInputStream in = new DataInputStream(request.getInputStream());
        //we are taking the length of Content type data
        int formDataLength = request.getContentLength();
        byte dataBytes[] = new byte[formDataLength];
        int byteRead = 0;
        int totalBytesRead = 0;
        //this loop converting the uploaded file into byte code
        while (totalBytesRead < formDataLength) {
            byteRead = in.read(dataBytes, totalBytesRead,formDataLength);
            totalBytesRead += byteRead;
            }
        String file = new String(dataBytes);
        //for saving the file name
        String saveFile = file.substring(file.indexOf("filename=\"") + 10);
        saveFile = saveFile.substring(0, saveFile.indexOf("\n"));
        saveFile = saveFile.substring(saveFile.lastIndexOf("\\") + 1,saveFile.indexOf("\""));
        int lastIndex = contentType.lastIndexOf("=");
        String boundary = contentType.substring(lastIndex + 1,contentType.length());
        int pos;
        //extracting the index of file 
        pos = file.indexOf("filename=\"");
        pos = file.indexOf("\n", pos) + 1;
        pos = file.indexOf("\n", pos) + 1;
        pos = file.indexOf("\n", pos) + 1;
        int boundaryLocation = file.indexOf(boundary, pos) - 4;
        int startPos = ((file.substring(0, pos)).getBytes()).length;
        int endPos = ((file.substring(0, boundaryLocation)).getBytes()).length;
        // creating a new file with the same name and writing the 
//content in new file
        String folder = (String) new File(config.getServletContext().getRealPath("/")).getParent();
                folder= (String)folder.replace(File.separatorChar, '/');
                File savedFile = new File(folder +"/IngDemo/asbuilts/"+saveFile) ;  
        FileOutputStream fileOut = new FileOutputStream(folder + savedFile);    
        //FileOutputStream fileOut = new FileOutputStream(savedFile);
        fileOut.write(dataBytes, startPos, (endPos - startPos));
        fileOut.flush();
        fileOut.close();
        %><br><table border="0"><tr><td><b>You have successfully upload the file by the name of:</b>
        <% out.println(saveFile); %></td></tr></table>

<p><font size=2 face="Century Gothic"><b>NEW AS BUILT DATA TO ENTER</b></font></p>
<p><font size=1 color=red face="Century Gothic"><b>Note: Only enter data if this is an as built.<br>
If as built has been marked up, just re-upload.</b></font></p>
<form method=post action="CreateAs.jsp">
<table>
<tr><td><font size= 2 face="Century Gothic">Document Title (with rev number):</font></td>
<td><input type=text name="d_title" size=50></td></tr>
<tr><td><font size=2 face"Century Gothic">Issued by :</font></td>
<td><input type=text name="i_by" size=30></td></tr>
<tr><td><font size=2 face="Century Gothic">Issued date:</font></td>
<td><input type=text name="i_date" size=20></td>
<td><input type="hidden" name="l_ocation" value="<%=saveFile%>"></td>
</tr>
</table>
<p><input type=submit value=Submit><p>
</form>

<%
    }
%>

</body>
</html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T10:34:25+00:00Added an answer on May 23, 2026 at 10:34 am
    1. Your form is missing enctype="multipart/form-data"
    2. You are missing a <input type="file" /> so I don’t see where would the file come from
    3. Use commons-fileupload
    4. Don’t put java code in JSP. Put it in a servlet.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using the following code but don't know why thumbnails are not created.
I tried to use the file upload using Apache Commons but the following exception
I am using the following code to upload the file <asp:UpdatePanel ID=UpdatePanel18 runat=server> <ContentTemplate>
I am trying to upload file to rackspace cloud file using the following code:
Hi Im using the following code: http://vikaskanani.wordpress.com/2011/01/11/android-upload-image-or-file-using-http-post-multi-part/ To POST an image to a WCF
so i decided against using uploadify as i could not get any help on
Can I use the following jQuery code to perform file upload using POST method
In my MVC application, I am using following code to upload a file. MODEL
When I upload files in Yii using the following code it generates an error.
I'm using following code but cannot return data from MySQL. This is the output:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.