Category Archives: Java

iReport

Getting Started

Hi, and welcome to iReport. If you are reading this document, probably you never used iReport before and it might not be clear to you what iReport is or can do.

If you are evaluating iReport, this document should help you to understand the basics concepts about creating reports with iReport and JasperReports. Be sure to check out the Gallery and the Features pages for a bigger overview of the iReport capabilities.

What is iReport?

There are several ways to add reporting capabilities to an application. For many web developers, to create a report just means to create a web page, which produces good results on screen but poor results when printed to paper. And to create a report in PDF means write more code… tons of code, making the reports hard to maintain and long to write.

When working with other technologies the problem does not change very much. For example, Java provides an extensive API for printing, but there is still a lot of work to write specific code for each document format.

The answer to this problem is to use a reporting library. JasperReports is the world’s most popular open source Java reporting library, and iReport is a visual report designer for JasperReports. 

The library is a report engine that can be integrated in your open or commercial application to generate the reports designed with iReport, display them on screen or export them in a final format like PDF, OpenOffice, DOCX and many others. Alternatively, you can stream the result through a web application or send the final document directly to a printer. JasperReports is in some way the core of iReport.

JasperReports

It is extremely easy to integrate in an Java application, but if you need an environment to use the reports without having to write a custom application, you may consider using JasperServer.

JasperServer provides a web based interface to manage, schedule, and run the reports; a repository to store all the report resources like images, fonts, data sources and much more; a security service to decide who can execute which report; and a web services API to execute the reports from external applications (so you can generate reports from any kind of environment, like PHP or .NET).

In the big picture, iReport allows you to design reports, JasperReports allows to execute them and generate output in a Java application, and JasperServer allows both end users and external applications to access, view, and publish your reports securely. JasperServer also makes reports interactive by adding drill down and drill up capabilities to your documents.

Report Life Cycle

Before we start working with iReport, let’s learn about the life cycle of a report. When you design a report using iReport you are creating a JRXML file, which is an XML document that contains the definition of the report layout. The layout is completely designed in a visual way, so you can ignore the real structure of the JRXML file.

Before executing a report, the JRXML must be compiled in a binary object called a Jasper file. This compilation is done for performance reasons. Jasper files are what you need to ship with your application in order to run the reports.

The report execution is performed by passing a Jasper file and a data source to JasperReports. There are plenty of types of data sources, it’s possible to fill a Jasper file from an SQL query, an XML file, a csv file, an HQL(Hibernate Query Language) query, a collection of JavaBeans, etc… If you don’t find a suitable data source, JasperReports is very flexible and allows you to write your own custom data source. With a Jasper file and a data source, JasperReports is able to generate the final document in the format you prefer.

iReport also lets you configure data sources and use them to test your reports. In many cases, data-driven wizards can help you design your reports much quicker. iReport includes the JasperReports engine itself to let you preview your report output, test, and refine your reports.

User Interface

So what does iReport look like? iReport is a powerful environment to design reports. Reports can be designed from scratch or from one of the many ready-to-use templates that are available.

iReport will assist you during all the phases of the report development: JRXML design, Jasper compilation, report execution, and document export or visualization.

Figure 2 shows the main user interface components of iReport.

  • The Report Designer is where you visually design the report by dragging, positioning, aligning and resizing report elements.
  • The Report Inspector shows the complete structure of the report which is composed of many objects (such as fields, parameters and variables), bands (which are sections of the document) and elements (such as textfields, images or charts).
  • The Elements Palette contains the elements that can be dragged inside a band to display your data.
  • The Property Sheet is used to set the properties of the currently selected component in the report (such as a field, element, band, group, or other).

Above the report designer there is the data source selector, which shows the active connection that will be used to execute the report (Figure 3).

The report designer toolbar has three buttons to easily switch from design to preview mode. When you click the preview button, iReport executes the report using the active connection and displays the result using an internal previewer. iReport can also be configured to automatically export the document in a particular format and open the proper viewer (such as a browser or a PDF viewer).

Now you’re ready to see iReport in action by designing a report.

 All the best!!!

Leave a comment

Filed under Java

Introduction To Struts-2

 

                                                                   About Struts-2

  • Struts2 is popular and mature web application framework based on the MVC design pattern.
  • Struts2 is not just the next version of Struts 1, but it is a complete rewrite of the Struts architecture.
  • The WebWork framework started off with Struts framework as the basis and its goal was to offer an enhanced and improved framework built on Struts to make web development easier for the developers.
  • After some time, the Webwork framework and the Struts community joined hands to create the famous Struts2 framework.

