Location finding error 1 Answer(s) 2 years and 11 months ago
Posted in : JSP-Servlet
Location needs from drive name:
My file uploading program has an error. It requires the location should be given from the directory name. Instead of this if only parent directory is given it shows the error as file not found. Below is the coding.The problem line is marked ^ character. __________________________________________________ <%@ page import="java.io.*" %> <%@ include file="../jsp_files/dbcode.jsp"%> <%@ include file="../jsp_files/security_code.jsp" %> <%@ include file="../session_files/sessioncheck.jsp" %> <script src="../scripts/blockrclick.js"></script> <% int no = (Integer)session.getAttribute("deptno"); String num = String.valueOf(no); String dno = "03PA"+num; %> <% String ext = null; int formDataLength=0; //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 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; } if(formDataLength-202>102400){%> <head> <meta name="Microsoft Theme" content="sumipntg 011"> </head>
try { Statement st = con.createStatement(); int res = st.executeUpdate("update stud_detail set photo='"+name+"' where deptno='"+dno+"'"); } catch (Exception ex) { out.println("Exception"+ex); } }%> _______________________________________________________
View Answers
July 22, 2010 at 4:08 PM
Hi Friend,
Try the following code:
1)page.jsp: <%@ page language="java" %> <HTML> <HEAD><TITLE>Display file upload form to the user</TITLE></HEAD>
<% 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;
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://localhost: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();} } %>
Thanks
Related Pages:
Location finding error - JSP-Servlet Locationfinding error Location needs from drive name:
My file uploading program has an error. It requires the location should be given from... the error as file not found. Below is the coding.The problem line is marked
Doclet for finding missing comments - Java Tutorials
Doclet for finding missing comments
2002-06-05 The Java Specialists' Newsletter [Issue 049] - Doclet for finding missing comments
Author:
Dr. Heinz M... a Java specialist,
especially if it can be done remotely.
Doclet for finding
Project Location change - Development process
Project Location change Hi , I have developed mini project . In my machine everything is working fine. But i moved that folder to another machine.... but still am getting 503 error. Is there any possibility to run my project in LAN
Finding A Date Finding A Date My Frequency Start Date is 24-08-2012
My frequency end date - not defined
Calculation Frequency is Weekly(Sunday)
My calculation will be from 24-08-2012 to the following sunday
My question is how to find
Location Reminder Location Reminder Hi, i am planing to do a project called location... mark thar place in my mobile, and later if i visit that location,my mobile has to give a reminder.
How to mark a location on mobile using GPS?
Please give me
location - MobileApplications
location I want to do project in which when i go to college
my mobile should get automatically to silent mode using the location where the
college... location that come on our mobile display and silent the mobile.
im new to J2ME
finding divisors of a number finding divisors of a number write a c program to input a number and print all its divisors using while loop
finding divisors of a number finding divisors of a number write a c program to input a number and print all its divisors using while loop
finding divisors of a number finding divisors of a number write a c program to input a number and print all its divisors using while loop
finding java code on internet finding java code on internet Is there anybody to help me?
i want to some java coding web sites.it is prerequest for me
Automatic vehicle location (AVL)
Automatic vehicle location (AVL)
 ....
Automatic vehicle location is also called Telelocation and is an important tool which... for this, for example direction finding, signposts system, global positioning system. The direction
javax.servlet not found error
javax.servlet not found error why iam getting javax.servlet error while running my servlet program...after setting the classpath also i am finding that problem
mkmapkit location search
mkmapkit location search How to create a location search function that will allow the current location search on the MKMapKit
iphone location framework
iphone location framework Which framework do i need to add to get the iphone current location in iPhone frameworks?
Add core location to your existing frameworks.
CoreLocation.framework
 
