Friday, 20 March 2015

Struts2 File Upload


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package com.lkr.actions;

import java.io.File;
import java.util.ArrayList;

import javax.xml.parsers.ParserConfigurationException;

import org.apache.commons.io.FilenameUtils;
import org.xml.sax.SAXException;

import com.opensymphony.xwork2.ActionSupport;

public class UploadAction extends ActionSupport{

 
 
 private File upload;
 private String uploadContentType;
 private String uploadFileName;
 private int questionCount;
 
 
 
 public int getQuestionCount() {
  return questionCount;
 }
 public void setQuestionCount(int questionCount) {
  this.questionCount = questionCount;
 }
 public UploadAction(){
  
 }

 
 
 public String execute() {
  
  if (getUploadFileName() != null) {

   // filePath = servletRequest.getRealPath("/");
   String fileNameWithOutExt = FilenameUtils
     .removeExtension(this.uploadFileName);
   System.out.println("file to create..........." + fileNameWithOutExt);
   }
 
  return SUCCESS;
 
 }
 
 /**
  * @return the upload
  */
 public File getUpload() {
  return upload;
 }
 /**
  * @param upload the upload to set
  */
 public void setUpload(File upload) {
  this.upload = upload;
 }
 /**
  * @return the uploadContentType
  */
 public String getUploadContentType() {
  return uploadContentType;
 }
 /**
  * @param uploadContentType the uploadContentType to set
  */
 public void setUploadContentType(String uploadContentType) {
  this.uploadContentType = uploadContentType;
 }
 /**
  * @return the uploadFileName
  */
 public String getUploadFileName() {
  return uploadFileName;
 }
 /**
  * @param uploadFileName the uploadFileName to set
  */
 public void setUploadFileName(String uploadFileName) {
  this.uploadFileName = uploadFileName;
 }
 
 
 
 

}
upload.jsp


in the upload.jsp the form method should be post and enctype="multipart/form-data"


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<%@ taglib prefix="s" uri="/struts-tags"%>
<html>
<head>
<style>
input[type="radio"] {
 margin-top: -1px;
 vertical-align: middle;
}
</style>
</head>

<body>
 <h1>Struts 2 radio button example</h1>

 <s:form action="resultAction" namespace="/" enctype="multipart/form-data" theme="simple" method="POST">

  <h4>
   <s:file name="upload" id="upload1">
   </s:file>
   
  </h4>

  <s:submit value="submit" name="submit" />

 </s:form>

</body>
</html>


struts.xml exam/result.jsp

Friday, 5 December 2014

Hibernate Pojo Annotations

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
package com.petrol.to;

// Generated Mar 8, 2014 3:29:01 AM by Hibernate Tools 3.4.0.CR1

import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import static javax.persistence.GenerationType.IDENTITY;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 * Bills generated by hbm2java
 */
@Entity
@Table(name = "bills", catalog = "pt")
public class Bills implements java.io.Serializable {

 private Integer id;
 private Customers customers;
 private int billNo;
 private Integer vehicleId;
 private Date billDate;
 private int type;
 private Date createdAt;
 private Date updatedAt;
 private Set<BillItems> billItemses = new HashSet<BillItems>(0);

 public Bills() {
 }

 public Bills(int billNo, int type) {
  this.billNo = billNo;
  this.type = type;
 }

 public Bills(Customers customers, int billNo, Integer vehicleId,
   Date billDate, int type, Date createdAt, Date updatedAt,
   Set<BillItems> billItemses) {
  this.customers = customers;
  this.billNo = billNo;
  this.vehicleId = vehicleId;
  this.billDate = billDate;
  this.type = type;
  this.createdAt = createdAt;
  this.updatedAt = updatedAt;
  this.billItemses = billItemses;
 }

 @Id
 @GeneratedValue(strategy = IDENTITY)
 @Column(name = "id", unique = true, nullable = false)
 public Integer getId() {
  return this.id;
 }

 public void setId(Integer id) {
  this.id = id;
 }

 @ManyToOne(fetch = FetchType.EAGER)
 @JoinColumn(name = "customer_id")
 public Customers getCustomers() {
  return this.customers;
 }

 public void setCustomers(Customers customers) {
  this.customers = customers;
 }

 @Column(name = "bill_no", nullable = false)
 public int getBillNo() {
  return this.billNo;
 }

 public void setBillNo(int billNo) {
  this.billNo = billNo;
 }

 @Column(name = "vehicle_id")
 public Integer getVehicleId() {
  return this.vehicleId;
 }

 public void setVehicleId(Integer vehicleId) {
  this.vehicleId = vehicleId;
 }

 @Temporal(TemporalType.DATE)
 @Column(name = "bill_date", length = 10)
 public Date getBillDate() {
  return this.billDate;
 }

 public void setBillDate(Date billDate) {
  this.billDate = billDate;
 }

 @Column(name = "type", nullable = false)
 public int getType() {
  return this.type;
 }

 public void setType(int type) {
  this.type = type;
 }

 @Temporal(TemporalType.TIMESTAMP)
 @Column(name = "created_at", length = 19)
 public Date getCreatedAt() {
  return this.createdAt;
 }

