Add hyperlinks in to report using JasperReports

I've designed jrxml with iReport with hyper-link functionality but its not working (the report is displaying, but hyperlink is not working).

I'm using this jsp page for displaying report:

<%
    //JasperPrint jasperPrint = (JasperPrint)session.getAttribute(ImageServlet.DEFAULT_JASPER_PRINT_SESSION_ATTRIBUTE);

    String filepath1 = request.getParameter("filepath"); 
    System.out.println("filepath:" + filepath1);
    String reportFile = filepath1;
    JasperDesign jasperDesign = JRXmlLoader.load(reportFile);
    JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
    java.util.Map<String, Object> params = new java.util.HashMap<String, Object>();
    DateFormat formatter;
    Date date, endDate;   
    formatter = new SimpleDateFormat("dd-mm-yyyy");
    date = formatter.parse("11-08-2012");
    endDate = formatter.parse("13-08-2012");
    HashMap<String, Object> values = new HashMap<String, Object>();

        values.put("camp", "tps1"); 
    JdbcTemplate myJdbcTemplate = null;
    net.sf.jasperreports.engine.JasperPrint jasperPrint = null;
    try {
        myJdbcTemplate = DaoFactory.getJdbcTemplate();
        if (myJdbcTemplate == null) {
        }
        //new apps.dbase.DBaseLink().OpenLink()
        jasperPrint = net.sf.jasperreports.engine.JasperFillManager.fillReport(jasperReport, values, myJdbcTemplate.getDataSource().getConnection());
        session.setAttribute("jasperprint", jasperPrint);
        java.io.PrintWriter printWriter = response.getWriter();
    } catch (Exception e) {
        e.printStackTrace();
    }
    if (request.getParameter("reload") != null || jasperPrint == null) {

        values = new HashMap<String, Object>();
        values.put("camp", "tps1");       
        jasperPrint = net.sf.jasperreports.engine.JasperFillManager.fillReport(jasperReport, values, myJdbcTemplate.getDataSource().getConnection());
        session.setAttribute(ImageServlet.DEFAULT_JASPER_PRINT_SESSION_ATTRIBUTE, jasperPrint);
    }

    JRHtmlExporter exporter = new JRHtmlExporter();

    int pageIndex = 0;
    int lastPageIndex = 0;
    if (jasperPrint.getPages() != null) {
        lastPageIndex = jasperPrint.getPages().size() - 1;
    }

    String pageStr = request.getParameter("page");
    System.out.println("page::" + pageStr);
    try {
        pageIndex = Integer.parseInt(pageStr);
    } catch (Exception e) {
    }

    if (pageIndex < 0) {
        pageIndex = 0;
    }
    System.out.println("pageindex::" + pageIndex);
    System.out.println("lastpage::" + lastPageIndex);

    if (pageIndex > lastPageIndex) {
        pageIndex = lastPageIndex;
    }
     JasperExportManager.exportReportToHtmlFile(jasperPrint,"/home/tulsi/Desktop/hi.html");
    StringBuffer sbuffer = new StringBuffer();
    PrintWriter out1 = response.getWriter();
    exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
    exporter.setParameter(JRExporterParameter.OUTPUT_STRING_BUFFER, sbuffer);
    //exporter.setParameter(net.sf.jasperreports.engine.JRExporterParameter.OUTPUT_WRITER, printWriter);
    exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI, "../servlets/image?image=");
    exporter.setParameter(JRExporterParameter.PAGE_INDEX, Integer.valueOf(pageIndex));
    exporter.setParameter(JRHtmlExporterParameter.HTML_HEADER, "");
    //exporter.setParameter(JRHtmlExporterParameter.BETWEEN_PAGES_HTML, "");
    exporter.setParameter(JRHtmlExporterParameter.HTML_FOOTER, "");

    exporter.exportReport();


%>

<html>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <head>
        <script>
            $("a#first").click(function() {
                var i1 = "0" ;
                var f =  $("input#filepath").val();

                $.ajax({
                    url: "viewer.jsp",
                   data:"page="+i1+"&filepath="+f ,
                    success: function(data){
                        $("#please").html(data);
                    }
                });
            });
            $("a#prev").click(function() {
                var i1 = $("input#pageIndex").val();
                var f =  $("input#filepath").val();
                i1 = parseInt(i1) - 1 ;

                $.ajax({
                    url: "viewer.jsp",
                   data:"page="+i1+"&filepath="+f ,
                    success: function(data){
                        $("#please").html(data);
                    }
                });

            });
            $("a#next").click(function() {

                var i1 = $("input#pageIndex").val();
                var f =  $("input#filepath").val();
                i1 = parseInt(i1) + 1 ;

                $.ajax({
                    url: "viewer.jsp",
                    data:"page="+i1+"&filepath="+f ,
                    success: function(data){
                        $("#please").html(data);
                    }
                });
            });
            $("a#last").click(function() {
                var i1 =  $("input#lastIndex").val();
                var f =  $("input#filepath").val();

                $.ajax({
                    url: "viewer.jsp",
                   data:"page="+i1+"&filepath="+f ,
                    success: function(data){
                        $("#please").html(data);
                    }
                });
            });
        </script>
    </head>
    <body text="#000000" link="#000000" alink="#000000" vlink="#000000">
        <div id="please" >
            <input type="hidden" id="pageIndex" value="<%=pageIndex%>" >
            <input type="hidden" id="lastIndex" value="<%=lastPageIndex%>" >
            <input type="hidden" id="filepath" value="<%=reportFile%>" >
            <%
                System.out.print("in ::" + pageIndex);
                if (pageIndex > 0) {
                    System.out.print("in if ");
            %>

            <a href="#"  id="first"  ><img alt="first" src="images/first.png" border="0"></a>
            <a href="#" id="prev"  ><img alt="pre" src="images/prev.png" border="0"></a></td>
                <%
                } else {
                    System.out.print("in else ");
                %>
        <img alt="first" src="images/first.png" border="0">
        <img alt="prev"  src="images/prev.png" border="0">
        <%
            }
            if (pageIndex < lastPageIndex) {
        %>
        <a  href="#" id="next" ><img alt="next" src="images/next.png" border="0"></a></td>
    <a href="#"  id="last"  ><img alt="last" src="images/last.png" border="0"></a></td>
        <%        } else {
        %>
<img alt="next" src="images/next.png" border="0">
<img alt="last" src="images/last.png" border="0">
<%    }
%>
<table  style=" width:200; border-style: solid; border: 1px; border-color: blue; "  >
    <tr><a href="DownloadAll?type=csv&filepath=<%= reportFile%>"  ><button> CSV</button></a></tr>
  <tr><a href="DownloadAll?type=pdf&filepath=<%= reportFile%>"  > <button>PDF</button></a></tr>
  <tr><a href="DownloadAll?type=xls&filepath=<%= reportFile%>"  > <button>XLS</button></a></tr>
  <tr><a href="DownloadAll?type=docx&filepath=<%= reportFile%>"  ><button>DOCX</button></a></tr>
</table>
<div>
    <%=sbuffer.toString()%>
</div>
</div>
</body>
</html>

I think that problem is in jasperPrint object.

Please guide me how to add hyperlink functionality.

Answers


i got answer on this link after so much effort this is very useful Drill-down with JSP pages


Need Your Help

Traveling Salesman: Matrix and Tours

matrix traveling-salesman

Consider the following matrix/array that contains the distances between 4 cities:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.