Finding searching phrase of a search engine Finding searching phrase of a search engine how to find out searching phrase of a search engine..? like, if visitors enter the keyword to google, is is any possible to get that keyword
Finding Lost Frames - Java tutorial Finding Lost Frames
2001-05-10 The Java Specialists' Newsletter [Issue 019] - Finding Lost Frames
Author:
Dr. Heinz M. Kabutz
If you are reading... fact to the
Politburo, but perhaps I've read too many spy stories.
Finding
submit error - WebSevices
')
{
alert('Choose Your Country & Get the Location & Comapny list');
form.country.focus();
}
Error: The cmbHire value is null.
So tell the correct
remove given error
: cannot find symbol
symbol : variable out
location: class System
System.out.println("Hello");
^
1 error
j2me location updates programming
j2me location updates programming kindly please, assist me with with a j2me code for obtaining and sending GPS location updates periodicaly to the server IE; LATITUDE, LONGITUDE, SPEED, TIME. Am using netbeans IDE and PHP
Remote Location Handeling - RMI
Remote Location Handeling I have application where I want main control from one location and have to connect two more locations remotly and have... location
Location Api - MobileApplications Location Api I am using following code to get coordinates of location in gps.
On emulator in netbeans it shows me output as
2.0 2.0... a location provider:
Criteria cr= new Criteria();
public void
Finding smallest value, then the next etc Finding smallest value, then the next etc hi,
I know how to search for the smallest value index in an unsorted array so far with this:
double currentValue = dist[0];
int smallestIndex = 0;
for (int j
Finding shapes in digital photos - java Finding shapes in digital photos - java Hello,
I need some hints/tips regarding some project I'm doing. The project is about finding shapes in digital photos (JPEG file). Here's what I have to do:
A digital photo
timezone_location_get
timezone_location_get() Function in PHP
timezone_location_get alias DateTimeZone::getLocation returns location information for a timezone including country code, latitude/longitude and comments.
Syntax of timezone_location_get
Error in POI - Java Beginners Error in POI Hi friend,
I am working with Excel using POI API.I need to read an excel file and do some modifications and save this file into different location. Along with this I need to remove the extra sheets which
class not found error - JDBC
. if so which version and share the link or download location.
whether eclipse ide is available free to download. if so the location for the download.
reply
ERROR - Java Beginners
ERROR Hello Sir
i am getting error to this code
1.write... am getting an error that is
StringProgram.java:6: cannot resolve symbol
symbol : constructor String (java.io.InputStream)
location: class
J2me Map load error
J2me Map load error Hi ,
i am making a POC to load google map in my mobile,now i m getting the address of location by its lattitude and longitude in web page , but thing is i wana to store in my net beans emulator , its showing
JavaScript method location
JavaScript method location
 ... using location property of the window object. One of
them is location.href which
Applet Error - Applet
in the above code...as it is a very large code which isn't necessary for finding the error...
as itz only drawing strings or lines
error
error while iam compiling iam getting expected error
Program in javascript to show the current location
Program in javascript to show the current location Hi All,
Actually in my application ..i wanted to updated the current location each time it gets... location in JavaScript?
Thanks
Java Get Class Location
Java Get Class Location
 ... location. For this, we
have used the classes URL and ClassLoader. The class...(classLocation)
returns the location of the class.
import 
Finding all palindrome prime numbers - Java Beginners Finding all palindrome prime numbers How do i write a program to Find all palindrome prime numbers between two integers supplied as input (start and end points are excluded
Error- Error- Hello, I would like to know about XSD file.
I try to print XML file but I am getting error SAXException-- says
Content is not allowed in prolog.
Please help me
error
error i have 404 error in my program plz tell me yhe solution about
error
error i have 404 error in my program plz tell me yhe solution about
Java compilation error - JSP-Servlet
to my problem, but having some error as below..
Generated servlet error:
C...;
^
Generated servlet error:
C:\Program Files\Apache Software Foundation...;
^
Generated servlet error:
C:\Program
Error
Error I have created ajax with php for state and city. When I change state then city will not come in dropdown list and it give me error as 'Unknown Runtime Error'.
This error come only in IE browser, but in other brower
i need a java code for finding typemismatch in an editor.
i need a java code for finding typemismatch in an editor. hi im sriram,
i need a java code in such a way that typemismatch code is embedded with the simple java editor.
the sample output is shown below
!alt text
Java Compilation error - JSP-Servlet
with this package
i download package from the location http://commons.apache.org...-fileupload-1.2.1.jar but still there is a problem and when i compile my file this error...
symbol : variable ServletFileUpload
location: class UploadImage
File location in FileOutputStream - JSP-Servlet
File location in FileOutputStream Hai,
For uploading a file i... a method to specify a location to store the file which is uploaded. I required...\webapps\mca2006sfssjc.co.in\stud\images
by changing the location to the folder
Struts properties file location - Struts
Struts properties file location Hi,
Where struts properties file stored in web application. I mean which location. Thank u Hi Friend,
The struts.properties file can be locate anywhere on the classpath
error
error java.lang.unsupportedclassversionerror:bad major version at offset 6
how to solve this????
Hi,
Please check the version of framework used and also the JDK version.
This type error also comes when java file