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



Home Answers Viewqa JSP-Servlet uploading file to tomcat server
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


jaswanth
uploading file to tomcat server
2 Answer(s)      2 years and 8 months ago
Posted in : JSP-Servlet


please tell me how to upload a file to the URL "http://192.168.12.7:8000/tomcat-docs/" ?

thanks !


Advertisement
View Answers

March 5, 2012 at 4:15 PM


1)page.jsp:

<%@ page language="java" %>
<HTML>
<FORM ENCTYPE="multipart/form-data" ACTION="upload.jsp" METHOD=POST>
<center>
<table border="0" bgcolor=#ccFDDEE>
<tr>
<center><td colspan="2" align="center"><B>UPLOAD THE FILE</B><center></td>
</tr>
<tr><td colspan="2" align="center"> </td></tr>
<tr><td><b>Choose the file To Upload:</b></td>
<td><INPUT NAME="file" TYPE="file"></td>
</tr>
<tr><td colspan="2" align="center"> </td></tr>
<tr><td colspan="2" align="center"><input type="submit" value="Send File"> </td></tr>
<table>
</center>
</FORM>
</HTML>

2)upload.jsp:

<%@ page import="java.io.*,java.sql.*,java.util.zip.*" %>
<%
String saveFile="";
String contentType = request.getContentType();
if((contentType != null)&&(contentType.indexOf("multipart/form-data") >= 0)){
DataInputStream in = new DataInputStream(request.getInputStream());
int formDataLength = request.getContentLength();
byte dataBytes[] = new byte[formDataLength];
int byteRead = 0;
int totalBytesRead = 0;
while(totalBytesRead < formDataLength){
byteRead = in.read(dataBytes, totalBytesRead,formDataLength);
totalBytesRead += byteRead;
}
String file = new String(dataBytes);
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;
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;
File ff = new File(saveFile);
FileOutputStream fileOut = new FileOutputStream(ff);
fileOut.write(dataBytes, startPos, (endPos - startPos));
fileOut.flush();
fileOut.close();
%><br><table border="2"><tr><td><b>You have successfully upload the file:</b>
<%out.println(saveFile);%></td></tr></table>
}
%>


March 7, 2012 at 6:14 PM


Thanks :)



