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...
<%@ page import="java.util.List" %>
<%@ page import="java.util.Iterator" %>
<%@ page import="java.io.File" %>
<%@ page import="org.apache.commons.fileupload.servlet.ServletFileUpload"%>
<%@ page import="org.apache.commons.fileupload.disk.DiskFileItemFactory"%>
<%@ page import="org.apache.commons.fileupload.*"%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="java.io.*,java.sql.*,java.util.zip.*" %>
<%@ page language="java" import="java.util.*,java.text.*" %>
<%!
String fileType="";
int cnt=0;
int count1=0,count2=0,count3=0,count4=0,count5=0,count6=0;
%>
<%
boolean isMultipart = ServletFileUpload.isMultipartContent(request);
if (!isMultipart) {
String id=request.getParameter("fileId");
String path1=request.getParameter("filePath");
String fileName=request.getParameter("fileNname");
String ftype=request.getParameter("fileType");
String file=request.getParameter("file");
}else {
FileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new
ServletFileUpload(factory);
List items = null;
try {
items = upload.parseRequest(request);
} catch (FileUploadException e) {
e.printStackTrace();
}
Iterator itr = items.iterator();
while (itr.hasNext())
{
FileItem item = (FileItem) itr.next();
if (item.isFormField())
{
String name = item.getFieldName();
String value = item.getString();
if(name.equals("fileType"))
{
fileType=value;
}
} else {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection
con=DriverManager.getConnection("jdbc:odbc:DNSlib");
Statement st=con.createStatement();
String id=session.getAttribute("fileid").toString();
ResultSet rs=st.executeQuery("select count(*) from
filePath where fileId='"+id+"' and fileType='PDF'");
while(rs.next())
{
cnt=rs.getInt(1);
}
if(cnt>0){
out.println("You can only uploaded one file with a
unique file Id..! please upload curresponding image files start new
upload");
%><font size="+3" color="white">
<TABLE>
<tr><td><form name="form1" action="closeupload.jsp" method="post" >
<button type="submit">new upload</input></form>
</TABLE>
<TABLE>
<TR><TD><form name="form2" action="upload12.jsp" method="post" >
<button type="submit">continue</button></form>
</TABLE><%
}else{
String itemName = item.getName();
File savedFile = new
File("C:/Users/nidi/Documents/NetBeansProjects/Library/web/doc/"+itemName);
item.write(savedFile);
String fname=session.getAttribute("filename").toString();
String path =(
"C:/Users/nidi/Documents/NetBeansProjects/Library/web/doc/"+itemName);
String fileP = new File(path).getName();
int i=st.executeUpdate ("insert into
filePath(fileId,filePath,fileName,fileType)
values("+id+",'"+fileP+"','"+fname+"','"+fileType+"')");
session.setAttribute("path1" , savedFile);
response.sendRedirect("upload12.jsp");
}} catch (Exception e) {
e.printStackTrace();
}
}
}
}
%>
my problem...:
firstly
org.apache.commons.fileupload.servlet.ServletFileUpload
not found....
i insert jar file commons-fileupload-1.1.1.
then problem solved...
bt real problem is when i upload files fusing mozilla browser...it
shows like this...
problem loading page..
The connection was reset
The connection to the server was reset while the page was loading.
The site could be temporarily unavailable or too busy. Try again in a few moments.
If you are unable to load any pages, check your computer's network connection.
If your computer or network is protected by a firewall or proxy, make sure that Firefox is permitted to access the Web.
plz help me...
View Answers
August 13, 2012 at 4:07 PM
Here is a jsp application to upload any file and save it to database.
1)page.jsp
<%@ page language="java" %>
<Html>
<HEAD><TITLE>Display file upload form to the user</TITLE></HEAD>
<BODY>
<FORM ENCTYPE="multipart/form-data" ACTION="upload.jsp" METHOD=POST>
<br><br><br>
<center><table border="2" >
<tr><center><td colspan="2"><p align="center"><B>UPLOAD THE FILE</B><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">
<p align="right"><INPUT TYPE="submit" VALUE="Send File" ></p></td></tr>
<table>
</center>
</FORM>
</BODY>
</HTML>
2)upload.jsp
<%@ page import="java.io.*" %>
<%@ page import="java.sql.*" %>
<%
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);
String saveFile = file.substring(file.indexOf("filename=\"") + 10);
saveFile = saveFile.substring(0, saveFile.indexOf("\n"));
saveFile = saveFile.substring(saveFile.lastIndexOf("\\") + 1,saveFile.indexOf("\""));
out.println(saveFile);
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;
saveFile="C:/UploadedFiles/"+saveFile;
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>
<%
Connection connection = null;
String connectionURL = "jdbc:mysql://192.168.10.112:3306/test";
ResultSet rs = null;
PreparedStatement psmnt = null;
FileInputStream fis;
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
connection = DriverManager.getConnection(connectionURL, "root", "root");
File f = new File(saveFile);
psmnt = connection.prepareStatement("insert into file(file_data) values(?)");
fis = new FileInputStream(f);
psmnt.setBinaryStream(1, (InputStream)fis, (int)(f.length()));
int s = psmnt.executeUpdate();
if(s>0) {
System.out.println("Uploaded successfully !");
}
else {
System.out.println("unsucessfull to upload file.");
}
}
catch(Exception e){e.printStackTrace();}
}
%>
August 14, 2012 at 4:33 PM
Related Tutorials/Questions & Answers:
uploading problemuploading problem i use glassfish server..
using netbeans for jsp...();
}
}
}
}
%>
my
problem...:
firstly....
then
problem solved...
bt real
problem is when i upload files fusing mozilla
Problem in uploading java applicationProblem in
uploading java application I have uploaded my java application (folder created under webapps) using Filezilla FtpClient.Application... this
problem Advertisements
File Uploading ProblemFile
Uploading Problem I have a file
uploading code but it create
problem
$(document).ready(function(){
$('#upload').click(function(){
var... it gives the
problem
org.apache.commons.fileupload.FileUploadException
File Uploading ProblemFile
Uploading Problem I have a file
uploading code but it create
problem
$(document).ready(function(){
$('#upload').click(function(){
var... it gives the
problem
org.apache.commons.fileupload.FileUploadException
Problem in uploading image to to mysql databaseProblem in
uploading image to to mysql database Hi, need some help here, i have a program where a user can input name, city and upload image. when... have no
problem in saving the image in the folder, my
problem is it can't save
Problem in uploading image to to mysql databaseProblem in
uploading image to to mysql database Hi, need some help here, i have a program where a user can input name, city and upload image. when... have no
problem in saving the image in the folder, my
problem is it can't save
Uploading filesUploading files Hi,
Please provide html code for my question.
I need to insert the browsed files temporarily to text area while attaching more than one files during mailing
uploading a fileuploading 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
File uploading - JSP-ServletFile 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 a exception is thrown
Please suggest me to solve this
problem
Thank & Regards
Image uploadingImage uploading Hi,can anyone explain the following code.
The code related to
uploading an image file to oracle database using java servlet.
CODE
import java.io.*;
import java.io.IOException;
import
Uploading a .3gp file. - MobileApplicationsUploading 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... level
problem for u people. Isn't it??????
reply me
Drag and drop file uploading - AjaxDrag and drop file uploading Hi all, This is NageswaraRao i want file
uploading feature on my web development..using drag and drop mouse functionality.
Problem:I have Created one Text area when i drop the file on text area
Uploading File on ServerUploading File on Server Hello,
Can someone explain or suggest example. How do i
uploading files on the FTP Server.
Thanks
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 fine for
uploading single image,but it doesn't work with
uploading multiple
Uploading a Software and storing in the databaseUploading a Software and storing in the database I want to upload....
The coding present in the site for
uploading and storing in the database... me with the code for
uploading software of bigger size
File Uploading NotificationFile
Uploading Notification I am
uploading files in my application and i want to know how can i know or be notified when file is uploaded. is there any file
uploading event there which can tell me that process is going
Uploading website
Uploading your website
Uploading Web Site
After developing the web... command.
7) After
uploading you web site, don't forgot to test it. User
uploading and copying filesuploading and copying files how can i upload and copy one file based on the given inputs and copy it from one directory to another
Image uploading in FTP ServerImage
uploading in FTP Server I want to upload images to a ftp server every 1 hour automatically using java..please help
uploading file to tomcat serveruploading file to tomcat server please tell me how to upload a file to the URL "http://192.168.12.7:8000/tomcat-docs/" ?
thanks
File uploading - AjaxFile 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
rename before uploadingrename 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
Uploading a file using UploadBeanUploading 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 filequery 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... to save the
uploading time and date in database.
please help me it is urgent
image uploading perminssion in server - JSP-Servletimage
uploading perminssion in server thanks dear,
but i am working in Linux Ubuntu, how can i set the path in server.
my
problem is i am not able to access the folders wherever we are
uploading the files, we are not able
Uploading image using jspUploading image using jsp how to upload image using jsp. Already i tried, But that image file does not read.
It returns only -1 without reading...("GET IMAGE
PROBLEM :: "+ex);
ex.printStackTrace();
}
return result;
}
%>
<
Struts file uploading - StrutsStruts file
uploading Hi all,
My application I am
uploading files using Struts FormFile.
Below is the code.
NewDocumentForm... it is breaking while
uploading the large file.
Please let me know if you know any API
video uploading using jspvideo
uploading using jsp how to upload a videos in web page using jsp
Hi,
You can upload your video with the help of JSP file upload code. Once file is upload you can play using any video player.
Get the code
excel uploading in jspexcel
uploading in jsp could you provide the source code for:
1)have to upload an empty excel sheet at client side i.e if client clicks an excel icon an empty excel sheet should open
2)when they fill data in that sheet and click
Uploading an image - JSP-ServletUploading an image I am doing a jsp project. In this
uploading an image is a part. For that i had done a coding for
uploading... and
uploading is done by different jsp coding. I don't know how to code for file size
file uploading - Java Server Faces Questions 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, but in server its not working.I think the
problem is www.godaddy.com didnt give any
uploading image in the formuploading image in the form Hi All,
I am working to build a form like railway registration form which accepts user id and password and image.../DisplayimageonJSPpageusingXML.shtml
To know about file
uploading using Struts2 you may go through the link, given
PHP error uploading file - PHPPHP error
uploading file I am getting error while
uploading a file in a folder in PHP ...
Warning: Cannot modify header information - headers already send
any idea
file uploading - JSP-Servlet 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... to solve the
problem as well. Thanks in advance.
Input File
image uploading perminssion in server - JSP-Servletimage
uploading perminssion in server Dear All,
I am facing some
problem image
uploading in server that i working fine in my system, OS Ubuntu...; Hi friend,
Plz give full source code with details to solve the
problem file Uploading - Development processfile Uploading Hi all, This is the
problem i am facing please help me and solve the problem.i want upload file from my localpc(computer)to any textarea in webapplication.when i drop the mouse on text area the file content
video uploading using jspvideo
uploading using jsp this is the code i hv written for
uploading..but the value in dropdown list is not captured..can any 1 tell the reason...; charset=ISO-8859-1">
<title>
uploading page</title>
</head>
uploading a text file into a databaseuploading a text file into a database how to upload a text file into a database using jchooser
import java.io.*;
import java.sql.*;
import javax.swing.*;
import java.awt.event.*;
public class UploadTextFile
file uploading using jspfile
uploading using jsp below file
uploading code has one error "toBytes[i-start]=fromBytes; " incompatable type error please help me how to solve... in
uploading ");
}
%>
Hi Friend,
Try the following code:
1
file uploading - JavaMailfile uploading Hi thi is swathi.Thank s for giving the answers to previous questions.I am getting the
problem with below code
FileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new
Uploading an image into the table - JSP-ServletUploading an image into the table how to upload an image into the table in java Hi friend,
Code to help in solving the
problem :
import java.sql.*;
import java.io.*;
class SaveImageToDatabase {
public
Uploading Multiple Files Using Jsp Uploading Multiple Files Using Jsp
... in file
uploading.
Inside the scriptlet
call the isMultipartContent() method.... If there is a
request for
uploading the file then it makes a object
change the name of the image after uploading the imagechange the name of the image after
uploading the image my form consists of a textbox and
uploading the image.after
uploading the image i want to change the name of the image with the content of the textbox before saving