Do we need Frame work?

  • We don’t need Frame work. Why?  Because, for normal application development you don’t want to learn new things.
  • We need to work with Frame work. Why? Because, In Real world applications, some Business Application developments have good presentations, give more secure for that application.

Features of Struts-2:

      Some of the features are in struts 2 frame work. Its mainly used to develop the web application as much as easier.

  1. POJO forms and POJO actions – Struts2 has done away with the Action Forms that were an integral part of the Struts framework. With Struts2, you can use any POJO to receive the form input. Similarly, you can now see any POJO as an Action class.
  2. Tag support – Struts2 has improved the form tags and the new tags allow the developers to write less code.
  3. AJAX support – Struts2 has recognized the takeover by Web2.0 technologies, and has integrated AJAX support into the product by creating AJAX tags, that function very similar to the standard Struts2 tags.
  4. Easy Integration – Integration with other frameworks like Spring, Tiles and Site Mesh is now easier with a variety of integration available with Struts2.
  5. Template Support – Support for generating views using templates.
  1. Easy to modify tags – Tag markups in Struts2 can be tweaked using free marker templates. This does not require JSP or java knowledge. Basic HTML, XML and CSS knowledge is enough to modify the tags.
  2. View Technologies: – Struts2 has a great support for multiple view options (JSP, Free marker, Velocity and XSLT)

 

Drawbacks of Struts 2:

Though Struts 2 comes with a list of great features but I would not forget to mention few negative points about Struts 2 and would need lots of improvements:

  1. Bigger learning curve – To use MVC with Struts, you have to be comfortable with the standard JSP, Servlet APIs and a large & elaborate framework.
  2. Poor documentation – Compared to the standard servlet and JSP APIs, Struts has fewer online resources, and many first-time users find the online Apache documentation confusing and poorly organized.
  3. Less transparent – With Struts applications, there is a lot more going on behind the scenes than with normal Java-based Web applications which makes it difficult to understand the framework.

Basic Structure for Struts 2 (MVC Design Pattern):

Basic Structure for Struts 2 (MVC Design Pattern)

Model:

  • The process of the model is to managing data in the database.
  • It responds the request from the view and also responds to instructions from the controller to update itself.

View:

  • The View is also called as presentation Logic.
  • It is used to presenting the data based on the systems like Jsp, servlet, Asp, Php etc.
  • The way of presenting the data in a web browser.

Controller:

  • Controller is a source used for interaction between the Model and View.
  • The controller receives the input; it validates the input and then performs the business operation that modifies the state of the data model.

How Struts Works?

Working principle of StrutsRequest life cycle:

Based on the above diagram, one can explain the user’s request life cycle in Struts 2 as follows:

  1. User sends a request to the server for requesting for some resource.
  2. The FilterDispatcher looks at the request and then determines the appropriate Action.
  3. Configured interceptors functionalities applies such as validation, file upload etc.
  4. Selected action is executed to perform the requested operation.
  5. Again, configured interceptors are applied to do any post-processing if required.
  6. Finally the result is prepared by the view and returns the result to the user.

                                                       Struts 2 Basic Configuration

First put struts jar Files into the Lib Folder.

create web.xml it starts from web.xml file

create struts.xml inside source Folder name as “resources”

Step-1:web.xml

<?xml version=“1.0” encoding=“UTF-8”?>

<web-app id=“WebApp_ID” version=“2.4” xmlns=http://java.sun.com/xml/ns/j2ee&#8221; xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance&#8221; xsi:schemaLocation=http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd&#8221;>

<display-name>strutssample</display-name>

<welcome-file-list>

<welcome-file>ss.jsp</welcome-file>

</welcome-file-list>

<filter>

<filter-name>struts2</filter-name>

<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>

</filter>

<filter-mapping>

<filter-name>struts2</filter-name>

<url-pattern>/*</url-pattern>

</filter-mapping>

</web-app>

Step-2:Form.jsp

<%@ taglib uri=”/struts-tags” prefix=”s” %> ——After include jar file mention this

<s:form action=“login.action” method=“post” validate=“true” >—-It says mention action name then it will go to struts.xml file then it check the action name

<%@ page language=“java” contentType=“text/html; charset=ISO-8859-1”

pageEncoding=“ISO-8859-1”%>

<%@ taglib uri=“/struts-tags” prefix=“s” %>

<!DOCTYPE html PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN” “http://www.w3.org/TR/html4/loose.dtd”&gt;

<html>

<head>

<meta http-equiv=“Content-Type” content=“text/html; charset=ISO-8859-1”>

<title>Registration Form</title>

</head>

<body>

<s:form action=“login.action” method=“post” validate=“true” >

<s:textfield name=“username”  label=“User Name” />

<s:password name=“password”  label=“Password”> </s:password>

<s:submit method=“execute” label=“login”/></b>

</s:form>

</body>

</html>

 

Step-3: struts.xml

<action name=“login” class=“pack.LoginAction”>—-It says check the name “login” from jsp page if it is true means it will go to Action class named as “LoginAction” i gave inside the package named as “pack”.so i mentioned “pack.LoginAction”

<result name=“success” >welcome.jsp </result>—It says after checking action class the code is fine means the action class return success inside execute method.Then it will go to welcome page

 

<?xml version=“1.0” encoding=“UTF-8”?>

<!DOCTYPE struts PUBLIC

“-//Apache Software Foundation//DTD Struts Configuration 2.0//EN”

http://struts.apache.org/dtds/struts-2.0.dtd”&gt;

<struts>

<constant name=“struts.enable.DynamicMethodInvocation” value=“false”></constant>

<constant name=“struts.devMode” value=“true” />

<constant name=“struts.custom.i18n.resources” value=“ApplicationResources” />

<package name=“default” extends=“struts-default”>

<action name=“login”  class=“pack.LoginAction”>

<result name=“success” >welcome.jsp </result>

<result name=“input”>Form.jsp</result>

</action>

</package>

</struts>
Step-4:LoginAction.java

package pack;

import com.opensymphony.xwork2.ActionSupport;

public class LoginAction extends ActionSupport{

private String username;

private String password;

/**

* @return the username

*/

public String getUsername() {

return username;

}

/**

* @param username the username to set

*/

public void setUsername(String username) {

this.username = username;

}

/**

* @return the password

*/

public String getPassword() {

return password;

}

/**

* @param password the password to set

*/

public void setPassword(String password) {

this.password = password;

}

public String execute()

{

if((this.username.equals(“mohan”)) && (this.password.equals(“mohan”)))

{

return SUCCESS;

}

else

{    return INPUT;

}

}

}

Step-5: welcome.jsp

<%@ page language=“java” contentType=“text/html; charset=ISO-8859-1”

pageEncoding=“ISO-8859-1”%>

<%@ taglib uri=“/struts-tags” prefix=“s”  %>

<!DOCTYPE html PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN” “http://www.w3.org/TR/html4/loose.dtd”&gt;

<html>

<head>

<meta http-equiv=“Content-Type” content=“text/html; charset=ISO-8859-1”>

<title>Welcome Page</title>

</head>

<body>

Welcome To Our Struts Program

</body>

</html>

Output:(Screen Shots)

Output1

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

8 Comments

Filed under Java

History Of Java

             In the early 90s, extending the power of network computing to the activities of everyday life was a radical vision. In 1991, a small group of Sun engineers called the “Green Team” believed that the next wave in computing was the union of digital consumer devices and computers. Led by James Gosling, the team worked around the clock and created the programming language that would revolutionize our world – Java.

             The Green Team demonstrated their new language with an interactive, handheld home-entertainment controller that was originally targeted at the digital cable television industry. Unfortunately, the concept was much too advanced for the them at the time. But it was just right for the Internet, which was just starting to take off. In 1995, the team announced that the Netscape Navigator Internet browser would incorporate Java technology.

             Today, Java not only permeates the Internet, but also is the invisible force behind many of the applications and devices that power our day-to-day lives. From mobile phones to handheld devices, games and navigation systems to e-business solutions, Java is everywhere!

How the name JAVA comes?

            Did you tasted a  Coffee in your life?  I am sure you did. yes the name ‘java’  denotes a coffee. Sun Corporation  planned to name their language so they had a Brainstorming  session.they had an idea to name it as ‘oak’ but they cant do that because oak technologies restrict them.so the name should be very simple  and it should not be like the technical terms. at last the session ended with the name JAVA.

What is Java technology and the need?

               Java is a programming language and computing platform first released by Sun Microsystems in 1995. It is the underlying technology that powers state-of-the-art programs including utilities, games, and business applications. Java runs on more than 850 million personal computers worldwide, and on billions of devices worldwide, including mobile and TV devices.

Leave a comment

Filed under Java