Home Answers Viewqa JSP-Servlet uploading file to tomcat server

 
 


jaswanth
uploading file to tomcat server
2 Answer(s)      a year and 2 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 !

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 Pages:
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
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 - 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
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 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
TOMCAT
TOMCAT  When i am deploy the servlet class file in tomcat server i get the following errors pe Exception report message description The server encountered an internal error () that prevented it from fulfilling this request
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
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
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
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 Beginners
file uploading   hi, i am developing one stand alone j2se programming in that i have to upload a file to another system in the LAN and have to download from the server .i am using java.io. and java.net and swing .the task
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
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
Running and deploying Tomcat Server
Running and deploying Tomcat Server  HI Somebody has given... for servlet is like this Apache Software Foundation/Tomcat 5.0/webapps/ i created... in classes folder. Next i created Servlet.html file in myapps directory
file uploading - JSP-Servlet
file uploading  Hi, thanks a lot for your kind answer. Now my program... problem. Im not geeting the full output for the program. Even, the file is not uploaded to the server folder. Im not sure which part is having problem. Again, i've
FTP Server : Upload file
This tutorial contains description of file uploading to the FTP server using java
Uploading Files - Java Server Faces Questions
Uploading Files  Hello sir, I, succeeded in uploading file. But i face a problem, that i cant upload the file having size more than 1MB. So, Please give me the solution
uploading problem
uploading problem  i use glassfish server.. using netbeans for jsp... i wnat to upload a file to a folder 'doc' and insert corresponding data about file into database lib. i use navicat Mysql ... i use this code... <
Multiple file Uploading - JSP-Servlet
Multiple file Uploading   Hello everyone I am using jsp and my IDE is eclipse and back end is ms sql server i am trying to upload multiple... class for JSP: An error occurred at line: 9 in the generated java file
image uploading perminssion in server - JSP-Servlet
image uploading perminssion in server  Dear All, I am facing some problem image uploading in server that i working fine in my system, OS Ubuntu. but in server it is showing following error
Uploading website
file you can use mput command. 7) After uploading you web site... Uploading your website       Uploading Web Site After developing the web
Tomcat
Tomcat  to run one application in tomcat server which files we need.i think jsp,xml,html is sufficient
tomcat
tomcat  Is it necessary to restart the server if we change the JDK path in tomcat server?   Yes, Thanks   Yes, Thanks
tomcat server - Java Server Faces Questions
install INFO: Processing Context configuration file URL file:E:\tomcat\conf... file URL file:E:\tomcat\conf\Catalina\loc alhost\manager.xml Jul 28, 2008 10:42... URL file:E:\ tomcat\webapps\jsp-examples Jul 28, 2008 10:42:13 PM
image uploading perminssion in server - JSP-Servlet
image uploading perminssion in server  dear friend... following is my uploading code and i want to save some records... Status 500 - type Exception report message description The server
image uploading perminssion in server - JSP-Servlet
image uploading perminssion in server  Thanks deepak following my... to writing image file in this path.. in multipartRequest. if u have any other uploading script please help me.. thanks   Hi, Plz give
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
rename before uploading
rename before uploading  I need to change (rename)the file name/image name before uploading it so that the file gets uploaded on server with this new name
struts code for scan the file while uploading - Struts
struts code for scan the file while uploading  Hi, I want the file to be scanned with anti-virus while uploading into server. can provide me help... party means An API which used inside application server
tomcat
the following links: http://www.roseindia.net/quickguide/tomcat/tomcatdownloadinstall.shtml http://www.roseindia.net/web-application-server/tomcat/install...tomcat   i downloaded and installed taomcat server but my servlet
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
Tomcat
the project in tomcat where we can store the html and Jsp ad Java, XML files in the tomcat web apps folder. the following structure is correct or not Tomcat-web apps-my project(beside this one jsp file) Inside the my project WEB-INF
Same email-massage is sending twice in online server(tomcat) but working fine in my local server(Tomcat)..
Same email-massage is sending twice in online server(tomcat) but working fine in my local server(Tomcat)..  Sir, I created one project in jsp... mail to admin at specific time. In local Server(tomcat):::>When employee
Tomcat
Tomcat  i have a problem in starting tomcat server.. May 12, 2011 12... resolving reference java.io.FileNotFoundException: D:\Workspace\conf\tomcat... Global JNDI Resources javax.naming.NamingException: D:\Workspace\conf\tomcat
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 audio file iphone
uploading audio file iphone  uploading audio file iphone
TOMCAT
TOMCAT  why we got the error like HTTP Status 500 - type Exception report message description The server encountered an internal error () that prevented it from fulfilling this request. exception
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
image file upload to a web server
Tomcat 5 server. How can I upload a file to the web server?   Here is an example of uploading an image on the server. The user can browse the image...image file upload to a web server  Refer roseindia post http
Working with Tomcat Server
Working with Tomcat Server       This section explains how to work with Tomcat Server... and java  Server Pages. Tomcat is very easy to install and configure. 
Pass hidden veritable while uploading file - JSP-Servlet
fields while uploading file on server?" Thanks in advance... are uploading file, all the parameter other then file upload are null. Is it write...Pass hidden veritable while uploading file  Hi All, Is there any
tomcat server start up error - Struts
tomcat server start up error   Hai friends..... while running tomcat server ,I got a problem..... Sep 5, 2009 4:49:08 AM org.apache.catalina.core.AprLifecycleListener lifecycleEvent INFO: The Apache Tomcat Native
tomcat - JSP-Servlet
tomcat  i want to run my war file in server in tomcat... to how to assign static IP in tomcat.... i want to run my project in local-network... my project is in jsp
FORM Tag Correctly for Uploading Files.
from the browser to the Web server. This transferring (uploading) process... a complete FORM tag for file uploading: How To Write the FORM Tag Correctly for Uploading Files? <?php print("<html><form action=file
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

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.