This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Servlets and the fly likes error while trying to download Excel file using java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "error while trying to download Excel file using java" Watch "error while trying to download Excel file using java" New topic
Author

error while trying to download Excel file using java

Nash kumar
Greenhorn

Joined: Sep 23, 2012
Posts: 20
I am trying to download excel file from server after clicking on a link. I have written the below JSP and Servlet code. JSP and Servlet are both in the same folder. I get the error "The requested resource (/BulkAccess/Download) is not available" after clicking on hyperlink to download the excel file. Any help?

JSP CODE


Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60800
    
  65

Your href value should be a server-realtive URL that starts with the context path. See the JspFaq for more information.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Nash kumar
Greenhorn

Joined: Sep 23, 2012
Posts: 20
Could you please type the server-realtive URL for href value ? Thank you. It will be helpful.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60800
    
  65

Is there a part of the JspFaq that you did not understand? Which part? I'll make sure it is clarified.
Nash kumar
Greenhorn

Joined: Sep 23, 2012
Posts: 20
This is what I tried from FAQ.. Correct me if I am doing anything wrong.

Changed the JSP Code to :





Then got the below error.


javax.servlet.ServletException: Wrapper cannot find servlet class Download or a class it depends on
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
java.lang.Thread.run(Unknown Source)


root cause

java.lang.ClassNotFoundException: Download
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1680)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1526)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
java.lang.Thread.run(Unknown Source)

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60800
    
  65

Here is the relevant part of the stack trace:

What does that tell you?

Hint: perhaps the servlet is incorrectly configured?
Nash kumar
Greenhorn

Joined: Sep 23, 2012
Posts: 20
First I tried copying the servlet to the same folder as JSP file that didn't work. Getting the same class not found error .

Now, I tried creating a package and then changing the servlet mapping to below code. But not luck yet.

com.abc.bulk is the package name.

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60800
    
  65

Where did you place the class file?
Nash kumar
Greenhorn

Joined: Sep 23, 2012
Posts: 20
com.abc.bulk package. This contains the servlet class file. (Download.java)
Deepak Vishwakarma
Greenhorn

Joined: Aug 19, 2012
Posts: 4
Nash kumar wrote:I am trying to download excel file from server after clicking on a link. I have written the below JSP and Servlet code. JSP and Servlet are both in the same folder. I get the error "The requested resource (/BulkAccess/Download) is not available" after clicking on hyperlink to download the excel file. Any help?

JSP CODE





<body>
<a href = "http://localhost:8080/myApp/Download">Download</a>
</body>
you can use this one , its work hope you got it
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60800
    
  65

Not a good idea. Using and absolute URL is a poor practice. And it won't solve the issue in any case.
Bharath Kannan
Greenhorn

Joined: Aug 04, 2013
Posts: 2
@Bear Bibealut:
Please suggest any other alternative rather than using 'absoulte URL'. Ive a servlet defined for such a download, though use the absolute URL in the client html.
Thanks
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10172
    
    8

Welcome to the Ranch.
Did you go through the JspFaq which Bear suggested to the OP?


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Ishan Pandya
Ranch Hand

Joined: Feb 06, 2012
Posts: 219

Nash kumar wrote:com.abc.bulk package. This contains the servlet class file. (Download.java)


Are you sure about this statement?
I see some mismatch in .java file and .class file
you sould have .class file in com.abc.bulk


OCPJP
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: error while trying to download Excel file using java
 
Similar Threads
file download servlet does not work on IE8
how content disposition works
Downloading file
Download file from Mysql database
Getting the Servlet output in a JSP file