Location finding error
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>
<body background="sumtextb.jpg" bgcolor="#FFFFFF" text="#000066" link="#3333CC" vlink="#666699" alink="#990099">
<!--mstheme--><font face="Verdana, Arial, Helvetica">
<p align="center"><Br>
<div align="center">
<center><!--mstheme--></font><table border="0"><tr><td>
<!--mstheme--><font face="Verdana, Arial, Helvetica">
<p align="center"><b>Your file size exceeded the limit.<br>You have not uploaded your photo</b>
</p>
<!--mstheme--></font>
</td></tr><tr><td>
<!--mstheme--><font face="Verdana, Arial, Helvetica">
<p align="center"><!--mstheme--></font></td></tr><tr><td>
<!--mstheme--><font face="Verdana, Arial, Helvetica">
<p align="center"><!--mstheme--></font></td></tr><tr><td>
<!--mstheme--><font face="Verdana, Arial, Helvetica">
<p align="center"><!--mstheme--></font></td></tr><tr><td>
<!--mstheme--><font face="Verdana, Arial, Helvetica">
<p align="center"><!--mstheme--></font></td></tr><tr><td>
<!--mstheme--><font face="Verdana, Arial, Helvetica">
<p align="center"><!--mstheme--></font></td></tr><tr><td>
<!--mstheme--><font face="Verdana, Arial, Helvetica">
<p align="center"><!--mstheme--></font></td></tr><tr><td>
<!--mstheme--><font face="Verdana, Arial, Helvetica">
<p align="center"><!--mstheme--></font></td></tr><tr><td>
<!--mstheme--><font face="Verdana, Arial, Helvetica">
<p align="center"><!--mstheme--></font></td></tr><tr><td>
<!--mstheme--><font face="Verdana, Arial, Helvetica">
<p align="center"><!--mstheme--></font></td></tr><tr><td><!--mstheme--><font face="Verdana, Arial, Helvetica"><p onclick="window.close()" align="center"><font face="Arial Narrow" size="3" color="#003366"><b><u>Close
Window</u></b></font><!--mstheme--></font></td></tr></table>
<!--mstheme--><font face="Verdana, Arial, Helvetica"> </center>
</div>
<%}else{
try
{
Statement st = con.createStatement();
rs = st.executeQuery("select photo from stud_detail where deptno='"+dno+"'");
}
catch (Exception ex)
{
out.println("Exception"+ex);
}String path=null;
while(rs.next()){path=rs.getString(1);}
File obj = new File("C:/Program Files/Apache Software Foundation/Tomcat 6.0/webapps/mca2006sfssjc.co.in/stud/images/"+path);
boolean ans = obj.delete();
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"));
/* File name should be given in below savefile variable*/
saveFile = saveFile.substring(saveFile.lastIndexOf("\\") + 1,saveFile.indexOf("\""));
//saveFile = "801.txt";
int mid= saveFile.lastIndexOf(".");
ext=saveFile.substring(mid+1,saveFile.length());
String fname = saveFile.substring(0,mid);
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("C:/Program Files/Apache Software Foundation/Tomcat 6.0/webapps/mca2006sfssjc.co.in/stud/images/"+num+"."+ext);^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
fileOut.write(dataBytes, startPos, (endPos - startPos));
fileOut.flush();
fileOut.close();
%>
<head>
<meta name="Microsoft Theme" content="sumipntg 011">
</head>
<body background="sumtextb.jpg" bgcolor="#FFFFFF" text="#000066" link="#3333CC" vlink="#666699" alink="#990099">
<p align="center"><Br>
<div align="center">
<center><!--mstheme--></font><table border="0"><tr><td>
<!--mstheme--><font face="Verdana, Arial, Helvetica">
<p align="center"><b>You have successfully uploaded your photo</b>
</p>
<!--mstheme--></font>
</td></tr><tr><td>
<!--mstheme--><font face="Verdana, Arial, Helvetica">
<p align="center"><!--mstheme--></font></td></tr><tr><td>
<!--mstheme--><font face="Verdana, Arial, Helvetica">
<p align="center"><!--mstheme--></font></td></tr><tr><td>
<!--mstheme--><font face="Verdana, Arial, Helvetica">
<p align="center"><!--mstheme--></font></td></tr><tr><td>
<!--mstheme--><font face="Verdana, Arial, Helvetica">
<p align="center"><!--mstheme--></font></td></tr><tr><td>
<!--mstheme--><font face="Verdana, Arial, Helvetica">
<p align="center"><!--mstheme--></font></td></tr><tr><td>
<!--mstheme--><font face="Verdana, Arial, Helvetica">
<p align="center"><!--mstheme--></font></td></tr><tr><td>
<!--mstheme--><font face="Verdana, Arial, Helvetica">
<p align="center"><!--mstheme--></font></td></tr><tr><td>
<!--mstheme--><font face="Verdana, Arial, Helvetica">
<p align="center"><!--mstheme--></font></td></tr><tr><td>
<!--mstheme--><font face="Verdana, Arial, Helvetica">
<p align="center"><!--mstheme--></font></td></tr><tr><td><!--mstheme--><font face="Verdana, Arial, Helvetica"><p onclick="window.close()" align="center"><font face="Arial Narrow" size="3" color="#003366"><b><u>Close
Window</u></b></font><!--mstheme--></font></td></tr></table>
<!--mstheme--><font face="Verdana, Arial, Helvetica"> </center>
</div>
<!--mstheme--></font>
<%
}}
%>
<%
if(formDataLength-202<102400){
String name = num+"."+ext;
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>
<BODY> <FORM ENCTYPE="multipart/form-data" ACTION=
"uploadandstore.jsp" METHOD=POST>
<br><br><br>
<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>
</BODY>
</HTML>
2)upload.jsp:
<%@ page import="java.io.*" %>
<%@ page import="java.sql.*" %>
<%
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 Tutorials/Questions & Answers:
Location finding error - JSP-ServletLocation finding 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
Finding A DateFinding 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
Advertisements
ModuleNotFoundError: No module named 'location' library, ModuleNotFoundError: No
module named '
location'
error...ModuleNotFoundError: No module named '
location' Hi,
My Python program is throwing following
error:
ModuleNotFoundError: No module named
errorerror while iam compiling iam getting expected
error 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
errorerror i have 404
error in my program plz tell me yhe solution about
errorerror i have 404
error in my program plz tell me yhe solution about
error/ServletUserEnquiryForm.shtml
getting an
error given below
SQLException caught: [Microsoft][ODBC SQL Server Driver]COUNT field incorrect or syntax
error
please suggest
ErrorError 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
errorerror 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.ADS_TO_REPLACE_1
This type
error also comes
errorerror When I deploye the example I have this message
cannot Deploy HelloWorld
Deployment
Error for module: HelloWorld:
Error occurred during deployment: Exception while deploying the app [HelloWorld
Location ReminderLocation 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
cursor location cursor
location hi,please how to change cursor
location by java code ,i use this code but not change the
location
JTextArea a=new JtextArea();
if(resultText.equalsIgnoreCase("class")){
a.append("a { \n }");
PointerInfo
error!!!!!!!!!error!!!!!!!!! st=con.createStatement();
int a=Integer.parseInt(txttrno.getText());
String b=txttname.getText();
String c=txtfrom.getText();
String d=txtto.getText
error!!!!!!!!!error!!!!!!!!! st=con.createStatement();
int a=Integer.parseInt(txttrno.getText());
String b=txttname.getText();
String c=txtfrom.getText();
String d=txtto.getText
error!!!!!!!!!error!!!!!!!!! st=con.createStatement();
int a=Integer.parseInt(txttrno.getText());
String b=txttname.getText();
String c=txtfrom.getText();
String d=txtto.getText
ErrorError Hi. I am getting
error in the following code after the line I have commented as
ERROR. How to solve this. Thanks in advance.
package...;");
//
ERROR
out.println(" var pattern
ErrorError Hi. I am getting
error in the following code after the line I have commented as
ERROR. How to solve this. Thanks in advance.
package...;");
//
ERROR
out.println(" var pattern
ErrorError Hi. I am getting
error in the following code after the line I have commented as
ERROR. How to solve this. Thanks in advance.
package...;");
//
ERROR
out.println(" var pattern
ErrorError Hi. I am getting
error in the following code after the line I have commented as
ERROR. How to solve this. Thanks in advance.
package...;");
//
ERROR
out.println(" var pattern = /^\d{3,5
error"+it);
}
}
this is my program i am getting an
error saying cannot find symbol class stringADS
errorerror whats the
error..............
import java.util.Scanner;
public class g {
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
int d,x,y;
System.out.println("Enter the first number
location - MobileApplicationslocation 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 java code on internetfinding java code on internet Is there anybody to help me?
i want to some java coding web sites.it is prerequest for me
finding the prime numbersfinding the prime numbers Hi, I am a beginner to java and I have problem with the code in
finding the prime numbers, can someone tell me about the problem.
Thanks.
Want to know about how to find out the given
mkmapkit location searchmkmapkit
location search How to create a
location search function that will allow the current
location search on the MKMapKit
iphone location frameworkiphone
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 engineFinding 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 smallest value, then the next etcFinding 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 page count in any fileFinding page count in any file Hi,
I want to find out the page count in any file (doc,ppt,pdf,image,etc...). Is there any universal API to deal with any file irrespective of the file extension.Its bit urgent. Please let me
Finding shapes in digital photos - javaFinding 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