Training and development officer required for Avanceon limited

Training and development officer required for Avanceon limited

Job Description :

Avanceon limited is looking for training and development officer. Position is permanent and is Lahore based. 1-2 years experience in HR and bachelor or master degree from reputable university. Competitive salary package with top tier corporates perks and benefits. Complimentary pick n drop facility.

Company Name:

Avanceon limited

Location:

Pakistan

Apply Before:

09th Apr, 2017

Real Facts “Balochistan Oil & Gas Reserves”

Conspiracy theory of Balochistan Oil and Gas Reserves

According to the Oil & Gas Journal, an industry publication, Pakistan’s total proven gas reserves were 31.3 trillion cubic feet as of January 1, 2009. That number sounds like a lot but it means that Pakistan is ranked 25th in the world in terms of gas reserves.

Iran’s reserves are 32 times higher and Russia’s are 54 times greater. Even tiny Qatar has 29 times more gas than Pakistan.

All of those legendary stories about Balochistan having massive gas fields are just that: myths and legends. It turns out that, despite Sui being one of the largest gas fields in the country, most of the country’s gas does not come from Balochistan. In fact, about 71 per cent comes from Sindh.

It is possible that there are large unknown reserves of gas in Balochistan, but policy decisions, especially major ones, should probably not be based on an assumption of the existence of undiscovered resources.

Officials of Pakistan Petroleum Limited (PPL) told the committee that gas production in Sui was falling by 5% every passing year and the reserves would wear out by 2022. Remaining reserves are estimated to be at 2 trillion cubic feet

as

Table.2            Province-wise Annual Gas Production: 2006-7

Province

Non-Associated Gas (MMCF)

Associated Gas (MMCF)

Total (MMCF)

Percentage

SindhPunjab

NWFP

Balochistan

979,198

52,481

22,818

318,188

21,217

16,127

3,552

0

1,000,415

68,608

26,370

318,188

70.77

4.58

1.86

22.50

Pakistan

1372,685

40,896

1413,581

100%

Source: Pakistan Energy Yearbook 2007

 

 

 

Province

Non-Associated Gas (MMCF)

Associated Gas (MMCF)

Total (MMCF)

Percentage

Sindh

Punjab

NWFP

Balochistan

979,198

52,481

22,818

318,188

21,217

16,127

3,552

0

1,000,415

68,608

26,370

318,188

70.77

4.58

1.86

22.50

Pakistan

1372,685

40,896

1413,581

100%

Source: Pakistan Energy Yearbook 2007

Normal
0

false
false
false

EN-US
X-NONE
AR-SA