 public void setCreatedAt(Date createdAt) {
  this.createdAt = createdAt;
 }

 @Temporal(TemporalType.TIMESTAMP)
 @Column(name = "updated_at", length = 19)
 public Date getUpdatedAt() {
  return this.updatedAt;
 }

 public void setUpdatedAt(Date updatedAt) {
  this.updatedAt = updatedAt;
 }

 @OneToMany(fetch = FetchType.EAGER, mappedBy = "bills")
 public Set<BillItems> getBillItemses() {
  return this.billItemses;
 }

 public void setBillItemses(Set<BillItems> billItemses) {
  this.billItemses = billItemses;
 }

}


hibernate.cfg.xml
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>
        <property name="hibernate.bytecode.use_reflection_optimizer">false</property>
        <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/pt</property>
        <property name="hibernate.connection.username">root</property>
        <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
        <property name="hibernate.search.autoregister_listeners">false</property>
        <mapping class="com.petrol.to.Customers" />
        <mapping class="com.petrol.to.Invoices" />
        <mapping class="com.petrol.to.Authorizations" />
        <mapping class="com.petrol.to.Sessions" />
        <mapping class="com.petrol.to.PetrolUser" />
        <mapping class="com.petrol.to.Stocks" />
        <mapping class="com.petrol.to.Actions" />
        <mapping class="com.petrol.to.SchemaMigrations" />
        <mapping class="com.petrol.to.Vehicles" />
        <mapping class="com.petrol.to.UserType" />
        <mapping class="com.petrol.to.Items" />
        <mapping class="com.petrol.to.BillItems" />
        <mapping class="com.petrol.to.Bills" />
        <mapping class="com.petrol.to.Recipts" />
    </session-factory>
</hibernate-configuration>


main.java
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package com.petrol.admin.action;

import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;

import com.petrol.dao.AuthorizationsHome;
import com.petrol.to.Authorizations;

/**
 * Handle authorization operation.
 * 
 * @author Asman.
 */
public class AuthorizationsLoader {

 /**
  * Getting authorizations.
  * 
  * @return authorizations
  */
 public List<Authorizations> loadAuthorizations() {
  List<Authorizations> authorizations = null;
  Session session = null;
  try {
   SessionFactory sessionFactory = new AnnotationConfiguration()
     .configure("/hibernate.cfg.xml").buildSessionFactory();
   session = sessionFactory.openSession();
   AuthorizationsHome authoDao = new AuthorizationsHome();
   authorizations = authoDao.getAllAuthorizations(session);
   session.close();

  } catch (HibernateException he) {
   // he.printStackTrace();
  }
  return authorizations;
 }

 public static void main(String s[]) {

 }
}

Struts2 Restful webservices


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
<?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">

<struts>

  <constant name="struts.devMode" value="true" />
  <constant name="struts.convention.action.suffix" value="Controller"/>
  <constant name="struts.convention.action.mapAllMatches" value="true"/>
  <constant name="struts.convention.default.parent.package" value="rest-default"/>
  <constant name="struts.convention.package.locators" value="example"/>

  <constant name="struts.convention.default.parent.package" value="rest-default"/>  

</struts>

OrdersController.java


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package org.lkr.struts2.rest.example;

import java.util.Collection;

import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.apache.struts2.rest.DefaultHttpHeaders;
import org.apache.struts2.rest.HttpHeaders;
import org.lkr.struts2.rest.service.OrdersService;
import org.lkr.struts2.rest.to.Order;

import com.opensymphony.xwork2.ModelDriven;

@Results({ @Result(name = "success", type = "redirectAction", params = {
  "actionName", "orders" }) })
public class OrdersController implements ModelDriven<Object> {

 /**
  * 
  */
 private static final long serialVersionUID = 3241256322152936000L;
 private Order model = new Order();
 private String id;
 private Collection<Order> list;
 private OrdersService ordersService = new OrdersService();

 // GET /orders/1
 public HttpHeaders show() {
  return new DefaultHttpHeaders("show");
 }

 // GET /orders
 public HttpHeaders index() {
  list = ordersService.getAll();
  return new DefaultHttpHeaders("index").disableCaching();
 }

 // GET /orders/1/edit
 public String edit() {
  return "edit";
 }

 // GET /orders/new
 public String editNew() {
  model = new Order();
  return "editNew";
 }

 // GET /orders/1/deleteConfirm
 public String deleteConfirm() {
  return "deleteConfirm";
 }

 // DELETE /orders/1
 public String destroy() {
  ordersService.remove(id);
  //addActionMessage("Order removed successfully");
  return "success";
 }

 // POST /orders
 public HttpHeaders create() {
  ordersService.save(model);
  //addActionMessage("New order created successfully");
  return new DefaultHttpHeaders("success").setLocationId(model.getId());
 }

 // PUT /orders/1
 public String update() {
  ordersService.save(model);
  //addActionMessage("Order updated successfully");
  return "success";
 }

