Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes JSP and the fly likes jxl.jar to be used in a .jsp file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "jxl.jar to be used in a .jsp file" Watch "jxl.jar to be used in a .jsp file" New topic
Author

jxl.jar to be used in a .jsp file

abdelmonaam kallali
Greenhorn

Joined: Mar 09, 2011
Posts: 7
Hi
I ran a standalone application that uses jxl and it works fine but when I imported the class file (writer.WriteExcel.class), generated in my project, into a .jsp file I get this message:
An error occurred at line: 1 in the generated java file
The type jxl.write.WritableSheet cannot be resolved. It is indirectly referenced from required .class files


An error occurred at line: 1 in the generated java file
The type jxl.write.WriteException cannot be resolved. It is indirectly referenced from required .class files


An error occurred at line: 1 in the generated java file
The type jxl.write.biff.RowsExceededException cannot be resolved. It is indirectly referenced from required .class files

An error occurred at line: 215 in the jsp file: /coverage/testCoverageMask1.jsp
jxl.WorkbookSettings cannot be resolved to a type
212: WriteExcel writeExcel = new WriteExcel();
213: File fw = new File(filename);
214:
215: jxl.WorkbookSettings wbSettings = new jxl.WorkbookSettings();
216:
217: wbSettings.setLocale(new Locale("en", "EN"));
218:


An error occurred at line: 215 in the jsp file: /coverage/testCoverageMask1.jsp
jxl.WorkbookSettings cannot be resolved to a type
212: WriteExcel writeExcel = new WriteExcel();
213: File fw = new File(filename);
214:
215: jxl.WorkbookSettings wbSettings = new jxl.WorkbookSettings();
216:
217: wbSettings.setLocale(new Locale("en", "EN"));
218:


An error occurred at line: 219 in the jsp file: /coverage/testCoverageMask1.jsp
jxl.write.WritableWorkbook cannot be resolved to a type
216:
217: wbSettings.setLocale(new Locale("en", "EN"));
218:
219: jxl.write.WritableWorkbook workbook = jxl.Workbook.createWorkbook(file, wbSettings);
220: workbook.createSheet("DVR Test", 0);
221: jxl.write.WritableSheet excelSheet = workbook.getSheet(0);
222: createLabel(excelSheet);


An error occurred at line: 219 in the jsp file: /coverage/testCoverageMask1.jsp
jxl.Workbook cannot be resolved to a type
216:
217: wbSettings.setLocale(new Locale("en", "EN"));
218:
219: jxl.write.WritableWorkbook workbook = jxl.Workbook.createWorkbook(file, wbSettings);
220: workbook.createSheet("DVR Test", 0);
221: jxl.write.WritableSheet excelSheet = workbook.getSheet(0);
222: createLabel(excelSheet);


An error occurred at line: 219 in the jsp file: /coverage/testCoverageMask1.jsp
file cannot be resolved
216:
217: wbSettings.setLocale(new Locale("en", "EN"));
218:
219: jxl.write.WritableWorkbook workbook = jxl.Workbook.createWorkbook(file, wbSettings);
220: workbook.createSheet("DVR Test", 0);
221: jxl.write.WritableSheet excelSheet = workbook.getSheet(0);
222: createLabel(excelSheet);


An error occurred at line: 221 in the jsp file: /coverage/testCoverageMask1.jsp
jxl.write.WritableSheet cannot be resolved to a type
218:
219: jxl.write.WritableWorkbook workbook = jxl.Workbook.createWorkbook(file, wbSettings);
220: workbook.createSheet("DVR Test", 0);
221: jxl.write.WritableSheet excelSheet = workbook.getSheet(0);
222: createLabel(excelSheet);
223: createContent(excelSheet);
224:

here is what I wrote in my .jsp file:
<%@ page import="writer.*"%>
<%@ page import="JSP_connection.build.classes.connection.*"%>
<%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*, java.sql.Connection, java.sql.DriverManager, java.sql.SQLException, java.text.DateFormat, java.util.*, java.lang.Math, java.io.*, java.net.*, jxl.*, jxl.CellView.*, jxl.Workbook.*, jxl.WorkbookSettings.*,jxl.format.Colour.*, jxl.format.UnderlineStyle.*, jxl.write.Label.*, jxl.write.Number.*, jxl.write.WritableFont.*, jxl.write.WritableWorkbook.*, jxl.write.WritableCell.*" errorPage="" %>
<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN">
.
.
....

<%
int i=0;
String variant = request.getParameter("variant");
String productType = request.getParameter("productType");
String filename = "C:\\xls\\Summary_"+variant+"_"+productType+".xls";
WriteExcel writeExcel = new WriteExcel();
File fw = new File(filename);

jxl.WorkbookSettings wbSettings = new jxl.WorkbookSettings();