st1:*{behavior:url(#ieooui) }

/* Style Definitions */
table.MsoNormalTable
{mso-style-name:”Table Normal”;
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-parent:””;
mso-padding-alt:0in 5.4pt 0in 5.4pt;
mso-para-margin-top:0in;
mso-para-margin-right:0in;
mso-para-margin-bottom:10.0pt;
mso-para-margin-left:0in;
line-height:115%;
mso-pagination:widow-orphan;
font-size:11.0pt;
font-family:”Calibri”,”sans-serif”;
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;
mso-bidi-font-family:Arial;
mso-bidi-theme-font:minor-bidi;}

Enhanced by Zemanta

Step by Step Guide to configure Router with PTCL modem

Shiro Broadband Router

Step to Configure TP-Link Router
——————————————

1.Power on Router.
2.Connect your PC/laptop with Router via ethernet cable. [Use Routers LAN ports only not WAN]
3.Your PC automatically gets IP address as default DHCP is enabled on Router.
You get IP from 192.168.1.x or 192.168.0.x (x: 2-254)
Router default IP varies from model to model either 192.168.1.1 or 192.168.0.1(written on router box)
4.Open browser and enter router default IP address http://192.168.1.1 according to your router.
5.Router authentication required. By default username/password is admin/admin.
6.TP-Link console opens.
7.Click on Network > LAN, change IP address to 192.168.1.2. Its due to your Modem
default IP address is 192.168.1.1.
8. Its reboots automatically.
9. Now open TP-Link console with new IP address which is 192.168.1.2
10.Click on Wireless Settings, Change default SSID with your choice like “Johnny”
11.Change other setting as per requirment like country. Rest leave by default.
12.Click on Wireless Security for making your wireless network secure.
13.Use WPA-PSK (Wireless security protocol)
14.Select your desired Encription like AES or TKIP.
15.Enter PSK password.
16. Select DHCP link.
17. Disable it. (As your Modems DHCP is already on)
18. Click system Tools > Reboot.
19. Your Router is ready to use, now just plug the ethernet with modem.

Note:
The guide is written because the novice user always in confusion, how to configure router.
Almost all vendors Wireless Router can be configureable with this guide with some minor change.
The Guide is made while the configuration of TP-Link WR-642G.
The Basic concept is to change the Router IP address & disable Routers DHCP service.

Swift Codes for all the Banks of Pakistan. You can find it here!

PakistanBelow are the SWIFT codes for all banks in Pakistan. These SWIFT codes are only the active participants who are connected to SWIFT network. The passive participant’s codes are excluded from the list.

Browse Pages :
Page 1 | Page 2 | Page 3 | Page 4 | Page 5 | Page 6 | Page 7

No Bank or Institution City Branch Name Swift Code
1 ALBARAKA ISLAMIC BANK B.S.C. (E.C.) KARACHI AIINPKKAXXX
2 ALBARAKA ISLAMIC BANK B.S.C. (E.C.) LAHORE AIINPKKALHR
3 ALLIED BANK LIMITED FAISALABAD (FAISALABAD CITY) ABPAPKKAFSD
4 ALLIED BANK LIMITED FAISALABAD (SITARA TOWER BRANCH) ABPAPKKA237
5 ALLIED BANK LIMITED ISLAMABAD (BLUE AREA BRANCH, CORPORATE BRANCH, ISLAMABAD – 0443) ABPAPKKA443
6 ALLIED BANK LIMITED ISLAMABAD (ISLAMABAD CITY) ABPAPKKAISL
7 ALLIED BANK LIMITED KARACHI (199-UPPER MALL, LAHORE (0979)) ABPAPKKA979
8 ALLIED BANK LIMITED KARACHI (BATH ISLAND) ABPAPKKATKC
9 ALLIED BANK LIMITED KARACHI (BRANCH KARACHI (0949)) ABPAPKKA949
10 ALLIED BANK LIMITED KARACHI (EXPORT PROCESSING ZONE BRANCH, (OFF SHORE BANKING UNIT)) ABPAPKKAEPZ
11 ALLIED BANK LIMITED KARACHI (GUJRANWALA CITY) ABPAPKKAGUJ
12 ALLIED BANK LIMITED KARACHI (PESHAWAR CITY) ABPAPKKAPSH
13 ALLIED BANK LIMITED KARACHI (RAWALPINDI CITY) ABPAPKKARWP
14 ALLIED BANK LIMITED KARACHI (TRADE FACTORY WING, TRADE TOWER, CENTRAL OFFICE, KARACHI.) ABPAPKKATFW
15 ALLIED BANK LIMITED KARACHI (TREASURY OPERATIONS (TROPS), OPERATIONS GROUP, CENTRAL OFFICE) ABPAPKKATRY
16 ALLIED BANK LIMITED KARACHI ABPAPKKAXXX
17 ALLIED BANK LIMITED LAHORE (7-E/III, CORPORATE CENTRE, BRANCH LAHORE (0361)) ABPAPKKA361
18 ALLIED BANK LIMITED LAHORE (LAHORE CITY) ABPAPKKALHR
19 ALLIED BANK LIMITED MULTAN (CHEN ONE TOWER 74 ABDALI ROAD BRANCH) ABPAPKKA393
20 ALLIED BANK LIMITED MULTAN (MULTAN CITY) ABPAPKKAMUL
21 ALLIED BANK LIMITED SIALKOT (SIALKOT CITY) ABPAPKKASKT
22 ARIF HABIB BANK LIMITED KARACHI AHRBPKKAXXX
23 ASKARI BANK LIMITED RAWALPINDI (AWT PLAZA, RAWALPINDI BRANCH) ASCMPKKA001
24 ASKARIBANK LIMITED FAISALABAD (UNIVERSITY ROAD BRANCH) ASCMPKKA009
25 ASKARIBANK LIMITED GUJRANWALA (GUJRANWALA BRANCH) ASCMPKKA012
26 ASKARIBANK LIMITED GUJRAT (GUJRAT BRANCH) ASCMPKKA037
27 ASKARIBANK LIMITED ISLAMABAD (ISLAMIC BKG BR, BLUE AREA ) ASCMPKKA905
28 ASKARIBANK LIMITED KARACHI (CENTRAL FOREIGN TRADE UNIT) ASCMPKKAFT1
29 ASKARIBANK LIMITED KARACHI (ISLAMIC BKG BR, JODIA BAZAR) ASCMPKKA904
30 ASKARIBANK LIMITED KARACHI (ISLAMIC TREASURY DESK, KHI) ASCMPKKAIBT
31 ASKARIBANK LIMITED KARACHI (SAIMA TRADE TOWER BRANCH) ASCMPKKA002
32 ASKARIBANK LIMITED KARACHI (TREASURY DIVISION) ASCMPKKATRY
33 ASKARIBANK LIMITED KARACHI ASCMPKKAXXX
34 ASKARIBANK LIMITED LAHORE (CENTRAL FOREIGN TRADE UNIT) ASCMPKKAFT2
35 ASKARIBANK LIMITED LAHORE (ISLAMIC BKG BR, WALTON CANTT) ASCMPKKA906
36 ASKARIBANK LIMITED LAHORE (SAT BRANCH) ASCMPKKA006
37 ASKARIBANK LIMITED MULTAN (MULTAN BRANCH) ASCMPKKA013
38 ASKARIBANK LIMITED PESHAWAR (CANTONMENT BRANCH) ASCMPKKA004
39 ASKARIBANK LIMITED PESHAWAR (IBB, PESHAWAR) ASCMPKKA902
40 ASKARIBANK LIMITED QUETTA (CANTONMENT BRANCH) ASCMPKKA003
41 ASKARIBANK LIMITED QUETTA (ISLAMIC BKG BR,JINNAH RD) ASCMPKKA903
42 ASKARIBANK LIMITED RAWALPINDI (CENTRAL FOREIGN TRADE UNIT) ASCMPKKAFT3
43 ASKARIBANK LIMITED RAWALPINDI (HEAD OFFICE, RAWALPINDI ) ASCMPKKAHOR
44 ASKARIBANK LIMITED RAWALPINDI (IBB, RAWALPINDI) ASCMPKKA901
45 ASKARIBANK LIMITED RAWALPINDI (INTERNATIONAL DIVISION) ASCMPKKAIND
46 ASKARIBANK LIMITED SIALKOT (SIALKOT BRANCH) ASCMPKKA010
47 ATLAS BANK LIMITED KARACHI (FOREX AND TREASURY DEPARTMENT) DBHDPKKATRY
48 ATLAS BANK LIMITED KARACHI (TRADE PROCESSING CENTER (SOUTH)) DBHDPKKAKHI
49 ATLAS BANK LIMITED KARACHI DBHDPKKAXXX
50 ATLAS BANK LIMITED LAHORE (TRADE PROCESSING CENTRE (NORTH)) DBHDPKKALHE
51 BANK AL HABIB LIMITED FAISALABAD (FAISALABAD BRANCH) BAHLPKKAFSD
52 BANK AL HABIB LIMITED ISLAMABAD (ISLAMABAD BRANCH) BAHLPKKAISL
53 BANK AL HABIB LIMITED KARACHI (CENTRAL PROCESSING UNIT) BAHLPKKACPU
54 BANK AL HABIB LIMITED KARACHI (EXPORT PROCESSING ZONE BRANCH) BAHLPKKAEPZ
55 BANK AL HABIB LIMITED KARACHI (ISLAMIC BANKING DIVISION) BAHLPKKAIBD
56 BANK AL HABIB LIMITED KARACHI (JODIA BAZAR) BAHLPKKAJBZ
57 BANK AL HABIB LIMITED KARACHI (KARACHI MAIN BRANCH) BAHLPKKAKHI
58 BANK AL HABIB LIMITED KARACHI (L C CENTRE) BAHLPKKALCC
59 BANK AL HABIB LIMITED KARACHI BAHLPKKAXXX
60 BANK AL HABIB LIMITED LAHORE (LAHORE BRANCH) BAHLPKKALHR
61 BANK AL HABIB LIMITED MULTAN (MULTAN MAIN BRANCH) BAHLPKKAMUL
62 BANK ALFALAH LIMITED ABBOTTABAD (ABBOTTABAD BRANCH) ALFHPKKA068
63 BANK ALFALAH LIMITED ABBOTTABAD (IBD ABBOTABAD) ALFHPKKA547
64 BANK ALFALAH LIMITED AHMADPUR EAST (AHMEDPUR EAST BRANCH) ALFHPKKA122
65 BANK ALFALAH LIMITED ARIFWALA (ARIFWALA BRANCH) ALFHPKKA115
66 BANK ALFALAH LIMITED ATTOCK (ATTOCK BRANCH) ALFHPKKA120
67 BANK ALFALAH LIMITED ATTOCK (HAZRO) ALFHPKKA141
68 BANK ALFALAH LIMITED ATTOCK (KAMRA) ALFHPKKA191
69 BANK ALFALAH LIMITED ATTOCK (LAKKAR MANDI GHORGHUSHTI BRANCH) ALFHPKKA231
70 BANK ALFALAH LIMITED BAHAWALNAGAR (BAHAWALNAGAR) ALFHPKKA164
71 BANK ALFALAH LIMITED BAHAWALPUR (BAHAWALPUR BRANCH) ALFHPKKA085
72 BANK ALFALAH LIMITED BALUCHISTAN (CHAMAN BRANCH) ALFHPKKA121
73 BANK ALFALAH LIMITED BALUCHISTAN (CUTPIECE BRANCH) ALFHPKKA097
74 BANK ALFALAH LIMITED BANNU (BANNU) ALFHPKKA154
75 BANK ALFALAH LIMITED BATTAGRAM (BATTAGRAM BRANCH) ALFHPKKA230
76 BANK ALFALAH LIMITED BHAKKAR (BHAKKAR BRANCH) ALFHPKKA202
77 BANK ALFALAH LIMITED BHALWAL (BHALWAL BRANCH) ALFHPKKA105
78 BANK ALFALAH LIMITED BUREWALA (BUREWALA BRANCH) ALFHPKKA055
79 BANK ALFALAH LIMITED CHAKWAL (CHAKWAL BRANCH) ALFHPKKA129
80 BANK ALFALAH LIMITED CHAKWAL (IBD DHUDIAL DISTT CHAKWAL) ALFHPKKA548
81 BANK ALFALAH LIMITED CHICHAWATNI (CHICHAWATNI BRANCH) ALFHPKKA116
82 BANK ALFALAH LIMITED CHINIOT (CHINIOT BRANCH) ALFHPKKA111
83 BANK ALFALAH LIMITED CHITRAL (CHITRAL) ALFHPKKA142
84 BANK ALFALAH LIMITED CHUCHUNG (CHUHNG BR IBD) ALFHPKKA536
85 BANK ALFALAH LIMITED DASKA (DASKA BRANCH) ALFHPKKA112
86 BANK ALFALAH LIMITED DEPALPUR (DEPALPUR) ALFHPKKA192
87 BANK ALFALAH LIMITED DERA GHAZI KHAN (DERA GHAZI KHAN BRANCH) ALFHPKKA075
88 BANK ALFALAH LIMITED DERA ISMAIL KHAN (D.I. KHAN BRANCH) ALFHPKKA057
89 BANK ALFALAH LIMITED DERA ISMAIL KHAN (IBD DERA ISMAIL KHAN) ALFHPKKA532
90 BANK ALFALAH LIMITED DHARKI (DHARKI BRANCH) ALFHPKKA123
91 BANK ALFALAH LIMITED DINA (DINA) ALFHPKKA190
92 BANK ALFALAH LIMITED FAISALABAD (BABAR CHOWK FAISALABAD) ALFHPKKA187
93 BANK ALFALAH LIMITED FAISALABAD (FAISALABAD BRANCH) ALFHPKKAFSD
94 BANK ALFALAH LIMITED FAISALABAD (GOJRA) ALFHPKKA160
95 BANK ALFALAH LIMITED FAISALABAD (IBD CANAL RD FAISALABAD) ALFHPKKA544
96 BANK ALFALAH LIMITED FAISALABAD (IBD MEDICAL COLLEGE ROAD BRANCH) ALFHPKKA511
97 BANK ALFALAH LIMITED FAISALABAD (IBD SATYANA ROAD FAISALABAD) ALFHPKKA533
98 BANK ALFALAH LIMITED FAISALABAD (ISLAMIC BANKING, KUTCHERY BAZAR BRANCH) ALFHPKKA503
99 BANK ALFALAH LIMITED FAISALABAD (JARANWALA) ALFHPKKA159
100 BANK ALFALAH LIMITED FAISALABAD (KHURRIAN WALA BRANCH) ALFHPKKA209


Browse Pages :
Page 1 | Page 2 | Page 3 | Page 4 | Page 5 | Page 6 | Page 7

 

Spring MVC + FreeMarker (FTL) Integration example

 

Today we will create a Spring MVC based application that uses Freemarker FTL as view instead of JSP. This would give you a good insight in Spring MVC + Freemarker integration. The application is similar to previous tutorial’s User app, where a list of users will be displayed and also we can add new user.

The application is very simple:

  1. There is a table that displays user info like firstname, lastname.
  2. New user can be added via Add User form.

Below is the wireframe of our final freemarker based spring mvc 3 app.
freemarker-servlet-wireframe

So lets get started.

Things We Need

Before we starts with our Spring MVC 3 + FreeMarker example, we will need few tools.

  1. JDK 1.6 or above (download)
  2. Tomcat 6.x or above or any other container (Glassfish, JBoss, Websphere, Weblogic etc) (download)
  3. Eclipse 3.4.x or above (download)
  4. Spring MVC 3.1.2 or above (download)
  5. Freemarker JAR v2.3.15 or above(download)

Let us start with our Spring MVC based Freemarker application.

Step 1: Getting Started

Open Eclipse and goto File -> New -> Project and select Dynamic Web Project in the New Project wizard screen.

dynamic web project in eclipse

After selecting Dynamic Web Project, press Next.

eclipse dynamic web project

Write the name of the project. For example Freemarker_SpringMVC_example. Once this is done, select the target runtime environment (e.g. Apache Tomcat v6.0). This is to run the project inside Eclipse environment. After this press Finish.

Once the project is created, you can see its structure in Project Explorer. This is how the project structure would look like when we finish the tutorial and add all source code.

springmvc-freemarker-ftl-project-structure

Till this step, our basic Eclipse web project is ready. We will now add Spring MVC and Freemarker support to this project.

Step 2: Adding Spring MVC Support

First copy all required Spring MVC and supporting JAR files in WebContent > WEB-INF > lib folder. Create this folder if it does not exists. Don’t worry if you do not have these JARs. You can download the complete source code with JAR files at the end of this tutorial.

Next we change web.xml (deployment descriptor) and add Spring MVC support to it. If you do not know why we do this, I strongly recommends you to go through Spring 3 MVC Tutorial series.

Related: Spring 3 MVC hello world example

Update the web.xml with following code:

File: /WebContent/WEB-INF/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_3_0.xsd"
        id="WebApp_ID" version="3.0">
        
  <display-name>Freemarker_SpringMVC_example</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
  <servlet>
        <servlet-name>spring</servlet-name>
        <servlet-class>
            org.springframework.web.servlet.DispatcherServlet
        </servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>spring</servlet-name>
        <url-pattern>*.html</url-pattern>
    </servlet-mapping>
</web-app>

The above code in web.xml will map DispatcherServlet with url pattern *.html. One thing to note here is the name of servlet in <servlet-name> tag in web.xml. Once the DispatcherServlet is initialized, it will look for a file name [servlet-name]-servlet.xml in WEB-INF folder of web application. In this example, the framework will look for file called spring-servlet.xml.

Create a new file spring-servlet.xml under /WebContent/WEB-INF/ folder. This is the spring configuration. Copy following code into it.
File: /WebContent/WEB-INF/spring-servlet.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:p="http://www.springframework.org/schema/p"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd                http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
    <!-- freemarker config -->
    <bean id="freemarkerConfig" class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
      <property name="templateLoaderPath" value="/WEB-INF/ftl/"/>
    </bean>
    
    <!--
      View resolvers can also be configured with ResourceBundles or XML files. If you need
      different view resolving based on Locale, you have to use the resource bundle resolver.
    -->
    <bean id="viewResolver" class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">
      <property name="cache" value="true"/>
      <property name="prefix" value=""/>
      <property name="suffix" value=".ftl"/>
    </bean>
    <context:component-scan
        base-package="net.viralpatel" />
         
</beans>

In the above xml configuration file, we have defined a tag <context:component-scan>. This will allow Spring to load all the components from package net.viralpatel and all its child packages. This will load our UserController class. Also we have defined a bean viewResolver. We uses org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver as view resolver. Also notice how we defined bean freemarkerConfig. This defines Freemarker configuration, in our case just one property templateLoaderPath; the path where we will store all our .ftl template files.

Thus the bean viewResolver will resolve the freemarker template view. Note that in our UserController class, we have return a view name “index”. This will be resolved to path /WEB-INF/ftl/index.ftl by FreeMarkerViewResolver.

Step 3: Create Spring MVC Controller

File: /src/net/viralpatel/UserController.java

package net.viralpatel;
import java.util.ArrayList;
import java.util.List;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
public class UserController {
    /**
     * Static list of users to simulate Database
     */
    private static List<User> userList = new ArrayList<User>();
    //Initialize the list with some data for index screen
    static {
        userList.add(new User("Bill", "Gates"));
        userList.add(new User("Steve", "Jobs"));
        userList.add(new User("Larry", "Page"));
        userList.add(new User("Sergey", "Brin"));
        userList.add(new User("Larry", "Ellison"));
    }
    /**
     * Saves the static list of users in model and renders it
     * via freemarker template.
     *
     * @param model
     * @return The index view (FTL)
     */
    @RequestMapping(value = "/index", method = RequestMethod.GET)
    public String index(@ModelAttribute("model") ModelMap model) {
        model.addAttribute("userList", userList);
        return "index";
    }
    /**
     * Add a new user into static user lists and display the
     * same into FTL via redirect
     *
     * @param user
     * @return Redirect to /index page to display user list
     */
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public String add(@ModelAttribute("user") User user) {
        if (null != user && null != user.getFirstname()
                && null != user.getLastname() && !user.getFirstname().isEmpty()
                && !user.getLastname().isEmpty()) {
            synchronized (userList) {
                userList.add(user);
            }
        }
        return "redirect:index.html";
    }
}

The UserController is a simple Spring 3 MVC controller that handles request/response. We have created a private static List userList which stores the user entries. Note that in ideal example you would like to read data from database. But for sake of simplicity we will stick to static List :)

There are two methods index() and add(), both mapped via @RequestMapping annotation. The index() method will simply store the users list in model object and render “index” view (index.ftl). And the add() method gets the user details from html form and add it inside static List. Once the add() has added user, it simply redirects the request to /index.html which will render the user list.

Apart from the above UserController class, we will also need a bean class User which holds the user information like firstname, lastname etc.

File: /src/net/viralpatel/User.java

package net.viralpatel;
public class User {
    private String firstname;
    private String lastname;
    public User() {
    }
    public User(String firstname, String lastname) {
        this.firstname = firstname;
        this.lastname = lastname;
    }
    //Add Getter and Setter methods
}

Now add Freemarker view in your project.

Step 4: Create Freemarker Template Files

Create a new file index.ftl under folder /WebContent/WEB-INF/ftl/. Copy following content into it.

File: /WebContent/WEB-INF/ftl/index.ftl

<html>
<head><title>ViralPatel.net - FreeMarker Spring MVC Hello World</title>
<body>
<div id="header">
<H2>
    <a href="http://viralpatel.net"><img height="37" width="236" border="0px" src="http://viralpatel.net/blogs/wp-content/themes/vp/images/logo.png" align="left"/></a>
    FreeMarker Spring MVC Hello World
</H2>
</div>
<div id="content">
    
  <fieldset>
    <legend>Add User</legend>
  <form name="user" action="add.html" method="post">
    Firstname: <input type="text" name="firstname" /> <br/>
    Lastname: <input type="text" name="lastname" />   <br/>
    <input type="submit" value="   Save   " />
  </form>
  </fieldset>
  <br/>
  <table class="datatable">
    <tr>
        <th>Firstname</th>  <th>Lastname</th>
    </tr>
    <#list model["userList"] as user>
    <tr>
        <td>${user.firstname}</td> <td>${user.lastname}</td>
    </tr>
    </#list>
  </table>
</div
</body>
</html

This is a simple FTL template file. We just iterate model[“userList”] list in a loop and prints user’s firstname and lastname in table.

That’s All Folks

You may want to run the application see the result. I assume you have already configured Tomcat in eclipse. All you need to do:
Open Server view from Windows > Show View > Server. Right click in this view and select New > Server and add your server details.

To run the project, right click on Project name from Project Explorer and select Run as > Run on Server (Shortcut: Alt+Shift+X, R)

URL: http://localhost:8080/Freemarker_SpringMVC_example/index.html
freemarker-springmvc-ftl-example

Download Source Code

Freemarker_SpringMVC_example.zip (4.4 MB)

Reference : viralpatel.net

 

In The Line of Fire [Kala Bagh Exclusive] Dawn News 12th Jan 2012

In The Line of Fire [Kala Bagh Exclusive] Dawn News 12th Jan 2012