?
Solved

download a file using jsf/jsp

Posted on 2005-04-13
8
Medium Priority
?
1,047 Views
Last Modified: 2008-01-09
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
Comment
Question by:nagulas
  • 3
  • 3
6 Comments
 
LVL 29

Expert Comment

by:bloodredsun
ID: 13771274
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
 

Author Comment

by:nagulas
ID: 13774979
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
 

Author Comment

by:nagulas
ID: 13784935
Hello , Does no one know an answer to this one???
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 29

Expert Comment

by:bloodredsun
ID: 13785582
<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
 

Author Comment

by:nagulas
ID: 13796183
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
 
LVL 29

Accepted Solution

by:
bloodredsun earned 1200 total points
ID: 13796522
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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Tech giants such as Amazon and Google have sold Alexa and Echo to such an extent that they have become household names. And soon they are expected to be used by commoners in their homes, ordering takeout, picking out a song, answering trivia questio…
Exchange administrators are always vigilant about Exchange crashes and disasters that are possible any time. It is quite essential to identify the symptoms of a possible Exchange issue and be prepared with a proper recovery plan. There are multiple…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question