 public void validate() {
  if (model.getClientName() == null
    || model.getClientName().length() == 0) {
   //addFieldError("clientName", "The client name is empty");
  }
 }

 public void setId(String id) {
  if (id != null) {
   this.model = ordersService.get(id);
  }
  this.id = id;
 }

 public Object getModel() {
  return (list != null ? list : model);
 }

}


orders-index.jsp
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<%@taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
 <title>Orders</title>
</head>
<body>
    <s:actionmessage />
    <table>
        <tr>
            <th>ID</th>
            <th>Client</th>
            <th>Amount</th>
            <th>Actions</th>
        </tr>
        <s:iterator value="model">
        <tr>
            <td>${id}</td>
            <td>${clientName}</td>
            <td>${amount}</td>
            <td><a href="orders/${id}">View</a> |
                <a href="orders/${id}/edit">Edit</a> |
                <a href="orders/${id}/deleteConfirm">Delete</a></td>
        </tr>
        </s:iterator>
    </table>     
    <a href="orders/new">Create a new order</a>
</body>
</html>


web.xml
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
 http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
 <filter>
  <filter-name>struts2</filter-name>
  <filter-class>
   org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
  </filter-class>
 </filter>
 <filter-mapping>
  <filter-name>struts2</filter-name>
  <url-pattern>/*</url-pattern>
 </filter-mapping>
 <welcome-file-list>
  <!-- <welcome-file>index.jsp</welcome-file> -->
  <welcome-file>index.jsp</welcome-file>
 </welcome-file-list>
</web-app>

Tuesday, 25 November 2014

Spring & Struts2 and Hibernate Integration

Application Context.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>

<!-- ...............DATASOURCE CONFIGURATION BEGIN.............. -->
<bean id="ieDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="com.mysql.jdbc.Driver" />
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/pt" />
<!--<property name="user" value="${jdbc.username}"/> <property name="password"
value="${jdbc.password}"/> -->
<property name="properties">
<props>
<prop key="c3p0.acquire_increment">10</prop>
<prop key="c3p0.idle_test_period">100</prop>
<prop key="c3p0.max_size">500</prop>
<prop key="c3p0.max_statements">0</prop>
<prop key="c3p0.min_size">10</prop>
<prop key="c3p0.timeout">120</prop>
<prop key="user">root</prop>
<prop key="password"></prop>
</props>
</property>
</bean>

<!-- .........................DATASOURCE CONFIGURATION END.................. -->

<!-- .......................HIBERNATE CONFIGURATION BEGIN................. -->
<bean id="ieSessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<!-- <bean id="ieSessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"> -->
<property name="dataSource" ref="ieDataSource" />
<property name="annotatedClasses">

<list>
<value>com.petrol.to.BillItems</value>
<value>com.petrol.to.Items</value>
<value>com.petrol.to.Bills</value>
<value>com.petrol.to.Customers</value>
<value>com.petrol.to.Recipts</value>
<value>com.petrol.to.SchemaMigrations</value>
<value>com.petrol.to.Sessions</value>
<value>com.petrol.to.Stocks</value>
<value>com.petrol.to.Vehicles</value>
<value>com.petrol.to.PetrolUser</value>
<value>com.petrol.to.UserType</value>
<value>com.petrol.to.Invoices</value>
<value>com.petrol.to.Actions</value>
<value>com.petrol.to.Authorizations</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect"> org.hibernate.dialect.MySQLDialect</prop>
<!-- <prop key="hibernate.show_sql">true</prop> -->
</props>
</property>

</bean>
<!-- ............. HIBERNATE CONFIGURATION END................ -->

<!-- .................. ACTION *** BEGIN....................... -->

<!-- ..................ADMIN MODULE *** BEGIN ........... -->

<bean id="loginAction" class="com.petrol.admin.action.LoginAction"
singleton="false">
   <property name="petrolUserService" ref="petrolUserService"></property>
</bean>

<bean id="userRegisterAction" class="com.petrol.admin.action.PetrolUserRegisterAction"
singleton="false">
<property name="petrolUserService" ref="petrolUserService"></property>
</bean>

<!-- ..................ADMIN MODULE *** END ........... -->

<!-- ..................LOGIN MODULE - BEGIN .......... -->

<!-- ..................LOGIN MODULE - END .......... -->

<!-- .................CUSTOMER MODULE - BEGIN ........-->

<bean id="getAllCustomersAction" class="com.petrol.admin.action.GetAllCustomersAction"
singleton="false">
<property name="getAllCustomersService" ref="getAllCustomersService"></property>
</bean>

<bean id="viewCustomerAction" class="com.petrol.admin.action.ViewCustomerAction"
singleton="false">
<property name="getAllCustomersService" ref="getAllCustomersService"></property>
</bean>

<bean id="registerAction" class="com.petrol.admin.action.UserRegisterAction"
singleton="false">
<property name="petrolUserService" ref="petrolUserService"></property>
</bean>

<!-- .................CUSTOMER MODULE - END ........-->

<!-- .................CUSTOMER TRANSACTION MODULE - BEGIN ..................-->

<bean id="billItemsAction" class="com.petrol.admin.action.BillItemsAction"
singleton="false">
<property name="petrolBillItemsService" ref="petrolBillItemsService"></property>
<property name="petrolItemsService" ref="petrolItemsService"></property>
<property name="petrolBillsService" ref="petrolBillsService"></property>
</bean>

<bean id="pdfAction" class="com.petrol.commons.GeneratingPdfAction"
singleton="false">
<property name="petrolBillItemsService" ref="petrolBillItemsService"></property>
<property name="getAllInvoicesService" ref="getAllInvoicesService"></property>
<property name="petrolStocksService" ref="petrolStocksService"></property>
</bean>


<!-- .................CUSTOMER TRANSACTION MODULE - END ..................-->

<!--.................PRODUCTS MODULE BEGIN .......................................-->

<bean id="getItemsAction" class="com.petrol.admin.action.GetItemsAction"
singleton="false">
<property name="petrolItemsService" ref="petrolItemsService"></property>
</bean>

<bean id="itemsAction" class="com.petrol.admin.action.ItemsAction"
singleton="false">
<property name="petrolItemsService" ref="petrolItemsService"></property>
</bean>

<bean id="stocksAction" class="com.petrol.admin.action.StocksAction"
singleton="false">
<property name="petrolStocksService" ref="petrolStocksService"></property>
</bean>

<bean id="getAllStocksAction" class="com.petrol.admin.action.GetAllStocksAction"
singleton="false">
<property name="getAllStocksService" ref="getAllStocksService"></property>
</bean>

<bean id="viewStockAction" class="com.petrol.admin.action.ViewStockAction"
singleton="false">
<property name="getAllStocksService" ref="getAllStocksService"></property>
</bean>

<!--.................PRODUCTS MODULE END .......................................-->

<!-- ................PRODUCTS TRANSACTION MODULE BEGIN........................ -->
<bean id="itemsPriceAction" class="com.petrol.admin.action.ItemsPriceAction"
singleton="false">
<property name="petrolItemsService" ref="petrolItemsService"></property>
</bean>


<!-- ................PRODUCTS TRANSACTION MODULE END........................ -->

<!-- ................BILL MODULE BEGIN ..............................................................-->

<bean id="billsAction" class="com.petrol.admin.action.BillsAction"
singleton="false">
<property name="petrolBillsService" ref="petrolBillsService"></property>
</bean>

<bean id="getCustomersAction" class="com.petrol.admin.action.GetCustomersAction"
singleton="false">
<property name="petrolBillsService" ref="petrolBillsService"></property>
</bean>

<bean id="getBillNumberAction" class="com.petrol.admin.action.GetBillNumberAction"
singleton="false">
<property name="petrolBillsService" ref="petrolBillsService"></property>
</bean>

<bean id="getBillItemsAction" class="com.petrol.admin.action.GetBillItemsAction"
singleton="false">
<property name="getBillItemsService" ref="getBillItemsService"></property>
</bean>

<bean id="priceAction" class="com.petrol.admin.action.PriceAction"
singleton="false">
<property name="petrolItemsService" ref="petrolItemsService"></property>
</bean>

<bean id="productSubmitAction" class="com.petrol.admin.action.ProductSubmitAction"
singleton="false">
<property name="productSubmitService" ref="productSubmitService"></property>
</bean>

<!-- ................BILL MODULE END ..............................................................-->

<!--  ...............INVOICE MODULE BEGIN ...................................................-->

<bean id="invoiceAction" class="com.petrol.admin.action.InvoiceAction"
singleton="false">
<property name="getAllInvoicesService" ref="getAllInvoicesService"></property>
</bean>

<!--  ...............INVOICE MODULE END ...................................................-->

<!-- ................ INVOICE TRANSACTION MODULE BEGIN ...................-->

<!-- ................ INVOICE TRANSACTION MODULE END ...................-->

<!-- ................... LOGOUT MODULE BEGIN .........................................-->

<!-- ................... LOGOUT MODULE END .........................................-->

<!-- <bean id="userManagementAction" class="com.petrol.admin.action.UserManagementAction"
singleton="false">
<property name="petrolService" ref="petrolService"></property>
</bean> -->



<!-- <bean id="mapTestAction" class="com.petrol.admin.action.MapTestAction"
singleton="false">
</bean> -->

<!-- <bean id="jasperReportAction" class="com.petrol.admin.action.JasperReportAction"
singleton="false">
</bean> -->

<!-- <bean id="productsAction" class="com.petrol.admin.action.ProductsAction"
singleton="false">
</bean> -->

<!-- <bean id="gridDataAction" class="com.petrol.admin.action.GridDataProvider"
singleton="false">
</bean> -->

<!-- <bean id="productDataProviderAction" class="com.petrol.admin.action.ProductsDataProvider"
singleton="false"></bean> -->

<!-- ................... ACTION *** END............................... -->

<!-- SERVICE *** BEGIN -->
<bean id="petrolUserService" class="com.petrol.service.PetrolUserService"
singleton="false">
<property name="sessionFactory" ref="ieSessionFactory"></property>
<property name="customersDao" ref="customersDao"></property>
<property name="userTypeDao" ref="userTypeDao"></property>
<property name="userDao" ref="userDao"></property>
</bean>

<bean id="getAllCustomersService" class="com.petrol.service.GetAllCustomersService"
singleton="false">
<property name="sessionFactory" ref="ieSessionFactory"></property>
<property name="customersDao" ref="customersDao"></property>
</bean>

<bean id="petrolBillItemsService" class="com.petrol.service.PetrolBillItemsService"
singleton="false">
<property name="sessionFactory" ref="ieSessionFactory"></property>
<property name="billItemsDao" ref="billItemsDao"></property>
</bean>

<bean id="petrolItemsService" class="com.petrol.service.PetrolItemsService"
singleton="false">
<property name="sessionFactory" ref="ieSessionFactory"></property>
<property name="itemsDao" ref="itemsDao"></property>
</bean>

<bean id="petrolBillsService" class="com.petrol.service.PetrolBillsService"
singleton="false">
<property name="sessionFactory" ref="ieSessionFactory"></property>
<property name="billsDao" ref="billsDao"></property>
<property name="billItemsDao" ref="billItemsDao"></property>
<property name="stocksDao" ref="stocksDao"></property>
<property name="itemsDao" ref="itemsDao"></property>
<property name="customersDao" ref="customersDao"></property>
</bean>

<bean id="getAllInvoicesService" class="com.petrol.service.GetAllInvoicesService"
singleton="false">
<property name="sessionFactory" ref="ieSessionFactory"></property>
<property name="invoicesDao" ref="invoicesDao"></property>
</bean>

<bean id="petrolStocksService" class="com.petrol.service.PetrolStocksService"
singleton="false">
<property name="sessionFactory" ref="ieSessionFactory"></property>
<property name="stocksDao" ref="stocksDao"></property>
<property name="itemsDao" ref="itemsDao"></property>
</bean>

<bean id="getAllStocksService" class="com.petrol.service.GetAllStocksService"
singleton="false">
<property name="sessionFactory" ref="ieSessionFactory"></property>
<property name="stocksDao" ref="stocksDao"></property>
<property name="itemsDao" ref="itemsDao"></property>
</bean>

<bean id="productSubmitService" class="com.petrol.service.ProductSubmitService"
singleton="false">
</bean>

<bean id="getBillItemsService" class="com.petrol.service.GetBillItemsService"
singleton="false">
<property name="sessionFactory" ref="ieSessionFactory"></property>
<property name="billItemsDao" ref="billItemsDao"></property>
</bean>

<!-- hehehheh -->

<!-- <bean id="petrolService" class="com.petrol.service.PetrolService"
singleton="false">
<property name="sessionFactory" ref="ieSessionFactory"></property>
<property name="billItemsDao" ref="billItemsDao"></property>
</bean> -->

<!-- SERVICE *** END -->

<!-- ...........DAO *** BEGIN................................ -->
<bean id="billItemsDao" class="com.petrol.dao.BillItemsDao" />
<bean id="itemsDao" class="com.petrol.dao.ItemsDao" />
<bean id="customersDao" class="com.petrol.dao.CustomersDao"></bean>
<bean id="billsDao" class="com.petrol.dao.BillsDao"></bean>
<bean id="stocksDao" class="com.petrol.dao.StocksDao"></bean>
<bean id="invoicesDao" class="com.petrol.dao.InvoicesDao"></bean>
<bean id="userTypeDao" class="com.petrol.dao.UserTypeDao"></bean>
<bean id="userDao" class="com.petrol.dao.UserDao"></bean>

<!-- ..... DAO *** END...... -->
</beans>
*********************************************************************
********************************************************************
web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>Idea Exchange</display-name>

<context-param>
<param-name>
org.apache.tiles.impl.BasicTilesContainer.DEFINITIONS_CONFIG</param-name>
<param-value>/WEB-INF/petrolProjectTiles-defs.xml</param-value>
</context-param>

<filter>
<filter-name>pp</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>org.apache.struts2.tiles.StrutsTilesListener</listener-class>
</listener>
<filter-mapping>
<filter-name>pp</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<servlet>
<servlet-name>Captcha</servlet-name>

<servlet-class>com.petrol.commons.PetrolCaptcha</servlet-class>
<init-param>
<description>passing height</description>
<param-name>height</param-name>
<param-value>30</param-value>
</init-param>
<init-param>
<description>passing height</description>
<param-name>width</param-name>
<param-value>120</param-value>
</init-param>
</servlet>

<servlet-mapping>
<servlet-name>Captcha</servlet-name>
<url-pattern>/Captcha.jpeg</url-pattern>
</servlet-mapping>

<session-config>
<session-timeout>30</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
**************************************************************
*************************************************************
tiles.xml

<?xml version="1.0" encoding="UTF-8" ?>

<!DOCTYPE tiles-definitions PUBLIC
       "-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN"
       "http://tiles.apache.org/dtds/tiles-config_2_0.dtd">
<tiles-definitions>

<definition name="baseLayout" template="/baseLayout.jsp">
<put-attribute name="header" value="/petrolheader.jsp" />
<put-attribute name="logout" value="/logoutmenu.jsp" />
<put-attribute name="menu" value="/petrolmenu.jsp"/>
<put-attribute name="body" value="/body.jsp" />
<put-attribute name="footer" value="/petrolfooter.jsp" />
</definition>

<definition name="home" extends="baseLayout">
<put-attribute name="body" value="/Welcome.jsp" />
</definition>
<definition name="register" extends="baseLayout">
<put-attribute name="body" value="/register.jsp" />
<put-attribute name="menu" value="/body.jsp" />
</definition>
<definition name="bills" extends="baseLayout">
<put-attribute name="body" value="/bills.jsp" />
</definition>

<definition name="stocks" extends="baseLayout">
<put-attribute name="body" value="/stocks.jsp" />
</definition>

<definition name="items" extends="baseLayout">
<put-attribute name="body" value="/items.jsp" />
</definition>
<definition name="viewsales" extends="baseLayout">
<put-attribute name="body" value="/viewbillitems.jsp" />
</definition>
<definition name="success" extends="baseLayout">
<put-attribute name="body" value="/success.jsp" />
</definition>
<definition name="failure" extends="baseLayout">
<put-attribute name="body" value="/failure.jsp" />
</definition>
<definition name="login" extends="baseLayout">
<put-attribute name="body" value="/login.jsp" />
</definition>
<definition name="billItems" extends="baseLayout">
<put-attribute name="body" value="/billitems.jsp" />
</definition>
<definition name="customers" extends="baseLayout">
<put-attribute name="body" value="/customers.jsp" />
</definition>
<definition name="viewcustomer" extends="baseLayout">
<put-attribute name="body" value="/viewcustomer.jsp" />
</definition>
<definition name="precustomer" extends="baseLayout">
<put-attribute name="body" value="/createcustomer.jsp" />
</definition>
<definition name="precustomertransactions" extends="baseLayout">
<put-attribute name="body" value="/customertransactions.jsp" />
</definition>
<definition name="getBillItems" extends="baseLayout">
<put-attribute name="body" value="/viewbillitems.jsp" />
</definition>
<definition name="prebillcreation" extends="baseLayout">
<put-attribute name="body" value="/Copy of billitems.jsp" />
</definition>
<definition name="getallstocks" extends="baseLayout">
<put-attribute name="body" value="/stocks.jsp" />
</definition>
<definition name="addstocks" extends="baseLayout">
<put-attribute name="body" value="/addstocks.jsp" />
</definition>
<definition name="editstock" extends="baseLayout">
<put-attribute name="body" value="/addstocks.jsp" />
</definition>
<definition name="viewstock" extends="baseLayout">
<put-attribute name="body" value="/viewstock.jsp" />
</definition>
<definition name="createinvoice" extends="baseLayout">
<put-attribute name="body" value="/createinvoice.jsp" />
</definition>
<definition name="preinvoicetransaction" extends="baseLayout">
<put-attribute name="body" value="/invoicetransactions.jsp" />
</definition>
<definition name="viewinvoices" extends="baseLayout">
<put-attribute name="body" value="/viewiteminvoices.jsp" />
</definition>
<definition name="prestocktransaction" extends="baseLayout">
<put-attribute name="body" value="/stocktransactions.jsp" />
</definition>
<definition name="viewstocktransactions" extends="baseLayout">
<put-attribute name="body" value="/viewstocktransactions.jsp" />
</definition>
<definition name="getallitems" extends="baseLayout">
<put-attribute name="body" value="/allitems.jsp" />
</definition>
<definition name="preregister" template="/baseLayout.jsp">
   <put-attribute name="header" value="/petrolheader.jsp" />
   <put-attribute name="body" value="/userregister.jsp"/>
   <put-attribute name="menu" value="/body.jsp"/>
   <put-attribute name="logout" value="/body.jsp"/>
   <put-attribute name="footer" value="/petrolfooter.jsp" />
</definition>
</tiles-definitions>


*****************************************************
*****************************************************
struts.xml

<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>
<constant name="struts.devMode" value="true" />
<constant name="struts.convention.action.packages" value="com.jgeppert.struts2.jquery.showcase"/>
<package name="default " namespace="/"
extends="struts-default,json-default">
<result-types>
<result-type name="tiles"
class="org.apache.struts2.views.tiles.TilesResult" />
<result-type name="jasper" class="org.apache.struts2.views.jasperreports.JasperReportsResult"/>
</result-types>
<interceptors>
    <interceptor name="loginInterceptor"
    class="com.petrol.admin.action.PetrolLoginInterceptor">
   </interceptor>

   <interceptor-stack name="petrolInterceptorsStack">
    <interceptor-ref name="alias" />
    <interceptor-ref name="params" />
    <interceptor-ref name="servletConfig" />
    <interceptor-ref name="exception" />
    <interceptor-ref name="prepare" />
    <interceptor-ref name="i18n" />
    <interceptor-ref name="chain" />
    <interceptor-ref name="modelDriven" />
    <interceptor-ref name="fileUpload" />
    <interceptor-ref name="checkbox" />
    <interceptor-ref name="staticParams" />
    <interceptor-ref name="params" />
    <interceptor-ref name="conversionError" />
    <interceptor-ref name="validation">
     <param name="excludeMethods">input,back,cancel</param>
    </interceptor-ref>
    <!-- <interceptor-ref name="workflow">  
     <param name="excludeMethods">input,back,cancel,browse</param>  
     </interceptor-ref> -->
    <interceptor-ref name="loginInterceptor" />
   </interceptor-stack>
  </interceptors>
  <default-interceptor-ref name="petrolInterceptorsStack"></default-interceptor-ref>
           <global-results>
   <result name="redirecthome" type="redirect">index.jsp</result>
    </global-results>

<!-- ADMIN MODULE - BEGIN -->
<action name="preRegister" method="prepareRegister" class="loginAction">
<result name="success" type="tiles">preregister</result>
<result name="input">/login.jsp</result>
</action>
<action name="userregister" class="userRegisterAction" method="registerUser">
<result name="input" type="tiles">home</result>
<result name="buyer" type="redirectAction">
<param name="actionName">getAllCustomers.action</param>
</result>
<result name="error" type="tiles">preregister</result>
<result name="owner" type="redirectAction">
<param name="actionName">getAllCustomers.action</param>
</result>
</action>
<!-- ADMIN MODULE - END -->
<!-- LOGIN MODULE - BEGIN -->
<action name="login" method="login" class="loginAction">
   <result type="redirectAction" name="owner">
<param name="actionName">getAllCustomers.action</param>
</result>
<result name="buyer" type="redirectAction">
<param name="actionName">getAllCustomers.action</param>
</result>
<result name="changepassword" type="tiles">changepassword</result>
<result name="input" type="tiles">home</result>
<result name="error" type="tiles">login</result>
</action>
<!-- LOGIN MODULE - END -->
<!--  CUSTOMER MODULE - BEGIN -->
<action name="getAllCustomers" method="getAllCustomers" class="getAllCustomersAction">
   <result name="success" type="tiles">customers</result>
</action>
<action name="preCreateCustomer" method="preCreateCusomer" class="viewCustomerAction">
   <result name="success" type="tiles">precustomer</result>
</action>
<action name="register" method="register" class="registerAction">
<result name="success" type="redirectAction">
<param name="actionName">
getAllCustomers.action
</param>
</result>
<result name="input" type="tiles">failure</result>
</action>
<action name="viewCustomer" method="viewCustomer" class="viewCustomerAction">
   <result name="success" type="tiles">viewcustomer</result>
</action>
<action name="editCustomer" method="viewCustomer" class="viewCustomerAction">
   <result name="success" type="tiles">precustomer</result>
</action>
<action name="deleteCustomer" method="deleteCustomer" class="viewCustomerAction">
   <result name="success" type="redirectAction">
<param name="actionName">
getAllCustomers.action
</param>
</result>
</action>
<action name="updateCustomer" method="updateCustomer" class="registerAction">
   <result name="success" type="redirectAction">
<param name="actionName">
getAllCustomers.action
</param>
</result>
</action>
<!-- CUSTOMER MODULE - END -->
<!--  CUSTOMER TRANSACTION MODULE - BEGIN -->
<action name="preCustomerTransactions" method="preCustomerTransactions" class="viewCustomerAction">
   <result name="success" type="tiles">precustomertransactions</result>
</action>
<action name="customerBillSearch" method="getBillByCustomer"
class="billItemsAction">
<result name="success" type="tiles">viewsales</result>
</action>
<action name="pdfAction" method="generateCustomerPdf" class="pdfAction">
<result name="test-stream" type="stream">
<param name="inputName">fileStream</param>
<param name="contentType">application/pdf</param>
<param name="contentDisposition">filename="test.pdf"</param>
</result>
</action>
<!--  CUSTOMER TRANSACTION MODULE - END -->
<!-- PRODUCTS MODULE BEGIN -->
<action name="getAllItems" method="allItems" class="getItemsAction">
   <result name="success" type="tiles">getallitems</result>
</action>
<action name="prepareItems" method="prepareItems" class="itemsAction">
<result name="success" type="tiles">items</result>
<result name="input" type="tiles">failure</result>
</action>
<action name="items" method="items" class="itemsAction">
<result name="success" type="redirectAction">
<param name="actionName">
getAllItems.action
</param>
</result>
<result name="input" type="tiles">items</result>
<result name="error" type="tiles">items</result>
</action>
<action name="prepareStocks" method="prepareStocks" class="stocksAction">
<result name="success" type="tiles">addstocks</result>
<result name="input" type="tiles">failure</result>
</action>
<action name="generateStocks" method="generateStocks" class="stocksAction">
   <result name="success" type="redirectAction">
<param name="actionName">
getAllStocks
</param>
</result>
<result name="input" type="tiles">failure</result>
</action>
<action name="getAllStocks" method="getAllStocks" class="getAllStocksAction">
   <result name="success" type="tiles">getallstocks</result>
</action>
<action name="viewItemStock" method="viewItemStock" class="viewStockAction">
   <result name="success" type="tiles">viewstock</result>
</action>
<action name="editItemStock" method="viewItemStock" class="viewStockAction">
   <result name="success" type="tiles">items</result>
</action>
<action name="updateItem" method="updateItem" class="itemsAction">
   <result name="success" type="redirectAction">
<param name="actionName">
getAllItems.action
</param>
</result>
</action>
<action name="deleteItemStock" method="deleteItemStock" class="viewStockAction">
   <result name="success" type="redirectAction">
<param name="actionName">
getAllItems.action
</param>
</result>
</action>
<action name="viewStock" method="viewStock" class="viewStockAction">
   <result name="success" type="tiles">viewstock</result>
</action>
<!-- PRODUCTS MODULE END -->
<!-- PRODUCTS TRANSACTION MODULE BEGIN -->
<action name="preStockTransaction" method="preStockTransaction" class="stocksAction">
<result name="success" type="tiles">prestocktransaction</result>
<result name="input" type="tiles">failure</result>
</action>
<action name="getItems" method="getAllItems" class="itemsPriceAction">
<result name="success" type="json">
<param name="excludeProperties">.*application,validate </param>
</result>
</action>
<action name="itemStockSearch" method="getStockByItem" class="stocksAction">
<result name="success" type="tiles">viewstocktransactions</result>
</action>
<action name="stockspdfAction" method="generateStocksPdf" class="pdfAction">
<result name="test-stream" type="stream">
<param name="inputName">fileStream</param>
<param name="contentType">application/pdf</param>
<param name="contentDisposition">filename="test.pdf"</param>
</result>
</action>
<!-- PRODUCTS TRANSACTION MODULE END -->
<!-- BILL MODULE BEGIN -->
<action name="preBillCreation" method="preBillCreation" class="billsAction">
   <result name="success" type="tiles">prebillcreation</result>
</action>
<action name="getCustomers" method="getCustomers" class="getCustomersAction">
    <result name="success" type="json">
<param name="excludeProperties">.*application,validate </param>
</result>
</action>
<action name="getBillNumber" method="getBillNumber" class="getBillNumberAction">
    <result name="success" type="json">
<param name="excludeProperties">.*application,validate </param>
</result>
</action>
<action name="generateBill" method="generateBill" class="billsAction">
   <result name="success" type="redirectAction">
<param name="actionName">
getBillItems
</param>
</result>
<result name="input" type="tiles">failure</result>
<result name="error" type="tiles">prebillcreation</result>
</action>
<action name="getBillItems" method="getBillItemsByDate" class="getBillItemsAction">
   <result name="success" type="tiles">getBillItems</result>
</action>
<action name="getItemsAction" method="allItems" class="getItemsAction">
   <result name="success" type="json">
<param name="excludeProperties">.*application,validate </param>
</result>
</action>
<action name="priceAction" method="priceByItem" class="priceAction">
<result name="success" type="json">
<param name="excludeProperties">.*application,validate </param>
</result>
</action>
<action name="productsubmit" method="productSubmit" class="productSubmitAction">
   <result name="success" type="json">
<param name="excludeProperties">.*application,validate </param>
</result>
</action>
<action name="productdelete" method="productDelete" class="productSubmitAction">
   <result name="success" type="json">
<param name="excludeProperties">.*application,validate </param>
</result>
</action>
<!-- BILL MODULE END -->
<!--  INVOICE MODULE BEGIN -->
<action name="preCreateInvoice" method="preCreateInvoice" class="invoiceAction">
   <result name="success" type="tiles">createinvoice</result>
</action>
<action name="invoiceregister" method="invoiceRegister" class="invoiceAction">
<result name="success" type="redirectAction">
<param name="actionName">
getAllCustomers.action
</param>
</result>
<result name="input" type="tiles">failure</result>
</action>
<!--  INVOICE MODULE END -->
<!--  INVOICE TRANSACTION MODULE BEGIN -->
<action name="preInvoiceTransaction" method="preInvoiceTransaction" class="invoiceAction">
<result name="success" type="tiles">preinvoicetransaction</result>
<result name="input" type="tiles">failure</result>
</action>
<action name="itemInvoiceSearch" method="getInvoicesByItem"
class="invoiceAction">
<result name="success" type="tiles">viewinvoices</result>
</action>
<action name="invoicepdfAction" method="generateInvoicePdf" class="pdfAction">
<result name="test-stream" type="stream">
<param name="inputName">fileStream</param>
<param name="contentType">application/pdf</param>
<param name="contentDisposition">filename="test.pdf"</param>
</result>
</action>
<!--  INVOICE TRANSACTION MODULE END -->
<!-- LOGOUT MODULE BEGIN -->
<action name="logout" method="logOut" class="loginAction">
<result name="success">/index.jsp</result>
</action>
<!-- LOGOUT MODULE END -->
<!-- TESTING MODULE BEGIN -->
        
<!-- TESTING MODULE END -->
</package>
</struts>