path setting

path setting


Hello friends,

I download file uploading coding from the following url:
http://www.roseindia.net/jsp/file_upload/Sinle_upload.xhtml.shtml. And i changed the file saving path into a different folder. While setting this path i need to give the full path from drive name, instead of this if i give folder name only it shows error as cannot find the specified path. I ghad given the full coding here.------------------------------------------
<%@ 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);
}
}%>
--------------------------------------------------------------------------Two functions have full path in their parameters.
View Answers









Related Tutorials/Questions & Answers:
problem in setting path - Ant
Do some changes setting the path : 1)ANT_HOME=D:\installations\apache...problem in setting path  hi friends i am getting a problem in setting... the reply its urgent  Hi friend, Your code : i setted the path
Setting of java1.4.2 path
Setting of java1.4.2 path  Hello I have uploaded java1.4.2 into my laptop and i have done path settings for System variabales as Path (C:\j2sdk1.4.2\bin) and classpath(C:\j2sdk1.4.2\lib) .But when i write simple
Advertisements
path setting - JSP-Servlet
/Sinle_upload.xhtml.shtml. And i changed the file saving path into a different folder. While setting this path i need to give the full path from drive name, instead...path setting  Hello friends, I download file
path setting - JSP-Servlet
_upload.xhtml.shtml. And i changed the file saving path into a different folder. While setting this path i need to give the full path from drive name, instead of this if i...path setting   Hello friends, I download file uploading coding
path setting - JSP-Servlet
path setting  Hi, friends How to set the oracle 10g path on browser to servlet program
path setting for tomcat to java for Desktop PC - JDBC
path setting for tomcat to java for Desktop PC  Hi sir, I.... So my problem here is i dont know how to set path setting for that can u please... the following links which illustrates in detail the path setting
setting path problem for org.jfree files - Java Beginners
setting path problem for org.jfree files  Hi deepak, As u said, i have downloaded two files jar files and placed them in lib folder to work... org.jfree and so on........after setting the path, i have restarted my system also
setting keys
setting keys  Hi Sir\Mam,At present we are doing Payroll Project .I would like to set some special keys for my forms and i want the coding to do the same .Pls Provide me source code for setting keys as soon as possible
classpath and path for structs1.3.8
.....there is no need of setting path...classpath and path for structs1.3.8  How to set classpath and path for structs1.3.8 ?   just add struts-core-1.3.8.jar file to CLASSPATH
path classpath
path classpath  EXPLAIN PATH AND CLASSPATH ? DIFF send me ans plz..., Path is system wide variable that tells where to find your commands. Lets... be in path. While Classpath is Enviroment Variable that tells JVM or Java Tools where
Path was not found
Path was not found  The Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path
variable setting for servlet - JSP-Servlet
variable setting for servlet  how to set environment variable and class path variable for servlet and to compile servlet files i am using tomcat 6.0  Hi Friend, Please visit the following links: http
Regarding path settings in java
Regarding path settings in java  Hello I had a problem of setting paths in Java.I setted classpath(C:\java\j2sdk1.4.2\lib) and path(c:\java\j2sdk1.4.2\bin) in system variables. But when i compile simple java progrm
ModuleNotFoundError: No module named 'setting'
ModuleNotFoundError: No module named 'setting'  Hi, My Python... 'setting' How to remove the ModuleNotFoundError: No module named 'setting... to install padas library. You can install setting python with following command
Modifying the Path Example.
// Setting output of the path if (isset($_POST['posted'])) { $path = $_POST['path...Modifying the Path In this example, you will learn how to modify the corrupted path using $outpath command in PHP. This command will modify the path
setting web page size
setting web page size  How to set the webpage size in Java
absolute path in php - PHP
absolute path in php  how to get absolute path in php
No SDK with the name or path
or path....version xyz. Base SDK Missing. What is this error and how can i set... Missing or No SDK with the name or path for XYZ version follow the steps below and change the setting.. Project->Edit Project Settings->Build->Base
ModuleNotFoundError: No module named 'path'
ModuleNotFoundError: No module named 'path'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'path' How to remove the ModuleNotFoundError: No module named 'path' error
path - Java Beginners
meaning of path and classpath  what is the meaning of path and classpath. How it is set in environment variable.  Path and ClassPath in in JAVAJava ClassPath Resources:-http://www.roseindia.net/java/java-classpath.shtml
Setting file extension
Setting file extension  Hi, I have used FileChooser to save a file. When I was trying to save it, the extension of the file is showing 'File'. How can I save that file to .xls ? Thanks
how to set class path
how to set class path  how to set class path in java
Class path
. Setting the class path is mandatory to run a java application. Class path in java... the CLASSPATH environment variable. Setting the class path by using the -classpath.... ADS_TO_REPLACE_3 Setting the path by using the environment variable
Setting the default Java character encoding?
Setting the default Java character encoding?  Setting the default Java character encoding
path problem - Java Beginners
path problem  I dont know how to set the path. What path should we...-FINAL-20081019.jar in jdk's lib folder. I entered path as "C:\Program Files\Java\jdk1.6.0_07\lib" , is this correct? Becoz even after this path compilation
Setting File Attributes
Setting File Attributes  I would be glad if anyone could help me set file attributes in java I would like to know how to set the hidden file attribute or the read only file attribute. Thank you
Setting File Attributes
Setting File Attributes  I would be glad if anyone could help me set file attributes in java I would like to know how to set the hidden file attribute or the read only file attribute. Thank you
Setting environment variables
Setting environment variables  Hi, I have a java web application running on jboss AS. 1)How do I set the environment variable in jboss? 2)How do I get the environment variable from jboss
setting RGB for a circle
setting RGB for a circle  how can i change the color of the circle(not through filling it) and i want to use RGB (not regular colors such as black or red..) i should include RGB numbers (for example 240, 150, 19) but i am
Setting Cookie
Setting Cookie  setcookie function is used for setting up a cookie. In the following example, if you use $_COOKIE command, you will view one cookie value, and if you see print_r ($_COOKIE), you will view all cookie value. We have
PHP hide file path
PHP hide file path  PHP to read a path and convert that to the virtual link
Fileupload from source path to destination path
Fileupload from source path to destination path  first we will create... source path &Destination path fields and BOTH INPUT TYPES ARE "TEXT" we will give source path as statically where the .doc or .rtf files path will be their.and
Setting File Attributes
Setting File Attributes  I would be glad if anyone could help me set file attributes in java I would like to know how to set the hidden file attribute or the read only file attribute. Thank you   Hi Friend, If you want
How to give path to the Dfile?
How to give path to the Dfile?  Hello erveryone, I want to make... on sphinx, i have to give path to the sphinx4.jar file which is present in my... not linux ,i want to try above but in this i can't get the write Dfile path , can
Path Separator
Path Separator       In this example, path.separator is used to separate the path and file by semicolon (;). When it is run, Ant checks for the path separator and directory
ModuleNotFoundError: No module named 'django-setting'
ModuleNotFoundError: No module named 'django-setting'  Hi, My... named 'django-setting' How to remove the ModuleNotFoundError: No module named 'django-setting' error? Thanks   Hi, In your python
Class Path - Java Beginners
Class Path  Hello I was able to set the class path as You have......; there u can type the path both in user variables for administrator   Hi...-->environment variables--> there u can type the path both in user variables
File path for jar file
File path for jar file  Hi Experts, I have created one eclipse... path of the template, which is working as per expectation. But I have created... not found for the template file. Also I had tried to get that path from user
path - Java Beginners
path  how to set the path in environment variables to run java programs in my pc?   Hi friend, Read for more information. http://www.roseindia.net/java/learn-java-in-a-day/download-and-install-java.shtml
Setting File Attributes
Setting File Attributes  I would be glad if anyone could help me set file attributes in java I would like to know how to set the hidden file attribute or the read only file attribute. Thank you   Let me know
Setting source port on a Java Socket?
Setting source port on a Java Socket?  Is it possible to explicitly set the the source port on a Java Socket
How to get project path
How to get project path  my problem is,i have one jar file,in that one xml is their,i am adding this jar file to my project,my question is how i can open or get that xml path
How to get project path
How to get project path  my problem is,i have one jar file,in that one xml is their,i am adding this jar file to my project,my question is how i can open or get that xml path
interview path pdf
interview path pdf  Plz send me the paths of java core questions and answers pdfs or interview questions pdfs... the interview for any company for <1 year experience thanks for all of u in advance   Please visit
Error in context path
Error in context path   I Tried a Struts2 Login application having... = request.getContextPath(); System.out.println("Context Path " + contextPath... ... undeploy?path=/strutsDemo OK - Undeployed application at context path /strutsDemo
Add context path to URL for outputLink
Add context path to URL for outputLink  How to add context path to URL for outputLink
JSP Current Path
JSP Current Path          JSP Current Path is used to get the current path of the JSP page. Understand with ExampleADS_TO_REPLACE_1 The Tutorial
Enable Proxy Setting
In this section, you will learn to enable proxy setting for Maven using setting.xml file
Setting Variable Scope
Setting Variable Scope In this section we will learn about the different scope of the JSP variables. While developing the program you can store the variables in different scope. If you store the values in the application scope
Setting up the environment
Setting up the environment       To run the example of DbUnit in Eclipse, we need jar files of  DbUnit, JUnit and Jakarta Commons IO. DbUnit is available from

Ads