开发者

Calling Java Method HttpServletResponse in flex 4

开发者 https://www.devze.com 2023-04-01 10:42 出处:网络
I ha开发者_JAVA百科ve a service class that creates reports in xls using dynamicjasper, I wonder how I can include a button in my flex app to execute this method.

I ha开发者_JAVA百科ve a service class that creates reports in xls using dynamicjasper, I wonder how I can include a button in my flex app to execute this method.

@Service("downloadService")
@Transactional
public class DownServiceRelTemp {

    private static Logger logger = Logger.getLogger("service");

    @Resource(name="sessionFactory")
    private SessionFactory sessionFactory;

    public void downloadXLS(HttpServletResponse response) throws ColumnBuilderException,
        ClassNotFoundException, JRException {

        logger.debug("Downloading Excel report");

        DynamicReport dr = LayouteRelTemp.buildReportLayout();
        JRDataSource ds = getDataSource();
        JasperReport jr = DynamicJasperHelper.generateJasperReport(dr, new ClassicLayoutManager(), null);
        JasperPrint jp = JasperFillManager.fillReport(jr, null, ds);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        Exporter.exportToXLS(jp, baos);
        String fileName = "MyReport.xls";
        response.setHeader("Content-Disposition", "inline; filename=" + fileName);
        response.setContentType("application/vnd.ms-excel");
        response.setContentLength(baos.size());
        Writer.write(response, baos);
    }

Any suggestions, do not have much experience with adobe flex and would like a simple help.


There's some ways to interactive flex with java

  1. Using Web Services
  2. Using servlets
  3. By Remoting objects. By AMF thecnology.

I recommend this tutorial of the evangelist James Ward, in this tutorial him explains the differents ways to connect flex and java with code example. That's how I learned to comunicate flex and Java

Notes that you need to check blazeDs Library

0

精彩评论

暂无评论...
验证码 换一张
取 消