Related Tutorials/Questions & Answers:
uploading file to tomcat server
uploading file to tomcat server  please tell me how to upload a file to the URL "http://192.168.12.7:8000/tomcat-docs/" ? thanks
Uploading File on Server
Uploading File on Server  Hello, Can someone explain or suggest example. How do i uploading files on the FTP Server. Thanks
Advertisements
Uploading the file on Server.
Uploading the file on Server This example will explain you how to upload the file on FTP server. ftp_put() command allows to upload an existing file on the server. For uploading a file onto the FTP server, first you have to login
file uploading - Java Server Faces Questions
file uploading  HI this is swathi.Thanku for answering previous questions.Previously u helped me in file uploading but is not working the description of problem is below: The file uploading code is working in lan
file uploading - Java Server Faces Questions
file uploading  Hi thi is swathi . Thanku for answreing previous questions .But its not working for file uploading . U ask me to send the entire code... for lan but its not working for server pls tell me where is the problem
war file deploy in tomcat server - WebSevices
war file deploy in tomcat server  can anyone tell me how i can deploy war file in tomcat server ????  to deploy ur war file ...jus start ur tomcat server then type http://localhost:8080 in ur address bar
file uploading - Java Server Faces Questions
file uploading   In the mozilla browser if we browse the file it takes only the file name not the complete path and file not found exception... of the specified file located on any machine
Tomcat Server
Tomcat Server  Why my tomcat server installation stop at using:jvm c:\program files\java\jdk 1.6.0\bin\client\jvm.dll. Even though i trying to install several times. please help me....   Installing Tomcat Server
uploading a file
uploading a file  When I am trying to upload a file to another system in lan at a location "http://192.168.12.5:8080/tomcat-docs/myapps",then it is giving the following error message "http://192.168.12.5:8080/tomcat-docs/myapps
FTP Server : Upload file
This tutorial contains description of file uploading to the FTP server using java
file uploading
file uploading  How to upload music files onto the server and save the file information to the mysql database fetch and play the music files on a display page without download thus streaming the files
uploading audio file iphone
uploading audio file iphone  uploading audio file iphone
servlet (tomcat server) and jar
servlet (tomcat server) and jar  how to create a jar file and where to place the jar file in tomecat server
Image uploading in FTP Server
Image uploading in FTP Server  I want to upload images to a ftp server every 1 hour automatically using java..please help
Tomcat server
Tomcat server  Can anyone tell me in simple words what this error is about.. ERROR org.hibernate.event.def.AbstractFlushingEventListener Could not synchronize database state with session org.hibernate.StaleObjectStateException
Uploading Multiple Image On Server?
Uploading Multiple Image On Server?  Hello sir, I am stuck with a problem of uploading multiple images on server. i have done a code which works... images dynamically on server. one live example of this is like facebook uploading
Tomcat Server
Tomcat Server In this section we will read about the Tomcat Server. Here we... is tomcat server, components of tomcat, features of tomcat and many more. What is Tomcat Server? Tomcat Server is a pure Java HTTP web server environment to run
File uploading - Ajax
File uploading  hi friends, how to uploading the file by using "AJAX".Please send the complete source code for this application   where u want to store the file Can u specify
Uploading a file using UploadBean
Uploading a file using UploadBean  Dear sir, In my project i have to upload the file and use the same file for getting a values from that uploaded .xls file.I used UploadBean for uploading .For the first time when i
query related to uploading file
query related to uploading file  hello friends i am doing my project in servlet and i want to upload a file and store file in local hard drive and file name and path in oracle database.with name file name and path i also want
File Uploading Problem
File Uploading Problem  I have a file uploading code but it create...: the request was rejected because no multipart boundary was found and my server side... = FileUpload.isMultipartContent(request); // Create a new file upload handler
File Uploading Problem
File Uploading Problem  I have a file uploading code but it create...: the request was rejected because no multipart boundary was found and my server side... = FileUpload.isMultipartContent(request); // Create a new file upload handler
Tomcat Server error - Framework
Tomcat Server error  I am doing problem on struts,spring integration.in that at the time of tomcat server starting SEVERE: Error listenerStart occurs.why this error will occurs please tell the reason
Tomcat Configuration For Eclipse Server
Tomcat Server? I am using Tomcat 6.0v Thanks In Advance   Install tomcat... and ready to run on tomcat server. Right panel content all application that are ready to run on tomcat server. And click on the finish button. After
File uploading - JSP-Servlet
File uploading  i am using file uploading code for multiple file and aslo for single file but i am getting problem that No such file found.... http://www.roseindia.net/jsp/file_upload/Sinle_upload.xhtml.shtml
Struts file uploading - Struts
Struts file uploading   Hi all, My application I am uploading... it is breaking while uploading the large file. Please let me know if you know any API... newDocumentForm = (NewDocumentForm) form; FormFile file
tomcat web server
Tomcat Web Server         ... the Tomcat Server Tomcat is an open source web server developed by Apache Group. Apache Tomcat is the servlet container that is used in the official
Tomcat server/any application server
Tomcat server/any application server  how the server understands request is coming from client and how can it give response within very short span of time
file uploading - JavaMail
file uploading  Hi thi is swathi.Thank s for giving the answers... fro local host but in case of server this code is not working java.security.AccessControlException: access denied (java.io.FilePermission /web/tomcat/temp
Uploading a .3gp file. - MobileApplications
Uploading a .3gp file.  sir, i m sending it again .i want code for java based mobile application, that can take .3GP video file and upload it to youtube using youtube's APIs. The video file would be located on a weblink
About running the Tomcat Server
About running the Tomcat Server   HI I want to run a simple... this Apache Software Foundation/Tomcat 5.0/webapps/ i created myapps... the java.class and pasted in classes folder. Next i created Servlet.html file
 

 

 

DMCA.com