Link to home
Start Free TrialLog in
Avatar of nagulas
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("application/octet-stream");

response.setHeader("Content-Disposition", "attachment;filename=\"girish1.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.NullPointerException at com.sun.faces.el.valueBinidigImpl.<init>(ValueBindingImpl.java:98)
at com.sun.faces.ApplicationImpl.createValueBinding(ApplicationImpl.java: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,response 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.
Avatar of bloodredsun
bloodredsun
Flag of Australia image

Can you please show us the JSF code that doesn't work?

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?
Avatar of nagulas
nagulas

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)FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY);
            return appFactory.getApplication();
      }
      
      private static ValueBinding getValueBinding(String el)
      {
            return getApplication().createValueBinding(el);
      }

Avatar of nagulas

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,response 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.
Avatar of nagulas

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 = .....

ASKER CERTIFIED SOLUTION
Avatar of bloodredsun
bloodredsun
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial