Java report learning

xiaoxiao2021-03-05  20

The report is an important part of Web-based OA. I have experienced three phases.

The earliest is to output the report directly in IE, which is a way to make a report. This is logically simple

single. It is just that the customer is not very convenient when using it. Because some report output results, customers need to modify, such as deleting

In addition to some lines, some columns. To this end, I wrote a long code with JavaScript for custom output.

Columns, output different columns based on his choice. As for some customers to delete some rows. I suggest that customers will lose IE

The report is all copied to ELXCEL, and edit printing there.

Do a report with Ireport.

Learn to write the IERPORT to do a report, I spent a week. This is indeed a good report tool. I must make some reason

Use JDK1.3.1 so IREPORT0.1.0 that is better but the compatibility but the version is compared. But encounter some questions

question. For example, in the IREPORT, the form is used in line tools. There are various Bands on the design layout, each Band is planned

Divided a certain location. If I am in a region, such as the line painted in Column header, I am not careful to get out of Detail.

In the report, the vertical line cannot be output when the report is compiled and output, so I think the form is not too square in Ireport.

Convenient. I also doubt whether I used the tool version too low? There is also a problem with Ireport, the client needs

Adobe Acrbat Reader can only see the report. I want to use Ireport to make a cookie histogram, and I have not succeeded.

Call the IREPORT with a JSP file. Jasper file always pops up the dialog asks if it is opened or downloaded, I am chaos after I open it.

Code, it is also garbled after downloading. It is said that it is an Adobe Reader, and it is not changed from IE and Adobe Reader.

Row, depressed ing.

Use the servlet call .jasper file. It's still not working with Adobe Reader6.0, it may be that my jsper.jar version is too low, it is changed.

Adobe Reader 4.0 is successful. Specific example

JSP call: Test.jsp file

<% @ Page import = "DORI.JASPER.EENGINE. *"%>

<% @ Page Import = "java.util. *"%>

<% @ Page Import = "java.io. *"%>

<% @ Page Import = "java.sql. *"%>

<%

Java.sql.connection sqlcon; // Database connection object

Java.lang.String strcon; // Database connection string

// Load JDBC driver

Class.Forname ("com.microsoft.jdbc.sqlser.sqlserverdriver);

/ / Set the database connection string

Strcon = "JDBC: Microsoft: SQLSERVER: // localhost: 1433; DatabaseName = Kenoah";

//Connect to the database

Sqlcon = java.sql.driverManager.getConnection (StrCon, "SA", "SA");

File ReportFile = New File (Application.getRealPath ("/ Reports / Test1.jasper");

Out.println (ReportFile.getPath ());

Out.println (SQLCON);

Map parameters = new hashmap ();

Parameters.put ("ReportTitle", "P"); byte [] bytes = jasperrunmanager.runreporttopdf (

Reportfile.getPath (),

Parameters,

Sqlcon

);

Out.println (Bytes.length);

Response.setContentType ("Application / PDF");

Response.setContentLength; Bytes.length

ServletOutputStream OuputStream = response.getOutputStream ();

OuputStream.write (bytes, 0, bytes.length);

Ouputstream.flush ();

Ouputstream.close ();

%>

Servlet call: Testreport.java

Import javax.servlet. *;

Import javax.servlet.http. *;

Import dori.jasper.Engine. *;

Import java.io. *;

Import java.util. *;

Import java.sql. *;

Public Class TestReport Extends httpservlet {

Public void doget (httpservletRequest request, httpservletResponse response) throws servletexception, ioException {

Connection conn = NULL;

Try {

Class.Forname ("com.microsoft.jdbc.sqlser.sqlserverdriver);

Conn = drivermanager.getConnection ("JDBC: Microsoft: SQLServer: // localhost: 1433; DatabaseName = Kenoah", "SA", "SA");

ServletContext servletcontext = this.getServletContext ();

File ReportFile = New File (servletContext.getRealPath ("/ report / test1.jasper"));

Map parameters = new hashmap ();

String MyName = New String ("lxd");

Parameters.Put ("Name", MyName);

System.out.println (MyName);

System.out.Println ("Hello");

Byte [] bytes = jasperrunmanager.runreporttopdf (ReportFile.getPath (), parameters, conn;

Response.setContentType ("Application / PDF");

Response.setContentLength; Bytes.length;

ServletOutputStream outputStream = response.getOutputStream ();

OutputStream.write (bytes, 0, bytes.length);

OutputStream.flush ();

OutputStream.Close ();

} catch (jrexception jre) {

System.out.println ("JREXCEPTION:" JRE.GETMESSAGE ());} catch (Exception E) {

System.out.println ("Exception:" E.getMessage ());

}

}

Public void dopost (httpservletRequest request, httpservletResponse response) throws servletexception, ioException {

DOGET (Request, Response);

}

}

Export the report directly to Word

I think this is a good way to use the Web way OA. Simple production, just modify the original JSP file,

Put the output mode to call Word.

Then the output report calls Word directly, runs out if you pop up the dialog box to ask if you open or save it, choose Open, IE calls Word directly,

That customer can edit the output report directly in Word.

JSP file modified place: <% @ page contenttype = "Application / MSWORD; charset = GB2312"%> is the value of the ContentType.

Example: mytest.jsp

<% @ Page ContentType = "Application / Msword; Charset = GB2312"%>

<% @ Page Import = "java.sql. *"%>

Report> </ Title></p> <p></ HEAD></p> <p><Body bgcolor = "# ffffff"></p> <p><Center> <H1> Report </ h1> </ center></p> <p><Table border = 1 cellspacing = 0 cellpadding = 0 bordercolor = # 000000 align = center></p> <p><Tr></p> <p><TD> User Name </ TD></p> <p><TD> Real Name </ TD></p> <p><TD> Gender </ TD></p> <p></ TR></p> <p><%</p> <p>Java.sql.connection sqlcon; // Database connection object</p> <p>Java.lang.String strcon; // Database connection string</p> <p>Class.Forname ("com.microsoft.jdbc.sqlser.sqlserverdriver);</p> <p>/ / Connect User Database</p> <p>Strcon = "JDBC: Microsoft: SQLSERVER: // localhost: 1433; DatabaseName = Kenoah";</p> <p>//Connect to the database</p> <p>Sqlcon = java.sql.driverManager.getConnection (StrCon, "SA", "SA");</p> <p>STATEMENT STMT = Sqlcon.createStatement ();</p> <p>ResultSet RS = Stmt.executeQuery ("Select * from kenoahuser);</p> <p>// Query the USER table</p> <p>While (rs.next ()) {</p> <p>%></p> <p><Tr></p> <p><TD> <% = rs.getstring ("fullname")%> </ td></p> <p><TD> <% = rs.getstring ("Mobile")%> </ td></p> <p><TD> <% = rs.getstring ("Workemail")%> </ td> </ tr></p> <p><%</p> <p>}</p> <p>%></p> <p><%</p> <p>Rs.close ();</p> <p>Stmt.close ();</p> <p>Sqlcon.close ();</p> <p>%></p> <p></ TABLE></p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-38612.html</div><div class="plugin d-flex justify-content-center mt-3"></div><hr><div class="row"><div class="col-lg-12 text-muted mt-2"><i class="icon-tags mr-2"></i><span class="badge border border-secondary mr-2"><h2 class="h6 mb-0 small"><a class="text-secondary" href="tag-2.html">9cbs</a></h2></span></div></div></div></div><div class="card card-postlist border-white shadow"><div class="card-body"><div class="card-title"><div class="d-flex justify-content-between"><div><b>New Post</b>(<span class="posts">0</span>) </div><div></div></div></div><ul class="postlist list-unstyled"> </ul></div></div><div class="d-none threadlist"><input type="checkbox" name="modtid" value="38612" checked /></div></div></div></div></div><footer class="text-muted small bg-dark py-4 mt-3" id="footer"><div class="container"><div class="row"><div class="col">CopyRight © 2020 All Rights Reserved </div><div class="col text-right">Processed: <b>0.045</b>, SQL: <b>9</b></div></div></div></footer><script src="./lang/en-us/lang.js?2.2.0"></script><script src="view/js/jquery.min.js?2.2.0"></script><script src="view/js/popper.min.js?2.2.0"></script><script src="view/js/bootstrap.min.js?2.2.0"></script><script src="view/js/xiuno.js?2.2.0"></script><script src="view/js/bootstrap-plugin.js?2.2.0"></script><script src="view/js/async.min.js?2.2.0"></script><script src="view/js/form.js?2.2.0"></script><script> var debug = DEBUG = 0; var url_rewrite_on = 1; var url_path = './'; var forumarr = {"1":"Tech"}; var fid = 1; var uid = 0; var gid = 0; xn.options.water_image_url = 'view/img/water-small.png'; </script><script src="view/js/wellcms.js?2.2.0"></script><a class="scroll-to-top rounded" href="javascript:void(0);"><i class="icon-angle-up"></i></a><a class="scroll-to-bottom rounded" href="javascript:void(0);" style="display: inline;"><i class="icon-angle-down"></i></a></body></html><script> var forum_url = 'list-1.html'; var safe_token = 'aR9dxUkP4gja8s1bQQaKQ6cqHUTBH5wsye_2FbmpYfk89FDFkNYp2BV2nXc2cGJhGcEwK8lV1q2IC_2BKr_2FF'; var body = $('body'); body.on('submit', '#form', function() { var jthis = $(this); var jsubmit = jthis.find('#submit'); jthis.reset(); jsubmit.button('loading'); var postdata = jthis.serializeObject(); $.xpost(jthis.attr('action'), postdata, function(code, message) { if(code == 0) { location.reload(); } else { $.alert(message); jsubmit.button('reset'); } }); return false; }); function resize_image() { var jmessagelist = $('div.message'); var first_width = jmessagelist.width(); jmessagelist.each(function() { var jdiv = $(this); var maxwidth = jdiv.attr('isfirst') ? first_width : jdiv.width(); var jmessage_width = Math.min(jdiv.width(), maxwidth); jdiv.find('img, embed, iframe, video').each(function() { var jimg = $(this); var img_width = this.org_width; var img_height = this.org_height; if(!img_width) { var img_width = jimg.attr('width'); var img_height = jimg.attr('height'); this.org_width = img_width; this.org_height = img_height; } if(img_width > jmessage_width) { if(this.tagName == 'IMG') { jimg.width(jmessage_width); jimg.css('height', 'auto'); jimg.css('cursor', 'pointer'); jimg.on('click', function() { }); } else { jimg.width(jmessage_width); var height = (img_height / img_width) * jimg.width(); jimg.height(height); } } }); }); } function resize_table() { $('div.message').each(function() { var jdiv = $(this); jdiv.find('table').addClass('table').wrap('<div class="table-responsive"></div>'); }); } $(function() { resize_image(); resize_table(); $(window).on('resize', resize_image); }); var jmessage = $('#message'); jmessage.on('focus', function() {if(jmessage.t) { clearTimeout(jmessage.t); jmessage.t = null; } jmessage.css('height', '6rem'); }); jmessage.on('blur', function() {jmessage.t = setTimeout(function() { jmessage.css('height', '2.5rem');}, 1000); }); $('#nav li[data-active="fid-1"]').addClass('active'); </script>