nagulas
asked on
download a file using jsf/jsp
I am trying to download a file using jsf/jsp. I am using the following code which works fine for a jsp page.
************************** ********** ********** ********** ********** ********
response.setContentType("a pplication /octet-str eam");
response.setHeader("Conten t-Disposit ion", "attachment;filename=\"gir ish1.jrxml \"");
String rdlxml=report.retrieveRDL( );
String myStr = "<parent><version num='1.0'/></parent>";
out.clearBuffer();
out.write(myStr);
out.flush();
************************** ********** ********** ********** ***
This displays a dialog box when the user clicks on a link (that redirects him to this page) giving him the choice to download the file and save it on the disk.
For my requirement , I need to retrieve the contents of the String myStr dynamically from within a bean. I am not able to do so , because my entire application is in jsf , except this one page. It throws the following exception
java.lang.NullPointerExcep tion at com.sun.faces.el.valueBini digImpl.<i nit>(Value BindingImp l.java:98)
at com.sun.faces.ApplicationI mpl.create ValueBindi ng(Applica tionImpl.j ava:292)
Somehow it is not able to get the value binding. I am not sure how to rectify this. I want to know how do I access the HttpServletrequest,respons e objects from within a java program without using the servlet service method?? Mebbe this will help to get around the problem. If anybody has any other suggestions please let me know.
**************************
response.setContentType("a
response.setHeader("Conten
String rdlxml=report.retrieveRDL(
String myStr = "<parent><version num='1.0'/></parent>";
out.clearBuffer();
out.write(myStr);
out.flush();
**************************
This displays a dialog box when the user clicks on a link (that redirects him to this page) giving him the choice to download the file and save it on the disk.
For my requirement , I need to retrieve the contents of the String myStr dynamically from within a bean. I am not able to do so , because my entire application is in jsf , except this one page. It throws the following exception
java.lang.NullPointerExcep
at com.sun.faces.ApplicationI
Somehow it is not able to get the value binding. I am not sure how to rectify this. I want to know how do I access the HttpServletrequest,respons
ASKER
Actually this one page is in jsp. So I am using the jsp usebean tag as follows:
<jsp:useBean id="web" class="Report"/>
It throws the above exception. That is specifically for the Valuebinding method shown below. I am actually extending an existing project. So I am not sure how this thing works.
private static Application getApplication()
{
ApplicationFactory appFactory = (ApplicationFactory)Factor yFinder.ge tFactory(F actoryFind er.APPLICA TION_FACTO RY);
return appFactory.getApplication( );
}
private static ValueBinding getValueBinding(String el)
{
return getApplication().createVal ueBinding( el);
}
<jsp:useBean id="web" class="Report"/>
It throws the above exception. That is specifically for the Valuebinding method shown below. I am actually extending an existing project. So I am not sure how this thing works.
private static Application getApplication()
{
ApplicationFactory appFactory = (ApplicationFactory)Factor
return appFactory.getApplication(
}
private static ValueBinding getValueBinding(String el)
{
return getApplication().createVal
}
ASKER
Hello , Does no one know an answer to this one???
<jsp:useBean id="web" class="Report"/>
This shouldn''t work. All beans must be declared in a package, so it should be <jsp:useBean id="web" class="com.examples.Report "/> or somehting similar.
>>I want to know how do I access the HttpServletrequest,respons e objects from within a java program without using the servlet service method??
Inside a servlet you would override the doPost or doGet method, you shouldn't use the service method.
This shouldn''t work. All beans must be declared in a package, so it should be <jsp:useBean id="web" class="com.examples.Report
>>I want to know how do I access the HttpServletrequest,respons
Inside a servlet you would override the doPost or doGet method, you shouldn't use the service method.
ASKER
I figured out the earlier exception , it was because I was not using a jsf component link to access the page , instead i was using a normal < a href..> . Now it doesnt get a get value binding error and I am able to access the method properly. I want to know , in my method that i m calling from the jsp page, how do i access a response object?? Something like
HttpServletResponse response = .....
HttpServletResponse response = .....
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If you're using EL, you should be able to use dot notation to access the bean and it's properties. Is that how you're doing it?