Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa JSP-Servlet Getting file size

Have Programming Question? Ask it here!
 
 
 


Jagadeesh
Getting file size
2 Answer(s)      5 years and 9 months ago
Posted in : JSP-Servlet



Advertisement
View Answers

November 11, 2008 at 12:31 AM


Hi friend,


<%@ page language="java" %>

<HTml>

<HEAD>
<TITLE>Display file upload form to the user</TITLE>

</HEAD>

<% // for uploading the file we used Encrypt type of multipart/form-data and input of file type to browse and submit the file %>

<BODY>
<FORM ENCTYPE="multipart/form-data" ACTION="SingleFileUpload_Action.jsp" METHOD=POST>

<br><br><br>

<center>
<table border="2" bgcolor=#ccFDD00 cellspacing="0" cellpadding="0">

<tr>
<center>
<td colspan="2">
<p align="center"><B>Single file Uploading in JSP</B>
<center>
</td></tr>
<tr><td><b>Choose the file To Upload:</b></td>

<td><INPUT NAME="F1" TYPE="file" size="40"></td></tr>

<tr>
<td colspan="2">
<p align="center">
<INPUT TYPE="submit" VALUE="Send File" ></p></td></tr>

</table>

</center>

</FORM>

</BODY>

</HTML>

-------------------------------------------


November 11, 2008 at 12:34 AM


file action code.

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

<%

//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

FileOutputStream fileOut = new FileOutputStream(saveFile);

fileOut.write(dataBytes, startPos, (endPos - startPos));

fileOut.flush();

fileOut.close();



%><Br><table border="2"><tr><td><b>You have successfully upload the file by the name of:</b>

<% out.println(saveFile); %></td></tr></table> <%

}

%>


-------------------------------------------------

Visit for more information.

http://www.roseindia.net/jsp/file_upload/index.shtml

Thanks.


