Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Jagadeesh
path setting
0 Answer(s)      4 years and 7 months ago
Posted in : JSP-Servlet



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.

Advertisement
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
_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
/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
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
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
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
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
setting web page size
setting web page size  How to set the webpage size in Java
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
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
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
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 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 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
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
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
Setting the default Java character encoding?
Setting the default Java character encoding?  Setting the default Java character encoding
absolute path in php - PHP
absolute path in php  how to get absolute path in php
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
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
Modifying the Path Example.
; <body> <?php // Setting output of the path if (isset($_POST['posted...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 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
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
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 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 set class path
how to set class path  how to set class path in java
Advertisements
 

 

 

DMCA.com