on 11-24-2009 3:04 PM
Hi,
I want to read an xsl file from a java class(which is located in a package com.a.b.c)
xsl file and the java class resides in the same package.(com.a.b.c)
The possible ways that i tried:
String xsltFile = "test.xsl";
String xsltFile = new File("test.xsl").toURL().toExternalForm( );
String xsltFile = new File("test.xsl").getAbsolutePath();
String xsltFile = new File("test.xsl").getPath( );
String xsltFile = "com/a/b/c/test.xsl"
All the above methods returns file path (where the application is deployed) but the actual xsl file doesn't exist there.
How should I read this "xsl file" from my java class which is located in the same path?
Could some one help me out on it?
Thanks & Regards,
Chandana.
Edited by: Chandana Lakku on Nov 25, 2009 7:52 AM
Hi Chandana,
Either move your .xsl file to the root directory of your package and use
new File("text.xsl");
, or leave the file where it is and use
new File("com/a/b/c/test.xsl");
.
Hope this helps.
Regards,
Alain
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Chandana,
You can try the below code of a servlet.
import java.io.IOException;
import java.io.OutputStream;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import jxl.Workbook;
import jxl.write.Label;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
public class Sample extends HttpServlet {
public void doGet
(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
OutputStream out = null;
try {
response.setContentType("application/vnd.ms-excel");
response.setHeader
("Content-Disposition", "attachment; filename=sampleName.xls");
WritableWorkbook w =
Workbook.createWorkbook(response.getOutputStream());
WritableSheet s = w.createSheet("Demo", 0);
s.addCell(new Label(0, 0, "Hello World"));
w.write();
w.close();
}
catch (Exception e){
throw new ServletException("Exception in Excel Sample Servlet", e);
}
finally{
if (out != null)
out.close();
}
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
84 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.