We need a separate servlet class to open a report of jasper for each button in report or not?

Mr President.

We need a separate servlet class to open a report of jasper for each button in report or not?

My code for the servlet is as under which works very well for a single report.

package ash.view;


import ash.model.SchoolAppModuleImpl;


import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;


import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;


import java.util.HashMap;
import java.util.Locale;
import java.util.Map;


import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperExportManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.engine.design.JasperDesign;
import net.sf.jasperreports.engine.xml.JRXmlLoader;


import oracle.jbo.client.Configuration;


@WebServlet(name = "ReportServlet", urlPatterns = { "/reportservlet" })
public class ReportServlet extends HttpServlet {
    private static final String CONTENT_TYPE = "text/html; charset=UTF-8";


    public void init(ServletConfig config) throws ServletException {
        super.init(config);
    }
    
    protected Connection getConnection() {
        
        PreparedStatement st = null;
        String amDef = "ash.model.SchoolAppModule";
        String config = "SchoolAppModuleLocal";
        SchoolAppModuleImpl am = (SchoolAppModuleImpl ) Configuration.createRootApplicationModule(amDef, config);
        
        st = am.getDBTransaction().createPreparedStatement("select 1 from dual", 0);
        Connection conn = null;    
    
        try {
            conn = st.getConnection();
            return conn;
        } catch (SQLException e) {
        }   
    
        return null;
    }


    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String var0 = "";
        try {
            var0 = request.getParameter("classId");
        } catch (Exception e) {
            e.printStackTrace();
        }
        response.setContentType(CONTENT_TYPE);
        Map parameters = new HashMap();
               parameters.put("format", "pdf");
               parameters.put("WEBDIR", getServletContext().getRealPath("/"));
               parameters.put("REPORT_LOCALE", new Locale("ar"));
        
        
               parameters.put("classId", new String(var0));
               Connection conn = null;
               InputStream is = null;
               try
               {
                 conn = getConnection();
                 is = getServletContext().getResourceAsStream("/WEB-INF/reports/ClassDataReport.jrxml");
        
        
                 response.setContentType("application/pdf");
                 response.addHeader("Content-Disposition", "attachment; filename=ClassDataReport.pdf");
                  
                 JasperDesign jasperDesign = JRXmlLoader.load(is);
                 JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
                 JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, conn);                    
                 JasperExportManager.exportReportToPdfStream(jasperPrint, response.getOutputStream());
                          
                 conn.close();
               }
               catch (Exception e) {
                 e.printStackTrace();
               } finally {
                 closeConnection(conn);
                 try {
                     if(is !=null){
                         is.close();
                     }                   
                    
                 } catch (Exception localException1)
                 {
                 }
               }
        
        PrintWriter out = response.getWriter();
        out.println("<html>");
        out.println("<head><title>ReportServlet</title></head>");
        out.println("<body>");
        out.println("<p>The servlet has received a GET. This is the reply.</p>");
        out.println("</body></html>");
        out.close();
    }
    
    protected static void closeConnection(Connection conn) {
        try {
            if(conn !=null){
                conn.close();
            }           
        } catch (Exception ex) {
            //  System.out.println("Developer Msg : Exception in printReport1Servlet.closeConnection()");
        }
    }
}

Concerning

