aspose file tools*
The moose likes JSP and the fly likes error is coming in file variable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "error is coming in file variable" Watch "error is coming in file variable" New topic
Author

error is coming in file variable

Megha Singhal
Ranch Hand

Joined: Feb 28, 2012
Posts: 225

i am making program for uploading file in the database and i am facing error

input.jsp


inputcon.jsp



error is coming @ following line


please help me in solving this
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10451
    
    8

Megha Singhal wrote:error is coming @ following line

So you want to tell us what the error is or is it top secret? Please read =>TellTheDetails


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
E Armitage
Rancher

Joined: Mar 17, 2012
Posts: 892
    
    9
1.) Did you import the java.io.File class first before using it?
2.) You should the error message if you get an error and only post if you didn't understand the error.
3.) Do not write Java processing logic in JSPs. Use a servlet for that. JSPs should only be used for presentation.
4.) Do not use the odbc driver. Find a jdbc driver from your database manufacturer and use that.
5.) Always close statements and connections in the finally block of a try/catch.
Megha Singhal
Ranch Hand

Joined: Feb 28, 2012
Posts: 225

error is "fileName cannot be resolved".
E Armitage
Rancher

Joined: Mar 17, 2012
Posts: 892
    
    9
So check in the code. Java is case sensitive so filename is not the same as fileName. Also see the other suggestions above.
Pramod Kumar Pandey
Ranch Hand

Joined: Dec 05, 2013
Posts: 51

actually in your code File f=new File(request.getParameter("fileName")); the value of argument is null.
when you use <input type="file"> you will not able to get the data from that page using request.getParameter(String) otherwise you will get null . you have to follow some instruction as follows :
1.> you will have to write enctype="multipart/form-data" as an attribute in your <form > tag.
2. when you will have to get tha data first you will have to check that field was type file or type text, because now there are two type of data is coming from that page text & file.
3. you will have to add two jars to your project Library named commons-fileupload-1.2.2.jar and commons-io-2.4.jar jars version may be changed.

may be following code would help.



and my jsp page was as follow :

Megha Singhal
Ranch Hand

Joined: Feb 28, 2012
Posts: 225


following error is coming for the above code

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: Wrapper cannot find servlet class upload.UploadImage or a class it depends on
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
java.lang.Thread.run(Unknown Source)


root cause

java.lang.ClassNotFoundException: upload.UploadImage
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1360)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1206)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
java.lang.Thread.run(Unknown Source)


note The full stack trace of the root cause is available in the Apache Tomcat/6.0.16 logs.


--------------------------------------------------------------------------------

Apache Tomcat/6.0.16


How can i remove this?
E Armitage
Rancher

Joined: Mar 17, 2012
Posts: 892
    
    9
Make sure that the class upload.UploadImage (or the jar file containing that class) is part of the war file you are deploying.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42289
    
  64
The above code does not have a class "upload.UploadImage" - did you make any changes to it?

Also note that that this bad example code, as it treats GET and POST interchangeably - which violates the HTTP specification. Don't ever do that, no matter how many servlet tutorials show that.


Ping & DNS - my free Android networking tools app
Megha Singhal
Ranch Hand

Joined: Feb 28, 2012
Posts: 225

Ulf Dittmer wrote:The above code does not have a class "upload.UploadImage" - did you make any changes to it?

Also note that that this bad example code, as it treats GET and POST interchangeably - which violates the HTTP specification. Don't ever do that, no matter how many servlet tutorials show that.


ok i'll remove override methods. and i am doing programming in eclipse so upload is project name so that's why i am using "upload.UploadImage"
Pramod Kumar Pandey
Ranch Hand

Joined: Dec 05, 2013
Posts: 51

Megha upload.UploadImage does not mean upload is your project Name and UploadImage is Servlet

but upload mean package name in which you'll put the UploadImage servlet. just try gud luck :thumbup:
Megha Singhal
Ranch Hand

Joined: Feb 28, 2012
Posts: 225


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: Error instantiating servlet class UploadImage
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
java.lang.Thread.run(Unknown Source)


root cause

java.lang.NoClassDefFoundError: org/apache/commons/fileupload/FileItemFactory
java.lang.Class.getDeclaredConstructors0(Native Method)
java.lang.Class.privateGetDeclaredConstructors(Unknown Source)
java.lang.Class.getConstructor0(Unknown Source)
java.lang.Class.newInstance0(Unknown Source)
java.lang.Class.newInstance(Unknown Source)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
java.lang.Thread.run(Unknown Source)


root cause

java.lang.ClassNotFoundException: org.apache.commons.fileupload.FileItemFactory
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1360)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1206)
java.lang.Class.getDeclaredConstructors0(Native Method)
java.lang.Class.privateGetDeclaredConstructors(Unknown Source)
java.lang.Class.getConstructor0(Unknown Source)
java.lang.Class.newInstance0(Unknown Source)
java.lang.Class.newInstance(Unknown Source)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
java.lang.Thread.run(Unknown Source)


note The full stack trace of the root cause is available in the Apache Tomcat/6.0.16 logs.


--------------------------------------------------------------------------------

Apache Tomcat/6.0.16


now i remove "upload" from UploadImage in web.xml now the above error is coming.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42289
    
  64
Apparently the jar files of the required libraries are not in WEB-INF/lib.
Megha Singhal
Ranch Hand

Joined: Feb 28, 2012
Posts: 225

Ulf Dittmer wrote:Apparently the jar files of the required libraries are not in WEB-INF/lib.


jar files are in the library, i externally added both the jar files.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42289
    
  64
To both the compile-time and runtime paths? If you're using an IDE, those can be different, and you need them in both.
Megha Singhal
Ranch Hand

Joined: Feb 28, 2012
Posts: 225

Ulf Dittmer wrote:To both the compile-time and runtime paths? If you're using an IDE, those can be different, and you need them in both.


This code is running now.
but where is the file uploading?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42289
    
  64
In whichever JSP/HTML page you implemented it. You already had such a page, and Pramod also posted one.
Pramod Kumar Pandey
Ranch Hand

Joined: Dec 05, 2013
Posts: 51

hello Megha now i m giving you the whole code ...but before it you just clean and build your project ... and in the project directory on your disk...within the dist/web/ create an folder named images where your images will be uploaded ...and then run my full code.
my jsp is


and servlet is
 
Don't get me started about those stupid light bulbs.
 
subject: error is coming in file variable