• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1057
  • Last Modified:

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.
0
nagulas
Asked:
nagulas
  • 3
  • 3
1 Solution
 
bloodredsunCommented:
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?
0
 
nagulasAuthor Commented:
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);
      }

0
 
nagulasAuthor Commented:
Hello , Does no one know an answer to this one???
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

 
bloodredsunCommented:
<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.
0
 
nagulasAuthor Commented:
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 = .....

0
 
bloodredsunCommented:
in a jsp, you have implicit access to the response object so you don't need to  explicitly get it in the way you ask.

e.g.

<%= response.getBufferSize() %>
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now