Related Tutorials/Questions & Answers:
Getting file size - JSP-Servlet
Getting file size  Hello friends, I am doing a jsp project. File uploading is one part of that. When uploading i have to check the file size. For this i used the java method .length(). But, for all type of files
Getting the Size of a File in Java
Java file get size In this section, you will learn how to get the size... then calls the method length() which returns the size of the file in bytes. Then we have converted the size of file from bytes to kilo bytes. Here is the code
Advertisements
Getting ResultSet size - JSP-Servlet
Getting ResultSet size  Hello friends, what..., The "fetch size" is a hint to the driver to control internal buffering within... is also free to ignore the hint. A "fetch size" of 0 means "transfer all
track file size changes
track file size changes  How to track a change in file size
file size - JSP-Servlet
the file size. Anyone help me how to check the file size with this coding. I tried...file size  Hello friends, I got the file upload coding in the roseindia at the following url: http://www.roseindia.net/jsp/file
Java file get size
Java file get size In this section, you will learn how to get the size... then calls the method length() which returns the size of the file in bytes. Then we have converted the size of file from bytes to kilo bytes. Here is the code
limiting file size - JSP-Servlet
limiting file size  I 'am unable to limit the size of file usin jspx.Can some body guide me ? Thanks
limiting file size - JSP-Servlet
limiting file size  I 'am unable to limit the size of file using... uploadMaxFileSize 100m Set the size limit... 100k Set the threshold size - files
Getting A File's Mime Type In Java
Getting A File's Mime Type In Java  Getting A File's Mime Type In Java
File size limit - JSP-Servlet
File size limit  i am still facing same issue. After adding parameter in web.xml web application is giving error.here is my web.xml file... /WEB-INF/tlds/c.tld   Hi friend, To set the file
Problem in getting file path in js
Problem in getting file path in js  hi, I am using ofbiz framework , How i can get the file path in javascript for input type = "file" and i am using only firefox not other browser. so please help me it is very important for me
How a split a file into many based on size?
How a split a file into many based on size?  Consider a text file which has a size of 400 bytes, i need to split up the contents in that 400 bytes file into 100 bytes of separate files.So there should be totally 4 files should
Difference in size of .java & its respective .class file
Difference in size of .java & its respective .class file  Hai, I had created & compiled a java class named sample.java. The size of sample.java is 340KB. Whereas the size of its respective class file sample.class is 137KB
How to Increase Upload File Size Limit in php
How to Increase Upload File Size Limit in php  Increase Upload File.... But the default file upload size settings restrict you to upload large files. PHP default setting allowed only 2MB file upload size. So if you want to upload
Get File Size
Get File Size      ... in understanding  Get File Size. For this we have a class name" Get File... display the list of array file using for loop. Now in order to evaluate the size
How to adjust a size of a pdf file
How to adjust a size of a pdf file   ... adjust the size of a pdf file irrespective of the fact whether it exists or not. If it exists then its fine, otherwise a pdf file will be created. 
Limiting the Size of a Log File in Java
Limiting the Size of a Log File in Java  ... to limit the size of a log file in Java. Log files haven't any boundation at the file creation time but Java provides the facility for limiting the size of a log
Getting path name of uploading file in struts 2.1.8
Getting path name of uploading file in struts 2.1.8  In my question I used struts 2.8.1 instead of 2.1.8. Sorry
Getting path name of uploading file in struts 2.8.1
Getting path name of uploading file in struts 2.8.1  Hai! I am using struts 2.8.1. I want to upload file into database with the path name. How can I can get the original path name of the file in struts 2.8.1? It only display
Getting File path error - JSP-Servlet
Getting File path error  I have a requirement where i need to get certain properties on application login page start itself. I an currently using String str = request.getRealPath("/")+"a" + System.getProperty( "file.separator
Getting Parameter from a css styled jsp file to a java servlet file...
Getting Parameter from a css styled jsp file to a java servlet file... ... is it not getting the parameter??? How do i accept the value in the servlet file...; <h1 class="art-logo-name"><font size="10" face="Palatino
Getting the Maximum Size of a Preference Key and Value
Getting the Maximum Size of a Preference Key and Value       This section demonstrates you to get the maximum size of Preference key and value. You can see in the given example that we have
Java MappedByteBuffer example, How to create a large size file in java.
Java MappedByteBuffer example, How to create a large file in java. In this tutorial, you will see how to create a large file with the help...;} } Output C:\>java CreateFile File
How to create a zip file and how to compare zip size with normal text file
How to create a zip file and how to compare zip size with normal text file .../ZipCreateExample.shtml but when i verified the size of zip and normal file,normal file is showing... file based on one text file.i saw the code in the below link which was provided
What is the maximum size of a file that can be uploaded using PHP and how can we change this?
What is the maximum size of a file that can be uploaded using PHP and how can we change this?  What is the maximum size of a file that can be uploaded using PHP and how can we change
i am getting the problem when i am downloading the pdf file from oracle 10g database - Struts
i am getting the problem when i am downloading the pdf file from oracle 10g database  if i created the pdf file from pdf machine,it is storing into datbase and download the pdf file from database. but when i created the pdf file
Get all file size on FTP Server
In this section we are going to describe how to get size of FTP server files using java
Size of commarea
Size of commarea  hii, What is the size of commarea?   hello, Default size of commarea is 65k
Size in FLex
Size in FLex  Hi..... What is the difference between width, explicitWidth, measuredMinWidth, measuredWidth, and percentWidth? please tell me about that difference Thanks
Size in FLex
Size in FLex  Hi... I just want to know about... What happens in measure()? measuredHeight, measuredWidth, measuredMinHeight, measuredMinWidth are set. please give me an example with description... Thanks
Getting next Tag in the XML File
Getting next Tag in the XML File     ... File. JAXP (Java API for XML Processing) is an interface which provides parsing... = Factory.createXMLStreamReader(new FileInputStream(file)):-Creates a new
Getting Exception
Getting Exception  How to get exception from commented code in java
this is my file upload page, here i am not getting tags input field value to my servlet,please suggest a solution?
this is my file upload page, here i am not getting tags input field value to my... <input id="file' + counter + '" name = "file' + counter + '" type="file" /></td></tr>' + '<input id="Button' + counter
getting variables
getting variables   how to get variables from servlet program to webservice program
Jmagick get image size
size when using Jmagick ImageInfo ii = new ImageInfo(path+"\"+file...Jmagick get image size  Hi, How I can get the image size while using... to get the image size when using Jmagick ImageInfo ii = new ImageInfo(path
Servletoutputstream size limit.
Servletoutputstream size limit.  What is the maximum size of ServletOutputStream
javascript max size
javascript max size   How to retrive Max size in JavaScript
Servletoutputstream size limit.
Servletoutputstream size limit.  What is the maximum size of ServletOutputStream?   By default size is set to 10MB.You can increase your message size maximum 2000000000 bytes. That is size limit is 2000000000
hibernate.jdbc.batch_size
In this section, you will learn about the hibernate.jdbc.batch_size of the hibernate.cfg.xml.
getting the emplo
getting the emplo   I have one table "EMPLOYEEMASTER" contains 'emp id', 'employee name' for eg: emp id employee name... kumar i want the sql statement for getting like emp id
Getting NumberFormatException
Getting NumberFormatException  Thanks for the reply. Its works well, but whenever I'm using numeric value from 0010 to 0757 it is returning some garbage value. I dont have the idea what is going wrong. Please give me some idea
Fixed size tables
Fixed size tables  Can anyone help me in creating a fixed size table in mysql database
calculate size of array
calculate size of array  Is it possible to calculate the size of array using pointers in Java
size of all primitive data
size of all primitive data   java program for to find the size of all primitive data types in java
Getting NumberFormatException
Getting NumberFormatException  Hello Sir, I'm using Integer.parseInt(String str) function which returns a NumberFormatException(Unknown source). I also used Integer.parseInt(String str, int radix) but it also throws the exception
getting errors
getting errors  public class positive { public static void main(String[] args) { retainPositiveNumbers(a); } private static int n; private static int j; static int a[]={-1,2,3,4,-5}; static int
setting web page size
setting web page size  How to set the webpage size in Java
Java Class Size
Java Class Size  How to determine size of java class
Max size of iPhone application
Max size of iPhone application  Hi, I am developing iPhone application. There are many images and videos. I want to know allowed max size in MB. What is the max size of iphone application? Thanks   Hi, I think
Getting Data from XML File (Document)
Getting Data from XML File (Document)   ... on the console with a message "Enter xml file name: ". After getting... from a XML file. All xml files store the data. You can add and modify the data
 

 

 

DMCA.com