Monday, December 23, 2013

How to Integrate Struts2.x in web application

Perform following steps to integrate Struts2.x.


1) Download struts2.3 from struts.www.apache.org/download.cgi‎ website. You will be getting couple of jars, however you no need to take all jars in your application.


2) Copy following jars in WEB-INF\lib folder


   1. struts2-core-2.3.15.3.jar
   2. xwork-core-2.3.15.3.jar
   3. ognl-3.0.6.jar
   4. javassist-3.11.0.GA.jar
   5. commons-lang3-3.1.jar
   6. commons-io-2.0.1.jar
   7. core-0.6.2.jar
   8. Xecers.jar
   9. xalan.jar

 3) Configure FilterDispatcher in the web.xml file to intercept each and every http request and response


<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>

4) Place Struts.xml file in WEB-INF\classes file and configure action in xml file.

<?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" />
   <package name="Test" extends="struts-default">
    
      <action name="testAction" class="com.test.TestAction" method="execute">
     <result name="success">/test/Test.jsp</result>
     </action>

   </package>
   <-- more packages can be listed here -->

</struts>

5) Write TestAction class file which will invoke execute method.

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ActionContext

public class TestAction extends ActionSupport {
    private String name;
    public String execute() throws Exception {
            System.out.println("TestAction" + name);
                        return SUCCESS;
        }
    public String getName(){
       return name;
    }
    public void setName(){
      this.name = name;
    }
}

 6) Write Test.jsp file and use value stack to take values from response
<%@page import="com.opensymphony.xwork2.util.ValueStack"%>
<%@page import="com.opensymphony.xwork2.ActionContext"%>
<%@page import="com.opensymphony.xwork2.ognl.OgnlValueStack"%>
<%
    ValueStack stack = ActionContext.getContext().getValueStack();
    String name = (String) stack.findValue("name");
    System.out.println("Name :"+name);
%>
<html>
    <body>
        <form method="post" action ="TestAction.action">
            <--- Write any HTML code which suites you
            use ognl for using tag or use struts inbuild tags.
            or use free form html tags. Its up to developer-->
        </form>
    </body>
</html>

7) After Prepare war file and deploy in the server.


Issues which you can see -

1) Sometimes Jar files conflict happens and that is too because of either classpath or server used.
2) IF you see xml parser issue then check your lib folder its quite possible that you are using xml jar file which is conflicting with server parsing jar file.in that case write servletcontextlistener and load you jar file during server startup.

Wednesday, March 6, 2013

Dhoni as Test Captain.......

There is a lot talk about Dhoni as a Test cricket captain.Victory in the Hyderabad Test has made MS Dhoni the most Successful captain in Indian cricket, with 22 Test wins. But one thing comes in my  mind that  Is he really the best Test Captain India ever had ? For me, He is successful in terms of victories but he is not Best Test captain. When we talk about Number's then definitely  Dhoni has given a result but when we talk about best as captain then we need to be subjective and need to look each and every aspects like. 
  1.  How many win came in overseas. 
  2. What kind of team composition captain is having.
  3. Team is playing against which opponent
  4. Is captain leading from the front when team is down.
  5. Captain grooming players who can steal the show independently.
There will be more aspect but I just listed few. Is Dhoni satisfied all the conditions? Lets go by statistics now and we will try to get the answers and  will analyze how well Dhoni done in Test cricket as captain. I will compare him with Ganguly because I personally believe he was better captain than anyone else in India.


Played Won Lost Draw Win (%)
Total 45          22 12 11 48.88
In India 24 17 3 4 70.83
Overseas 21 5 10 6 23



Our of his 22 wins, only three (one each in NZ, SA and WI) have come outside the subcontinent.
Now will have a look against whom we got victory overseas under his captaincy. Dhoni: 5 (New Zealand, Bangladesh, Sri Lanka, South Africa, West Indies) . He has been appointed as captain in 2008 and we all know, other than South Africa and SriLanka, no side was having quality players like India. Now see the Dravid's as captain -  Dravid: 5 Oveseas win (Bangladesh, Pakistan, South Africa, West Indies, England)
Moreover, we recently won 2 matches against the Australia, I am afraid whole Australian squad's test careers run is less than Sachin tendulkar's test runs ? Moreover if we combine the matches played by Australian squad and compare with Sachin's match, you will probably get what I want to say.
The poundings in the away series in England and Australia put him under the scanner.


When Dhoni took over from Kumble India team was winning, it just Kumble taken retirement, so he got the well set team in the plate. They said that Indian team is in transition phase with several greats fading away.But let me tell you all big losses came when all senior were there in the team ( Sachin, Sehwag, Dravid and laxman), this can not be a point to discuss.One who become a great when he handles all these situations and respond strongly.

There are couple of good thing happened under Dhoni's captaincy and we can not deny it.
MS Dhoni  is the only Indian captain who won all his first four Tests as captain.
MS Dhoni  is the only Indian captain who did not lose a Test in his first eleven Tests as captain(11 out of 13 played in India).
MS Dhoni  is the only Indian captain who did not lose a series in his first 12 Test series as captain ( same as above).
MS Dhoni  has recorded a victory on Indian soil against every team that has visited India. India did not play Bangladesh and Pakistan on home soil during his leadership.(Achievement)
MS Dhoni is most successful Wicket Keeper/Batsman Test Captain.
MS Dhoni is cool and calm in the ground but it doesn't always suggest that he is taking correct decision under ext ream pressure.


Let see some other captains record, we will start with Ganguly because he is the only competitor  :)
Played Won    Lost         Draw Win (%)
Total 49         21        13 15 42.87
In India 21         10        3 8 47.61
Overseas 28         11        10 7 39.28

Ganguly has recorded a victory on Indian soil against every team that has visited India except New Zealand. India did not play Bangladesh and Sri Lanka on home soil during his leadership.

Ganguly is also the only Indian captain and the third in history to have led his team to victory after being enforced to follow on - against Steve Waugh's Australia in 2001-02.

Ganguly took over when India had been rocked by match-fixing and needed a strong leader to unite the team. He gave the team the belief that they should never back down from anyone and did so by leading from the front. And he would go to any lengths to back his team. That’s why it is no surprise that Kolkata 2001, India's finest moment, came with Ganguly at the helm. He would just never allow the team to give up. And he won Tests in England and Australia too.

Summary : I am neither against Dhoni nor  supporting Ganguly. My only point is, when we talk about greatness or ability of a captain/person then we need to see all aspects rather just looking the results. Results obviously goes in favor of MS Dhoni but if you see all the angles probably you will agree with me that he needs to do a lot work to proove himself as  Best Test captain of India.