Commons fileupload - wrong path
Hello All,
I'm using commons fileupload for File upload ...My problem is if the user chooses a file and edits the path or if the user types a file path incorrectly...how can i detect that the file does not exists in the specified directory path...
Help is greatly appreciated
Thanks...
Why would you have to? That's the browser's problem.
By the way, this is not an Apache support forum.
Similar Messages
-
when i use commons fileupload to do file uploading, i got an exception
"javax.servlet.ServletException: Servlet execution threw an exception
fileters.ExampleFilter.doFilter(ExampleFilter.java:101)"
root cause:
"java.lang.NoClassDefFoundError: org/apache/commons/io/output/DeferredFileOutputStream
anyone can tell me:
What does it mean and how can i solve this problem?
Shall I import commons io jar to implement file uploading?
ThanksI am having the this exception though I have placed both the jars in web-Inf/lib(commons-io-1.1.jar AND commons-fileupload-1.1.jar
any thoughts where it mightbe going wrong.
Do I need to update any other jar files as well. -
Hi,
I'm trying to use the commons-fileupload-1.1.jar file and I've placed it in my WEB-INF/lib folder. When I try to compile my java though, I get an error that reads: package org.apache.commons.fileupload does not exist. I'm importing like this:
import org.apache.commons.fileupload.DiskFileUpload;
I've searched for answers on this already but can't find anything. I don't know if I'm placing it in the wrong folder or what. I'm using Tomcat so I also tried placing the jar file in the common/lib and server/lib folders but neither solved the problem. I've read that I may need to set in my classpath, but I don't know how to do this. Any help is appreciated. ThanksI'm trying to use the commons-fileupload-1.1.jar
ar file and I've placed it in my WEB-INF/lib folder.
When I try to compile my java though, I get an error
r that reads: package
org.apache.commons.fileupload does not exist.
I'm importing like this:
import org.apache.commons.fileupload.DiskFileUpload;Placing the jar in the WEB-INF/lib is the correct thing to do. But this would take care of the runtime. For compilation, you HAVE to set the jar to the classpath.
javac -classpath "%CLASSPATH%;c:\Tomcat\MyApp\WEB-INF\lib\commons-fileupload-1.1.jar" MyClass.javaThis is how your command should look.
I would rather suggest you to use Ant and create a simple build script to take care of all the compilation and classpath part. -
Apache Jakarta Commons FileUpload misleading message
I have a JSP page doing file upload using commons FileUpload package. The code looks like this:
<%
DiskFileUpload upload = new DiskFileUpload();
List items = upload.parseRequest(request);
Iterator itr = items.iterator();
while(itr.hasNext()) {
FileItem item = (FileItem) itr.next();
// check if the current item is a form field or an uploaded file
if(item.isFormField()) {
String fieldName = item.getFieldName();
if(fieldName.equals("name"))
request.setAttribute("msg", "Thank You: " + item.getString());
} else {
File fullFile = new File(item.getName());
File savedFile = new File("c:\\tmp\\", fullFile.getName());
item.write(savedFile);
%>
The JSP successfully uploaded the files but it still show me HTTP Status 404 - c:\tmp (Access is denied).
What's wrong with my code? Thank you.I just found out that the problem that I have mentioned in my previous post has nothing to do with Jakarta Commons Fileupload. It happens whenever I try throwing an exception. And it happens only when I use Internet Explorer
Thanks,
Joe
See the code below...
/**** throw-error.jsp ***/
<%@ page language="java" session="false" isErrorPage="false" errorPage="catch-error.jsp" %>
<%
throw new Exception("Catch this!");
%>
/****** catch-error.jsp ****/
<%@ page language="java" session="false" isErrorPage="true" %>
<html>
<head>
</head>
<body>
<%
out.println(exception.getMessage());
%>
</body>
</html> -
Plm in fileupload with struts commons-fileupload-1.0.jar
In my application, I use commons-fileupload-1.0.jar for file upload.
In the Jsp page,
I use the <html:form action="EventDetailsForScheduler" enctype="multipart/form-data" method="POST">.
and a file for field
<html:file name="eventdetailsform" property="imageFile" size="40"/>
In the Formbean class I have a property imageFile of Type FormFile to capture this value.
I want the Action class to do the file uploading( I use the builtin ActionServlet only...No customized Servlet or anything..)
In the execute Method,
I use the following code
DiskFileUpload fu = new DiskFileUpload();
// If file size exceeds, a FileUploadException will be thrown
fu.setSizeMax(1000000);
List fileItems = fu.parseRequest(req);
Iterator itr = fileItems.iterator();
But the size() method of this Iterator returns zero only..ie.no file is sent for uploading..
I tried printing the file name in the
setImageFile() method of the bean.and is correctly printing.then why it is not retrived in the Action class?
Cannot I handle the fileuploading inside the Action class?
What cud be wrong?
Thanks in advance
AathiAny comments from someone from Oracle?
regards
Jan -
File size with Jakarta Commons FileUpload
Hello fella experts,
I am using the org.apache.commons.FileUpload package to upload a file via a servlet.
I'm implementing the DiskFileUpload() method in the servlet.
My problem is that I want to apply a file-size validation and specify that files with size greater than 1MB should not be uploaded.
How to accomplish this ?
Any suggessions ?
Thanx in advance.Hi, I'm trying this code, and it works pretty fine, but when I try to transfer a .zip file, it give me a .zip file that I can't extract.
Please.. Am I doing something wrong, do I miss something??
I set already the File Type to binary...
any comments..
public static void copyFiles(String server, String user, String pwd, String origen, String destino)
try {
FTPClient ftp = new FTPClient();
ftp.connect(server);
ftp.login(user,pwd);
ftp.setFileType(ftp.BINARY_FILE_TYPE);
//ftp.enterLocalPassiveMode();
ftp.changeWorkingDirectory(origen);
int reply = ftp.getReplyCode();
if(!FTPReply.isPositiveCompletion(reply)) {
ftp.disconnect();
FTPFile[] files = ftp.listFiles();
FTPFile ftpfile = null;
OutputStream output = null;
for (int i = 0; i < files.length; i++) {
ftpfile = files;
if (ftpfile.isFile()){
output = new FileOutputStream(new File(destino+ftpfile.getName()));
if (ftp.retrieveFile(ftpfile.getName(),output)){
output.close();
ftp.logout();
ftp.disconnect();
} catch (Exception e) {
e.printStackTrace();
System.out.println("Error : " + e.toString()); -
I'm rather new to jsp. I'm using myeclipse and I'm deploying my site on tomcat. I've been slowly working away on the errors in my log files. Most of the problems that I've run into have been missing jar files. The log error that I'm stuck on follows:
10:14:40,359 ERROR [Faces Servlet]:253 - Servlet.service() for servlet Faces Servlet threw exception
java.lang.NoClassDefFoundError: org/apache/commons/fileupload/FileUpload
at org.apache.myfaces.component.html.util.ExtensionsFilter.doFilter(ExtensionsFilter.java:115)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at com.wolverinecrane.view.util.SecurityFilter.doFilter(SecurityFilter.java:77)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Thread.java:595)
In my buildpath I have commons-fileupload-1.0.jar which includes org.apache.commons.fileupload which has the class FileUpload.class in it.
Any help on what may be going wrong here would be appreciated.
DanSolved:
http://javalive.com/modules/newbb/viewtopic.php?topic_id=355&post_id=1013&order=0&viewmode=flat&pid=0&forum=4#forumpost1013 -
Jakarta Commons FileUpload ; Internet Explorer Problem
Hi all,
Environment:
Tomcat 5 ;Apache 2; JDK 1.5.0; Jakarta Commons Fileupload 1.0
OS: Windoze XP
Previously I've used jakarta commons fileupload package to succussfully to upload a file.
However, I am trying to check the content type of the file and throw an exception if its not a jpeg file. The following code works great when I use firefox. But it fails when I use Internet Explorer!
When I supply an existing jpg file on my desktop as the input to the HTML form, the code works fine. However if I enter a non-existing jpg filename, I get a "HTTP 500 Internal Server Error"! I expect to get the "Wrong content type!" message (which my JSP throws as an exception and should be caught by the error page). This problem happens only with Internet Explorer. With firefox, I get the "Wrong Content Type" message as expected.
What could be the problem? Please advise.
Thanks
Joe.
Code follows......
/************** file-upload.html *************/
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>File Upload</title>
<script type="text/javascript" language="JavaScript">
<!--
function fileTypeCheck() {
var fileName = document.uploadForm.pic.value;
if (fileName == "") {
alert ("Please select a file to upload!");
return false;
var indexOfExt = fileName.lastIndexOf (".");
if (indexOfExt < 0) {
alert('You can only upload a .jpg/.jpeg/.gif file!');
return false;
var ext = fileName.substring(indexOfExt);
ext = ext.toLowerCase();
if (ext != '.jpg' && ext != 'jpeg') {
alert('You selected a ' + ext + ' file; Please select a .jpg/.jpeg file instead!');
return false;
return true;
//--></script>
</head>
<form action="uploadPhoto.jsp" enctype="multipart/form-data" method="post" name="uploadForm" onSubmit="return fileTypeCheck();">
<input type="file" accept="image/jpeg,image/gif" name="pic" size="50" />
<br />
<input type="submit" value="Send" />
</form>
<body>
</body>
</html>
/*************** photoUpload.jsp **************/
<%@ page language="java" session="false" import="org.apache.commons.fileupload.*, java.util.*" isErrorPage="false" errorPage="uploadPhotoError.jsp" %>
<%!
public void processUploadedFile(FileItem item, ServletResponse response) throws Exception {
try {
// Process a file upload
String contentType = item.getContentType();
if (! contentType.equals("image/jpeg") && ! contentType.equals("image/pjpeg")) {
throw new FileUploadException("Wrong content type!");
} catch (Exception ex) {
throw ex;
%>
<%
// Check that we have a file upload requeste
boolean isMultipart = FileUpload.isMultipartContent(request);
// Create a new file upload handler
DiskFileUpload upload = new DiskFileUpload();
// Parse the request
List /* FileItem */ items = upload.parseRequest(request);
// Process the uploaded items
Iterator iter = items.iterator();
while (iter.hasNext()) {
FileItem item = (FileItem) iter.next();
if (! item.isFormField()) {
processUploadedFile(item, response);
%>
<html>
<head>
</head>
<body>
File uploaded succesfully! Thank you!
</body>
</html>
/******** uploadPhotoError.jsp ****/
<%@ page language="java" session="false" isErrorPage="true" %>
<html>
<head>
</head>
<body>
<%
out.println(exception.getMessage());
%>
</body>
</html>I just found out that the problem that I have mentioned in my previous post has nothing to do with Jakarta Commons Fileupload. It happens whenever I try throwing an exception. And it happens only when I use Internet Explorer
Thanks,
Joe
See the code below...
/**** throw-error.jsp ***/
<%@ page language="java" session="false" isErrorPage="false" errorPage="catch-error.jsp" %>
<%
throw new Exception("Catch this!");
%>
/****** catch-error.jsp ****/
<%@ page language="java" session="false" isErrorPage="true" %>
<html>
<head>
</head>
<body>
<%
out.println(exception.getMessage());
%>
</body> -
Commons fileupload to delete a file
Has anyone used the jakarta commons fileupload package to delete a file? Is it possible?
There is a delete() method in the package, but I can't get it to work. Does anyone have any ideas?Fair comment, point taken. Yes, I realise I can do it straight from a servlet, and yes, there was another thorn that wasn't in the post (it was in a post elsewhere).
The point being that since I use the commons filupload to upload the files to the server in the first place - and give the user the option of creating a set of directories in which to place the file, if I the user then wants to delete the uploaded file the servlet has to have some way of recovering the path and getPath(), getAbsolutePath() etc don't find the right path - they only return a path: /bin/file- that was really the problem. -
I am trying to use apache commons fileupload and get this error
I am using tomcat 5.5 as application server and JDK 1.6,
does anybody have idea how to resolve this error ?
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
java.security.AccessControlException: access denied (java.util.PropertyPermission java.io.tmpdir read)
java.security.AccessControlContext.checkPermission(AccessControlContext.java:323)
java.security.AccessController.checkPermission(AccessController.java:546)
java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
java.lang.SecurityManager.checkPropertyAccess(SecurityManager.java:1285)
java.lang.System.getProperty(System.java:652)
org.apache.commons.fileupload.disk.DiskFileItem.getTempFile(DiskFileItem.java:611)
org.apache.commons.fileupload.disk.DiskFileItem.getOutputStream(DiskFileItem.java:556)
org.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:362)
org.apache.commons.fileupload.servlet.ServletFileUpload.parseRequest(ServletFileUpload.java:126)
project.UploadFiles.processRequest(UploadFiles.java:48)
project.UploadFiles.doPost(UploadFiles.java:107)
javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
sun.reflect.GeneratedMethodAccessor49.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:597)
org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:244)
java.security.AccessController.doPrivileged(Native Method)
javax.security.auth.Subject.doAsPrivileged(Subject.java:517)
org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:276)
org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:162)Make sure that the servlet has permissions to write to that directory. I've hit that snag before, and on linux I set the permissions to nobody nobody 775.
Good luck,
Krista -
Wrong path and application in registry protocol\stdFileEditing\Server ?
Hi
How come there is a wrong path in registry is it a security issue, error or just values not in use anymore ?
I check via regedit: HKEY_CLASSES_ROOT the key .pdf points to
AcroExch.Document the key curver points to AcroExch.Document.7
Under this i check
HKEY_CLASSES_ROOT\AcroExch.Document.7\protocol\StdFileEditing\server
the value is
"C:\Program Files\Adobe\Reader 9.0\Acrobat\Acrobat.exe" (Acrobat catalog and the exe file is not existing)
but in my filesystem the real path is
C:\Program Files\Adobe\Reader 9.0\Reader
and i think the program should be AcroRd32.exe instead
When I have corrected the key an update would reverse it to the old not existing value
So could anyone tell me why i se this behaviour ?
Regards
SEJHi Frank,
How did you call the application in a war?
Regards,
Violeta -
Attachements with apache commons fileupload
I'm using:
http://commons.apache.org/fileupload/
to write file on server side (Tomcat running on Windows with XP or 2003).
I'm sending data to servlet with doPost() as follows:
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try {
DiskFileItemFactory factory = new DiskFileItemFactory();
factory.setSizeThreshold(4096);
factory.setRepository(new File("test"));
ServletFileUpload upload = new ServletFileUpload(factory);
upload.setSizeMax(1000000);
List fileItems = upload.parseRequest(request);
Iterator i = fileItems.iterator();
String comment = ((FileItem) i.next()).getString();
FileItem fi = (FileItem) i.next();
String fileName = fi.getName();
// db
fi.write(new File("C:/", fileName));
} catch (Exception ex) {
out.print(ex.getMessage());
out.close();
}but it's response is:
HTTP Status 500 -
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: Servlet execution threw an exception
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:390)
root cause
java.lang.NoClassDefFoundError: org/apache/commons/io/output/DeferredFileOutputStream
org.apache.commons.fileupload.disk.DiskFileItemFactory.createItem(DiskFileItemFactory.java:196)
org.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:358)
org.apache.commons.fileupload.servlet.ServletFileUpload.parseRequest(ServletFileUpload.java:126)
Upload.doPost(Upload.java:69)
javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:390)
root cause
java.lang.ClassNotFoundException: org.apache.commons.io.output.DeferredFileOutputStream
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1360)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1206)
java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
org.apache.commons.fileupload.disk.DiskFileItemFactory.createItem(DiskFileItemFactory.java:196)
org.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:358)
org.apache.commons.fileupload.servlet.ServletFileUpload.parseRequest(ServletFileUpload.java:126)
Upload.doPost(Upload.java:69)
javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:390)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.16 logs.
Apache Tomcat/6.0.16don't know why.. any ideas?java.lang.ClassNotFoundException: org.apache.commons.io.output.DeferredFileOutputStreamThe mentioned class is missing in the runtime classpath.
Add it (in this specific case, the JAR file with the mentioned class) to the classpath and the problem will disappear.
This class is part of Commons IO. Read the dependencies page at FileUpload user guide which JAR's you all need. -
Wrong path for go.bat in portal integration
Hi Friends,
during the configuration of the portal integration in rspor_cust01 I get the message
'Windows can not find C:\usr.......\go.bat'.
Where can I change the path because it is in D:\usr\sap\......go.bat.
Thanks you for any help.
Rg JimbobHi Subbu,
I used workshop page properties to associate the image to the page.
framework/skins/classic/images/home.gif
- Shankar
Subbu Allamaraju <[email protected]> wrote:
Shankar,
Did you use any tag to create the img tag? Do you have any sample
HTML/JSP snippet?
Subbu
Shankar Bala wrote:
I created a new desktop and have the following problem. The imagelinks to portal
pages in the horizontal nav bar in the top have wrong path.
Example.
In the original portal the home page link in the nav bar has a imageassociated
with it in workshop.
\framework\skin\classic\images\home.gif
The partial url generated for the image looks liek this:
\mywebapp\\framework\skin\classic\images\home.gif.
I created a new desktop everything works fine except for the images.The href's
are created for the links but the image path is wrong.
the url generated is : \mywebapp\appmanager\framework\skin\classic\images\home.gif
The "appmanager" in the path causes the problem.
Is this a bug? -
Hi
Sorry to post it here, but I was unable to find where We can post JavaFX Issues.
This is a minor issue, but need to be adressed.
I always set my java Console to shown, to test my applets, etc.
While testing some JavaFX, I could note that JavaFX has a wrong path, or a wrong path chaining:
network: Connecting http://javafx.com/launch/lib/lib/basickit.jar with cookie "JSESSIONID=c3c4962140d944b30859de123fae; s_cc=true; s_sq=%5B%5BB%5D%5D"
java.io.FileNotFoundException: http://javafx.com/launch/lib/lib/basickit.jar
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at sun.plugin.PluginURLJarFileCallBack.downloadJAR(Unknown Source)
at sun.plugin.PluginURLJarFileCallBack.access$000(Unknown Source)
at sun.plugin.PluginURLJarFileCallBack$2.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.plugin.PluginURLJarFileCallBack.retrieve(Unknown Source)
at sun.net.www.protocol.jar.URLJarFile.retrieve(Unknown Source)
at sun.net.www.protocol.jar.URLJarFile.getJarFile(Unknown Source)
at sun.net.www.protocol.jar.JarFileFactory.get(Unknown Source)
at sun.net.www.protocol.jar.JarURLConnection.connect(Unknown Source)
(...)Note the correnct URL is
http://javafx.com/launch/lib/basickit.jar an not
http://javafx.com/launch/lib/lib/basickit.jar , without the extra /lib
A few lines later there is a correct call to basickit.jar :
network: Connecting http://javafx.com/launch/lib/basickit.jar.pack.gz with cookie "JSESSIONID=c3c4962140d944b30859de123fae; s_cc=true; s_sq=%5B%5BB%5D%5D"
network: ResponseCode for http://javafx.com/launch/lib/basickit.jar.pack.gz : 304
network: Encoding for http://javafx.com/launch/lib/basickit.jar.pack.gz : null
network: Disconnect connection to http://javafx.com/launch/lib/basickit.jar.pack.gzI hope it help to find out a fix.
A.Which applet were you running?It happens on several demos at JavaFX.com .
Perhaps in all of then. -
Update Reader 9.5.2. Windows7 wrong path
Waar kan ik het correcte pad invoeren?
Sorry, I have no idea what "wrong path" you are talking about? An error message during the update? How are you updating?
Maybe and uninstall (using http://labs.adobe.com/downloads/acrobatcleaner.html) and reinstall will fix the problem?
Maybe you are looking for
-
Generating XML File with Table data...
Hi All, Bear with me, with my Oracle XML knowledge,,, we have Oracle 8i ( Relaease 3) as our database, and managegement want to have XML type of Text file, with respect to data in the Customer Table. Expected XML tags would be the Column Names of the
-
How to populate the data in fields if we tab out at one field
Hi Gurus, I am new to OAF Technology and I've new requirement in custom OAF page. We have 12 fields like ID, Fname, Lname, Age, Address, Tphone etc.. If we enter ID in message text input field box and tab out, then it should populate all the remainin
-
Photoshop does not work properly
we purchased Adobe elemnets 13, but it was for students. The store hard downloaded it and said we had to put personal info in but then we saw it was for students and we are not. We returned it and they gave us the standard Photoshop but it does not
-
Standard samrtforms and print program for Bill of Lading in delivery
Is there a standard smartform and print program for Bill of Lading for delivery?
-
Possible of memory leak in the loop
Recently my application do get OutOfMemory issue. I realized the memory is keep on stack up as i saw in the task manager, the jlaunch keep growing and it won't drop back. That day i'm running a search function and it will query the table to retrieve