It will be something like this:

  public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
          String var0 = "";
          String reportName = "";
          try {
              reportName = request.getParameter("reportName");
          } catch (Exception e) {
              e.printStackTrace();
          }
          response.setContentType(CONTENT_TYPE);
          Map parameters = new HashMap();
                 parameters.put("format", "pdf");
                 parameters.put("WEBDIR", getServletContext().getRealPath("/"));
                 parameters.put("REPORT_LOCALE", new Locale("ar"));

                 if(reportName.equals("report1"))
                 {
                   var0 = request.getParameter("classId");
                   parameters.put("classId", new String(var0));
                 }

                 if(reportName.equals("report2"))
                 {
                   Object value1 = request.getParameter("value1");
                   Object value2= request.getParameter("value2");
                   parameters.put("p1", value1);
                   parameters.put("p2", value2);
                 }

                 Connection conn = null;
                 InputStream is = null;
                 try
                 {
                   conn = getConnection();
                   is = getServletContext().getResourceAsStream("/WEB-INF/reports/"+reportName+".jrxml");

                   response.setContentType("application/pdf");
                   response.addHeader("Content-Disposition", "attachment; filename="+reportName+".pdf");

                   JasperDesign jasperDesign = JRXmlLoader.load(is);
                   JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
                   JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, conn);
                   JasperExportManager.exportReportToPdfStream(jasperPrint, response.getOutputStream());

                   conn.close();
                 }
                 catch (Exception e) {
                   e.printStackTrace();
                 } finally {
                   closeConnection(conn);
                   try {
                       if(is !=null){
                           is.close();
                       }                   

                   } catch (Exception localException1)
                   {
                   }
                 }

          PrintWriter out = response.getWriter();
          out.println("");
          out.println("ReportServlet");
          out.println("");
          out.println("

The servlet has received a GET. This is the reply.

"); out.println(""); out.close(); }

And the button that will call the report should be something like this;




Tags: Java

Similar Questions

  • Why do I need to reboot between print jobs? I downloaded a patch for my printer, but it did not help.

    Why do I need to reboot between print jobs?  I downloaded a patch for my printer, but it did not help.  Print jobs appear in my queue of the printer but does not print until I reboot between each job.

    I downloaded a patch for my printer, but it did not help.

    Hello

    This patch you downloaded and whence?

    I suggest that you do the following:

    Go to your printer manufacturer's Web site > key in your printer model number and operating system.

    Uninstall/reinstall your printer using the latest drivers from here your operating system.

    Most of the manufacturer will also have troubleshooting steps for you to take registered there, too.

    This can also help you:

    "Solve printer problems.

    http://Windows.Microsoft.com/en-us/Windows-Vista/troubleshoot-printer-problems

    "Solve printer problems.

    In the upper right corner, select your operating system from the menu drop-down.

    http://Windows.Microsoft.com/en-us/Windows/printer-problems-in-Windows-help#fix-printer-problems=Windows-XP&V1H=win8tab1&V2H=win7tab1&V3H=winvistatab1&v4h=winxptab1

    See you soon.

  • Need to separate Windows Acrobat DC again

    Hi all

    I need to the secret formula to open PDF files in a separate window (I need the windows side by side to compare designs)-not the new view by tabs in the ms of Acrobat.

    Thank you

    Chris

    Hi chrise87546491 ,

    Please try this step: -.

    Acrobat > edit > Preferences > General > uncheck "Open documents as tabs in the same window", then OK.

    Then relaunch the application.

    I would like to know if it works.

    Kind regards

    Christian

  • 30.0 Firefox is so slow since updated. IE &amp; Chrome not having problems loading pages, showing the blank pages, need two or more tests to open Web pages.

    30.0 Firefox is so slow since updated. IE & Chrome not having problems loading pages, showing the blank pages, need two or more tests to open Web pages. It seems to have something to do with the Visual data on the pages. My MSN homepage gets old and dies every time I open the page after the re-opening and closing of firefox. It takes forever! What is a memory drain? Each open page in a new session of firefox suffer the same fate.

    Start Firefox in Safe Mode {web link}
    While you are in safe mode;
    Press < Alt > or < F10 > to display the toolbar.
    Followed;

    Windows; Tools > Options
    Linux; Edit > Preferences
    Mac; name of the application > Preferences

    Then Advanced > General.
    Find and stop using hardware acceleration.

    Dig safe web sites and see if there is still a problem. Then restart.

  • I created a custom and registered with a specific name date format. However, when I open a new worksheet, my saved format does not display in the menu drop-down? Am hoping that I don't need to create the same format for each new sheet?

    I created a custom and registered with a specific name date format. However, when I open a new worksheet, my saved format does not appear in the menu drop-down? Am hoping that I don't need to create the same format for each new sheet?

    You must save the spreadsheet containing the new date as a model format and use this custom template for each new spreadsheet where you want that this date format personalized at your disposal.

  • need to separate instances/profiles WITHOUT manual profile selection

    My wife has a laptop (Windows XP, updated) running Firefox 3.6.12 that we
    both use when away from home. She has more than a dozen of saved tabs
    of course, who reappear whenever FF is started (and heaven help me
    If I close FF without them saved!).

    If a second instance is started, it shows just the home page - great.
    I'm not game close the first instance and then the second, in case
    the registered i1 tabs get buried (see supra by).

    For example, I have Eudora as an e-mail client on my desktop
    machine with two separate instances without interaction. This is the kind
    thing, I would like to achieve on his laptop with separate FF FF - one
    config/icon so that a completely different instance can be created and saved with its own data - not a dozen + tablets, but without interfering with the installation SWMBO. Is this possible, and if so someone can tell me how to do?

    I should mention that the FF Profile Manager is not * very * what to do
    We would like to - ideally two distinct from the desktop icons, each related to her
    Own profile with the equivalent of ' don't ask ' selected for each
    If we do not need to manually select a profile at startup. It is possible that the two bodies will be simultaneous.

    See this:

    http://KB.mozillazine.org/Starting_Firefox_or_Thunderbird_with_a_specified_profile

  • Is it possible under the EULA to have several virtual machines on a single physical hard disk while using the same OS license or do I need a separate license for each virtual computer?

    I have several programs that are not compatible with my 64 bit Windows 7 operating system.  I would like to run each different software under another virtual machine of VMWare (5 packs of different software programs and 5 different virtual machines of Windows XP).  These would all be installed on your laptop.  I can use the same license of Windows XP for each virtual machine, or do I need a separate XP license for each (different XP in case 5 licenses)?

    It is lifted directly from my EULA:

    1. GRANT OF LICENSE.
    The manufacturer that you grant the following rights, provided that
    comply you with all terms and conditions of this EULA:
    1.1 installation and use.  You may install, use, access,
    display and run one copy of the SOFTWARE on
    THE COMPUTER.  The SOFTWARE may not be used
    by more than two 2-processor both on the
    COMPUTER, unless a greater number is
    indicated on the certificate of authenticity.
    Then...
    This means that as long as you are running two or more instances of XP at the same TIME, you agree? Or does this mean that, after you install once, you have reached your limit?
    I imagine that most people (including those who are running Microsoft!) will say that the second interpretation is correct.
    However...
    If this is the case, anyone their hard drive as a backup to clone strategy would violate the EULA!
  • Whenever I try to change the settings for startup from the Control Panel, a pop up tells me that I need to activate Windows Defender and open

    I installed Microsoft Security Essentials today and I'm trying to edit startup programs. Whenever I try to change the settings for startup from the Control Panel, a pop up tells me that I need to activate Windows Defender and open.  However, most of the security will not allow Windows Defender be turned on and I want to change the startup parameters.  How can I accomplish this?

    Hello

    If you use Norton, AVG, Avira, Microsoft Security Essentials, McAfee, etc. the default action is for Windows Defender must be disabled, that these AntiVirus programs have their own Antispyware Applications.

    There is nothing to worry.

    Using both programs at the same time can cause system conflicts, etc.

    If you want to have additional protection against malware using the version FREE of Malwarebytes AntiMalware:

    http://www.Malwarebytes.org/products/malwarebytes_free

    And now edit startup in Vista without using Defender programs, use one of the following methods:

    "How to use MSCONFIG in Windows Vista"

    http://netsquirrel.com/Msconfig/msconfig_vista.html

    Or the program Autoruns for FREE:

    "V11.21 Autoruns for Windows"

    http://TechNet.Microsoft.com/en-us/sysinternals/bb963902

    See you soon.

  • Need to separate the query

    Hi all

    I have the below where all the WITH clause needs to separate query and SELECT article queries must be separated. Any help is very appreciated. Try SUBSTR and INSTR.

    SQL query:

    ######################################################################

    WITH

    test_does1 like)

    Select 'Y' in double

    )

    Select *.

    of test_does1

    UNION ALL

    SELECT 'X' FROM double

    UNION ALL

    SELECT 'A' FROM dual

    UNION ALL

    WITH

    test_does2 like)

    Select 'Y' in double

    )

    Select *.

    of test_does2

    ######################################################################

    OK... Then try the below (LISTAGG will not work in oracle 10g)

    -Separate with clause

    SELECT DBMS_XMLGEN. CONVERT (RTRIM (XMLAGG (XMLELEMENT (E, str |)))) "UNION ALL"). " (Extract ('//Text ()')), 'UNION ALL'), 1) lsval

    FROM (SELECT LEVEL, LTRIM (REPLACE (REGEXP_SUBSTR(str1,'[^,]+',1,LEVEL), CHR (10))) str)

    FROM (SELECT REPLACE (' WITH test_does1 AS))

    (SELECT "Y" FROM dual)

    )

    SELECT * from test_does1

    UNION ALL

    SELECT "X" FROM dual

    UNION ALL

    SELECT "A" dual FROM

    UNION ALL

    WITH test_does2 AS

    (SELECT "Y" FROM dual)

    )

    SELECT * FROM test_does2 ',' UNION ALL ',',') str1

    THE DOUBLE)

    CONNECT BY LEVEL<= length(regexp_replace(str1,="" '[^,]+'))="">

    WHERE the str AS "WITH % ';

    -Select to separate

    SELECT DBMS_XMLGEN. CONVERT (RTRIM (XMLAGG (XMLELEMENT (E, str |)))) "UNION ALL"). " (Extract ('//Text ()')), 'UNION ALL'), 1) lsval

    FROM (SELECT LEVEL, LTRIM (REPLACE (REGEXP_SUBSTR(str1,'[^,]+',1,LEVEL), CHR (10))) str)

    FROM (SELECT REPLACE (' WITH test_does1 AS))

    (SELECT "Y" FROM dual)

    )

    SELECT * from test_does1

    UNION ALL

    SELECT "X" FROM dual

    UNION ALL

    SELECT "A" dual FROM

    UNION ALL

    WITH test_does2 AS

    (SELECT "Y" FROM dual)

    )

    SELECT * FROM test_does2 ',' UNION ALL ',',') str1

    THE DOUBLE)

    CONNECT BY LEVEL<= length(regexp_replace(str1,="" '[^,]+'))="">

    WHERE str AS 'CHOOSE % ';

    -Unit tests

    SQL > SELECT DBMS_XMLGEN. CONVERT (RTRIM (XMLAGG (XMLELEMENT (E, str |)))) "UNION ALL"). " (Extract ('//Text ()')), 'UNION ALL'), 1) lsval

    2 FROM (SELECT LEVEL, LTRIM (REPLACE (REGEXP_SUBSTR(str1,'[^,]+',1,LEVEL), CHR (10))) str)

    3 (SELECT REPLACE (' WITH test_does1 AS))

    4 (SELECT "Y" FROM dual)

    5    )

    6. SELECT * FROM test_does1

    7 UNION ALL

    8 "X" SELECT FROM dual

    9 UNION ALL

    10. SELECT "A" dual FROM

    11 UNION ALL

    12 test_does2 WITH AS

    13 (SELECT "Y" FROM dual)

    14)

    15 SELECT * FROM test_does2 ',' UNION ALL ',',') str1

    16 DOUBLE)

    17 CONNECT BY LEVEL<= length(regexp_replace(str1,="" '[^,]+'))="">

    18. WHERE LIKE str "WITH % ';

    LSVAL

    --------------------------------------------------------------------------------

    WITH test_does1 AS (SELECT FROM dual 'Y') SELECT * FROM test_does1 UNION ALL

    WITH test_does2 AS (SELECT FROM dual 'Y') SELECT * FROM test_does2

    SQL > SELECT DBMS_XMLGEN. CONVERT (RTRIM (XMLAGG (XMLELEMENT (E, str |)))) "UNION ALL"). " (Extract ('//Text ()')), 'UNION ALL'), 1) lsval

    2 FROM (SELECT LEVEL, LTRIM (REPLACE (REGEXP_SUBSTR(str1,'[^,]+',1,LEVEL), CHR (10))) str)

    3 (SELECT REPLACE (' WITH test_does1 AS))

    4 (SELECT "Y" FROM dual)

    5    )

    6. SELECT * FROM test_does1

    7 UNION ALL

    8 "X" SELECT FROM dual

    9 UNION ALL

    10. SELECT "A" dual FROM

    11 UNION ALL

    12 test_does2 WITH AS

    13 (SELECT "Y" FROM dual)

    14)

    15 SELECT * FROM test_does2 ',' UNION ALL ',',') str1

    16 DOUBLE)

    17 CONNECT BY LEVEL<= length(regexp_replace(str1,="" '[^,]+'))="">

    18. WHERE str LIKE "SELECT % ';

    LSVAL

    --------------------------------------------------------------------------------

    SELECT 'X' FROM dual UNION ALL SELECT 'A' double

  • Adobe said I need an update in order to open a file specific .pdf... when I run the update is says I have the latest version for my OS. ???

    Adobe said I need an update in order to open a file specific .pdf... when I run the update is says I have the latest version for my OS. ???

    Alternatively, save the file of Chrome on your desktop - the one with the message. Then, open in Adobe Reader. It will not be solved by the upgrade, even if the message you tips in mind as well.

  • I need help! I try to open my PDF but I get this message on my Macbook Pro! "Before you display PDF documents in the browser, you must launch Adobe Reader and accept the end user license agreement, and then quit and relaunch the browser."

    I need help! I try to open my PDF but I get this message on my Macbook Pro! "Before you display PDF documents in the browser, you must launch Adobe Reader and accept the end user license agreement, and then quit and relaunch the browser." What should I do?

    Do exactly what the message says, and it will go away.

  • Access to a Java servlet class

    Can make a servlet running on the access of the server has a class defined on server B?
    More information:
    I am new to Java servlet programming and want to make sure that my web application is secure. I've implemented a Java class that returns information from the user (name, address, e-mail etc.) and I put in place of the jsp and servlet pages that access the class through a 'import my.class...» "for servlets and a ' @page import ="my.class... ". ' 'for the jsp. Pages jsp and servlets do session verification and authentication, but the class has nothing of all this - it's methods simply return the requested data. I don't want to put all the identifications in the class, but I want to make sure that there no way to other web servers out there on the internet could access this class in my web application. I don't think it is possible, but my fear is that some hacker out there could do it somehow remotely a @page import "my.class...". "on my Web server and then access my methods of the class? These web applications are run within a Glassfish 3.0 application server.

    Thank you!

    No.. Servlet running on a server can not access anything on server B that are not accessible via HTTP.
    Your class/jar files (and in fact anything under the WEB - INF directory) are not public.

    In fact, if you have WebApplicationA running on the server has WebApplicationB on the same server cannot access the WebApplicationA classes.

    You should not have problems of security in this regard.

    see you soon,
    evnafets

  • We travel New Zealand in February.  I have an iphone 6 s.  I also have an adapter to their electrical outlets.  Do I need a separate power transformer/converter?

    We travel to New Zealand in February.  I have an iphone 6 s.  I also have an adapter plug of NZ.  Do I need a transformer/power converter, too?

    N ° power supply for iPhone works with input voltages between 110 and 220 volts.

  • Do I need separate Adobe contribute for each user copies?

    I'm looking into using Adobe Contribute as a CMS for our intranet. Each Department has their own section, which they would like to publish and modify as needed. My guess is 'Yes', but to confirm, if anyone knows - what I have to buy copies of Adobe Contribute for each user who will be granted these permissions? If there are 6 departments - are talking us about to buy 6 copies of Contribute to be installed on their computer? Please advice... Thank you!

    Hello

    Thank you to the Adobe community.

    I wish to inform you that a contribute license can be installed on both machines max, but executed on one machine at a time.

    In your case if 6 users will work to contribute entered then you will need to buy 6 licenses of Adobe Contribute. But if only three users will work on this topic at a time then 3 licenses of contribute would be sufficient for you.

    I hope this helps!

    Shekhar

  • Install the Acrobat batch - open password needs me to reenter passwords for each file?

    Hello

    I'm sure I'm missing something simple here, I use processing documents Acrobat pro 9.4.4 trying to set a password to open multiple PDFs that are freshly created from sources .docx (using Acrobat to create) a batch.

    Batch, I take command of security and define "encrypt all the contents of the document" and check the "require a password to open the document", then key the password (twice) and press OK. Then I run.

    I output all option to add as a prefix to the files so I know that he treats. When I run the batch sequence, it appears on password security - settings window, and if I just press OK and do not re-enter the password (twice), the new pdf is created without a password to open (he said 'Secured' on the title bar when it opens). If I get the password (twice) for each processed file, then I find myself with open passwords to work on PDF files. I can't understand what I'm doing wrong - any suggestions welcome!

    I use Windows XP Professional 5.1.2600.

    Thank you very much for reading, hope that you have some ideas to help.

    Peter

    You must change the mode of interactivity. See my responses on this thread:

    http://forums.Adobe.com/message/3703411

Maybe you are looking for