wbSettings.setLocale(new Locale("en", "EN"));

jxl.write.WritableWorkbook workbook = jxl.Workbook.createWorkbook(file, wbSettings);
workbook.createSheet("DVR Test", 0);
jxl.write.WritableSheet excelSheet = workbook.getSheet(0);
createLabel(excelSheet);
...
.
.
I am using Tomcat 5.5
I have put jxl.jar in the java class path
and in ROOT\WEB-INF\lib

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60765
    
  65

You are moving Java code out of a Java class and into a JSP? Really?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
abdelmonaam kallali
Greenhorn

Joined: Mar 09, 2011
Posts: 7
No I am calling that class from jsp file using
<%@ page import="writer.*"%>
Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1016
I would echo Bear's comments about writing scriptlet code in a JSP.
Java code belongs in a java class. Either a servlet or a bean.

The java classpath is irrelevant to Tomcat.
Its classpath consists of the WEB-INF/classes directory, jar files in WEB-INF/lib and jar files in the server's /lib directories.

You say you have put jxl.jar in ROOT\WEB-INF\lib.
Where have you put your JSP? I'm guessing it should be ROOT/coverage/testCoverageMask1.jsp

Your import command looks funny. You have way too much in it.
You seem to have a bunch of classes with a .* after them?
Also you are importing a bunch that just don't need to be, because they are (eg java.lang)

Also don't be afraid to split up an import command over multiple lines for easier reading.
jxl.* looks correct, but jxl.CellView.*, jxl.Workbook.* .....
CellView and Workbook are actual classes.
I think it should be:





One other thing I have noticed is that this code outputs to a File.
This file will of course be on the Server, and not the machine running the web browser.
In order to send a file to the client you need to send it via the ServletOutputStream.

If you are sending binary output (rather than text) then a JSP is particularly unsuited, and a Servlet would be the appropriate tool.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60765
    
  65

But you are putting Java code (of any kind) into a JSP page? That's a horrible practice that has been discredited for over 9 years now.
abdelmonaam kallali
Greenhorn

Joined: Mar 09, 2011
Posts: 7
Hi Stefan
you are right I have too much import but that's because I was trying different imports.
I had them before as classes imported but did not help.
Anyway I tried to import the packages I need (what you suggested earlier) but it did not help, I still have the error "The type jxl.write.WritableSheet cannot be resolved. It is indirectly referenced from required .class files....".

I did the following exercise:
_ I took out the import of the "writer.*". and the error of "indirectly referenced...." disappeared but I still have the other errors

org.apache.jasper.JasperException: Unable to compile class for JSP:

An error occurred at line: 215 in the jsp file: /coverage/testCoverageMask1.jsp
WorkbookSettings cannot be resolved to a type
212: //WriteExcel writeExcel = new WriteExcel();
213: File fw = new File(filename);
214:
215: WorkbookSettings wbSettings = new WorkbookSettings();
216:
217: wbSettings.setLocale(new Locale("en", "EN"));
218:


which means the jxl packages did not get imported. any ideas??

Hi Bear
Sorry I did not understand what you mean by "you are putting Java code (of any kind) into a JSP page?". Isn't that what we should do when creating JSP files?

Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41068
    
  43
The syntax you're using for the imports is wrong. There is a difference between importing "jxl.WorkbookSettings.*" and importing "jxl.WorkbookSettings", and whereas you are using the former, you should be using the latter. You may want to read up on the various syntax possibilities of the import statement.


Ping & DNS - my free Android networking tools app
abdelmonaam kallali
Greenhorn

Joined: Mar 09, 2011
Posts: 7
Hi Ulf
I tried that before but I got this error message:
An error occurred at line: 19 in the generated java file
Only a type can be imported. jxl.WorkbookSettings resolves to a package.

Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41068
    
  43
That's quite odd, jxl.WorkbookSettings is a class according to its javadocs. And even if it were a package, you would still be able to import it.
abdelmonaam kallali
Greenhorn

Joined: Mar 09, 2011
Posts: 7
That is why I am thinking that the package jxl.* is not seen by the JSP page.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41068
    
  43
Just to make sure: Is the JSP page part of the ROOT web app? You said that's where you put the jxl jar file.
abdelmonaam kallali
Greenhorn

Joined: Mar 09, 2011
Posts: 7
the JSP page is in a sub folder (called coverage) of ROOT and the jxl.jar is in ROOT\WEB-INF\lib
abdelmonaam kallali
Greenhorn

Joined: Mar 09, 2011
Posts: 7
Hi all and thank you for your responses.
I got the issue and it's as simple as restart Tomcat.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: jxl.jar to be used in a .jsp file
 
Similar Threads
Excelsheet content reading
Using JXL to edit an existing excel sheet withe new data
Writing a content in excel in incremental way
Read data from ExcelSheet
transfer data between Excel sheets