g l a r i m y training on struts 2 · g l a r i m y training on struts 2 krishna mohan koyya,...

25
G l a r i m y Training on Struts 2 Krishna Mohan Koyya, M.Tech, DBM, PMP Technology Consultant & Corporate Trainer [email protected] | www.glarimy.com 091-9731 4231 66 © 2009, Glarimy. All rights reserved. http://www.glarimy.com G l a r i m y

Upload: others

Post on 04-Aug-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: G l a r i m y Training on Struts 2 · G l a r i m y Training on Struts 2 Krishna Mohan Koyya, M.Tech, DBM, PMP Technology Consultant & Corporate Trainer krishna@glarimy.com |

G l a r i m y Training on

Struts 2Krishna Mohan Koyya, M.Tech, DBM, PMP

Technology Consultant & Corporate [email protected] | www.glarimy.com

091-9731 4231 66

© 2009, Glarimy. All rights reserved. http://www.glarimy.com

G l a r i m y

Page 2: G l a r i m y Training on Struts 2 · G l a r i m y Training on Struts 2 Krishna Mohan Koyya, M.Tech, DBM, PMP Technology Consultant & Corporate Trainer krishna@glarimy.com |

© 2009, Glarimy. All rights reserved.

G l a r i m y

Agenda• Session 1

– Breaking the Ice with Introduction– PreTest– MVC Framework– DI & AOP

• Session 2– Struts Architectural Goals– Struts Architecture– Hello World

• Session 3– Actions– Interceptors

• Session 4– Validation Framework– Internationalization

Stru

ts2 F

ram

ewor

k

Page 3: G l a r i m y Training on Struts 2 · G l a r i m y Training on Struts 2 Krishna Mohan Koyya, M.Tech, DBM, PMP Technology Consultant & Corporate Trainer krishna@glarimy.com |

• Call me Krishna– Originally from Tadepalligudem in

Andhra Pradesh– Have been in Bengaluru for the last

10 years• Held various positions in the IT

Industry– Worked on development of huge

systems • Extensive work in the areas of

– Object Orientation– Distributed Systems– Network Management Systems– Java Technologies

Krishna Mohan Koyya

© 2009, Glarimy. All rights reserved.

G l a r i m y

Page 4: G l a r i m y Training on Struts 2 · G l a r i m y Training on Struts 2 Krishna Mohan Koyya, M.Tech, DBM, PMP Technology Consultant & Corporate Trainer krishna@glarimy.com |

• Graduation– B.E. in Electronics & Communication Engineering

• SRKR Engineering College, Bhimavaram, affiliated to Andhra University, Visakhapatnam

• 1989-1993• Post Graduation

– M.Tech in Computer Science & Technology• College of Engineering, Andhra University, Visakhapatnam• 1995-1997

• Certifications– PMP (Project Management Professional)

• PMI® USA• 2005

• Others– Diploma in Business Management (Finance)

• ICFAI, Hyderabad• 2007

Academics

© 2009, Glarimy. All rights reserved.

G l a r i m y

Page 5: G l a r i m y Training on Struts 2 · G l a r i m y Training on Struts 2 Krishna Mohan Koyya, M.Tech, DBM, PMP Technology Consultant & Corporate Trainer krishna@glarimy.com |

• A total of 13 years of experience with the IT Industry• Since July 2008

– Technology Consultant & Corporate Trainer– Runs G l a r i m y, online skill development portal

• June 2007- May 2008– Associate Professor & HOD of Department of IT– Sasi Institute of Technology and Engineering, Tadepalligudem, India

• Jan 2006 – Dec 2006– Chief Executive Officer– Sudhari IT Solutions India Private Limited, Bangalore, India

• Dec 2000 – Jan 2006– Software Engineer– Cisco Systems India Private Limited, Bangalore, India

• Nov 1998 – Dec 2000– Senior Software Engineer– Wipro Technologies, Bangalore, India

• Others– Dhanya Software for Hewlett-Packard ISO, Bangalore, India in 1998– Ace Software Exports Limited, Rajkot, India in 1997– Neo Software, Visakhapatnam in 1994-1995

Career

© 2009, Glarimy. All rights reserved.

G l a r i m y

Page 6: G l a r i m y Training on Struts 2 · G l a r i m y Training on Struts 2 Krishna Mohan Koyya, M.Tech, DBM, PMP Technology Consultant & Corporate Trainer krishna@glarimy.com |

• Basic– Java Induction http://www.glarimy.com/courses/gb01.php – Java http://www.glarimy.com/coursess/gb02.php – XML http://www.glarimy.com/courses/gb03.php – OOAD & UML http://www.glarimy.com/courses/gb04.php – Design Patterns http://www.glarimy.com/courses/gb05.php

• Advanced– JEE Web Component http://www.glarimy.com/courses/ga01.php – JEE Enterprise Component http://www.glarimy.com/courses/ga02.php – Axis Web Services http://www.glarimy.com/courses/ga03.php – Spring Framework http://www.glarimy.com/courses/ga04.php – Hibernate http://www.glarimy.com/courses/ga05.php – Struts2 http://www.glarimy.com/courses/ga06.php – Java Server Faces http://www.glarimy.com/courses/ga07.php – JBoss SEAM http://www.glarimy.com/courses/ga08.php – Dojo Framework http://www.glarimy.com/courses/ga09.php – Extreme Programming http://www.glarimy.com/courses/ga10.php

• Full list of courses– http://www.glarimy.com/courses

Training Courses

© 2009, Glarimy. All rights reserved.

G l a r i m y

Page 7: G l a r i m y Training on Struts 2 · G l a r i m y Training on Struts 2 Krishna Mohan Koyya, M.Tech, DBM, PMP Technology Consultant & Corporate Trainer krishna@glarimy.com |

Corporate Trainings

© 2009, Glarimy. All rights reserved.

G l a r i m y

BangaloreChennaiMysore

Hyderabad

Page 8: G l a r i m y Training on Struts 2 · G l a r i m y Training on Struts 2 Krishna Mohan Koyya, M.Tech, DBM, PMP Technology Consultant & Corporate Trainer krishna@glarimy.com |

© 2009, Glarimy. All rights reserved.

G l a r i m y

Agenda• Session 1

– Breaking the Ice with Introduction– PreTest– MVC Framework– DI & AOP

• Session 2– Struts Architectural Goals– Struts Architecture– Hello World

• Session 3– Actions– Interceptors

• Session 4– Validation Framework– Internationalization

Stru

ts2 F

ram

ewor

k

Page 9: G l a r i m y Training on Struts 2 · G l a r i m y Training on Struts 2 Krishna Mohan Koyya, M.Tech, DBM, PMP Technology Consultant & Corporate Trainer krishna@glarimy.com |

MVC Framework• Client Server Systems

– Clients– Server– Request/Response– Protocols

• The J2EE Web Architecture– Browser– Web Server– Java– Servlets– JSP– Business Logic

• FrontController– Model– View– Controller

G l a r i m y

© 2009, Glarimy. All rights reserved.

Page 10: G l a r i m y Training on Struts 2 · G l a r i m y Training on Struts 2 Krishna Mohan Koyya, M.Tech, DBM, PMP Technology Consultant & Corporate Trainer krishna@glarimy.com |

MVC Framework• Common Features

– Validation– Exception Handling– Navigation – Internationalization– Tiling– Data Binding– Data Conversion– Configuration– Session Management

G l a r i m y

© 2009, Glarimy. All rights reserved.

Page 11: G l a r i m y Training on Struts 2 · G l a r i m y Training on Struts 2 Krishna Mohan Koyya, M.Tech, DBM, PMP Technology Consultant & Corporate Trainer krishna@glarimy.com |

AOP• Cross Cutting Concerns

– Advice/Aspect– Join-points– Point-cuts– Advisor/Interceptor

• Weaving– Compile Time– Load Time– Compile Time

• Aspects– Validation– Security– Transaction– Conversion– Filters– Logging

G l a r i m y

© 2009, Glarimy. All rights reserved.

Page 12: G l a r i m y Training on Struts 2 · G l a r i m y Training on Struts 2 Krishna Mohan Koyya, M.Tech, DBM, PMP Technology Consultant & Corporate Trainer krishna@glarimy.com |

Dependency Injection• Object Orientation

– Classes/Objects– Relations

• Dependency• Association• Aggregation• Composition

• Inversion of Control– Injecting Dependencies– Java Bean Architecture

• Framework– Factory– Configuration (wiring)

• Advantages– Loose Coupling– Configurability– Testability

G l a r i m y

© 2009, Glarimy. All rights reserved.

Page 13: G l a r i m y Training on Struts 2 · G l a r i m y Training on Struts 2 Krishna Mohan Koyya, M.Tech, DBM, PMP Technology Consultant & Corporate Trainer krishna@glarimy.com |

Struts 2 Architectural Goals• Separation of Concerns

– Pre Action Logic– Obtaining Business Objects– Translation– Separation of Concerns

• Loose Coupling– URL to Action mapping– Results to View mapping– Exceptions to View mapping

• Testability– De-linking HTTP objects

• Modularization– Distributed Configuration– Plug-ins– Flexibility

• Convention– Not just configuration– Intelligent Defaults

G l a r i m y

© 2009, Glarimy. All rights reserved.

Page 14: G l a r i m y Training on Struts 2 · G l a r i m y Training on Struts 2 Krishna Mohan Koyya, M.Tech, DBM, PMP Technology Consultant & Corporate Trainer krishna@glarimy.com |

Struts 2 Architecture• Controller (Filter/Dispatcher)• Model-Action• View-Result• Interceptors• Value Stack• Object Graph Notation Language

G l a r i m y

© 2009, Glarimy. All rights reserved.

Page 15: G l a r i m y Training on Struts 2 · G l a r i m y Training on Struts 2 Krishna Mohan Koyya, M.Tech, DBM, PMP Technology Consultant & Corporate Trainer krishna@glarimy.com |

Struts 2 Actions• What they do?

– Encapsulates business logic– Point of data transfer– Returns control strings

• One for each request• POJO as Action

– Method: execute() returns String• Optional Action Interface

– Method: execute() returns String– Control Strings

• SUCCESS• INPUT• LOGIN• NONE• ERROR

G l a r i m y

© 2009, Glarimy. All rights reserved.

Page 16: G l a r i m y Training on Struts 2 · G l a r i m y Training on Struts 2 Krishna Mohan Koyya, M.Tech, DBM, PMP Technology Consultant & Corporate Trainer krishna@glarimy.com |

Struts 2 Actions• Basic Data Binding

– Fields to Bean Properties• Object Binding

– Fields to Model Objects– Bean Backed

• OGNL with dot notation: • Accessors for the object

– Model Driven• ModelDriven interface• getModel mothod• Model object instantiation• No re-initialization of the model object //NOTE THIS

G l a r i m y

© 2009, Glarimy. All rights reserved.

Page 17: G l a r i m y Training on Struts 2 · G l a r i m y Training on Struts 2 Krishna Mohan Koyya, M.Tech, DBM, PMP Technology Consultant & Corporate Trainer krishna@glarimy.com |

Struts 2 Actions• ActionSupport class

– Basic Validation• Interceptor: workflow• Interface: Validateable

– Method: validate• Interface: ValidateAware

– Methods: addFieldError, addActionError• Control String: input

– Basic Internationalization• Interface: TextProvider• Resource Bundles: properties files• Method: getText()

G l a r i m y

© 2009, Glarimy. All rights reserved.

Page 18: G l a r i m y Training on Struts 2 · G l a r i m y Training on Struts 2 Krishna Mohan Koyya, M.Tech, DBM, PMP Technology Consultant & Corporate Trainer krishna@glarimy.com |

Struts 2 Interceptors• ActionInvocation

– Interceptors– Action– Result– Method: invoke()

• Interceptor– Method: intercept

• Parameter: ActionInvocation– Pre-processing– ActionInvocation.invoke(); //result is rendered, please note this.– Post-processing and return result

• Stacks– Order of Interceptors– Default Stack– Basic Stack

• Categories– Utility Interceptors– Data Transfer Interceptors– Workflow Interceptors– Other Interceptors

G l a r i m y

© 2009, Glarimy. All rights reserved.

Page 19: G l a r i m y Training on Struts 2 · G l a r i m y Training on Struts 2 Krishna Mohan Koyya, M.Tech, DBM, PMP Technology Consultant & Corporate Trainer krishna@glarimy.com |

Struts 2 Interceptors• Deploying Interceptors

– Pacakge• Interceptors

– Interceptor with Name and class– Interceptor-stack with Name

» Interceptor-ref with name– Default-interceptor-ref with name (stack name)

– Action• Interceptor-ref with name• Default-intercetor-ref with name (also stack name)

• Building Interceptors– Intercetor interface– Methods:

• Destory• Init• intercept

G l a r i m y

© 2009, Glarimy. All rights reserved.

Page 20: G l a r i m y Training on Struts 2 · G l a r i m y Training on Struts 2 Krishna Mohan Koyya, M.Tech, DBM, PMP Technology Consultant & Corporate Trainer krishna@glarimy.com |

Struts 2 Interceptors• Important Interceptors

– Params: Sets request parameters into action– CreateSession: Creates HttpSession– I18n: Remembers locale– Validation: Validates using configuration– Workflow: Validates using action code– Exception: Maps exceptions to the result

G l a r i m y

© 2009, Glarimy. All rights reserved.

Page 21: G l a r i m y Training on Struts 2 · G l a r i m y Training on Struts 2 Krishna Mohan Koyya, M.Tech, DBM, PMP Technology Consultant & Corporate Trainer krishna@glarimy.com |

Struts 2 Data Converters• Value Stack

– Stack of Properties– Treated as its own properties

• OGNL– Language for Object Graph– Out side of Struts2

• Built-in-Converters– Primitive Types (and Wrappers)– Date– List, Map and array

• Custom Converters– Interface: TypeConvertor (OGNL)– Class: StrutsTypeConvertor (Struts)

• convertFromString• convertToString

– Deployment• <action>-conversion.properties• xwork-conversion.properties• Any where in the class path

G l a r i m y

© 2009, Glarimy. All rights reserved.

Page 22: G l a r i m y Training on Struts 2 · G l a r i m y Training on Struts 2 Krishna Mohan Koyya, M.Tech, DBM, PMP Technology Consultant & Corporate Trainer krishna@glarimy.com |

Java Development Kit 1.6• Installation

– Download URL• http://java.sun.com/j2se/downloads

– Installation• Double click on the installable and click Run on the pop-up dialog• Install it into C:\Program Files\Java\jdk1.6.0_14• Verify that you find folders like jre, bin, lib and etc are found under

C:\Program Files\Java\jdk1.6.0_14 folder• Create a new environment variable JAVA_HOME to C:\Program

Files\Java\jdk1.6.0_14• Create or edit PATH variable with value %JAVA_HOME%\bin

• Using Java – Type javac –version on command prompt

• javac 1.6.0_14 should be the response– Type java –version on command prompt

• Java version “1.6.0_14” should be the response

G l a r i m y

© 2009, Glarimy. All rights reserved.

Page 23: G l a r i m y Training on Struts 2 · G l a r i m y Training on Struts 2 Krishna Mohan Koyya, M.Tech, DBM, PMP Technology Consultant & Corporate Trainer krishna@glarimy.com |

Apache Tomcat 6.0.20• Installation

– Pre-requisites• Java 1.6• Setup JAVA_HOME

– Download URL• http://apache.mirrors.timporter.net/tomcat/tomcat-6/v6.0.20/bin/apache-tomcat-6.0.20.zip

– Installation• Extract the downloaded zip to C:\Program Files• Rename the apache-tomcat-6.0.20 to Tomcat for convenience• Set C:\Program Files\Tomcat as TOMCAT_HOME

– Default port number• 8080• Can be changed in the file %TOMCAT_HOME%\conf\server.xml

• Running/Stopping – To run - %TOMCAT_HOME%\bin\startup.bat– Default Homepage

• http://localhost:8080 or http://127.0.0.1:8080– Debugging - %TOMCAT_HOME%\logs– To stop - %TOMCAT_HOME%\bin\shutdown.bat

• Application Access– http://localhost:8080/<context-root>/<app-specific-resources>

G l a r i m y

© 2009, Glarimy. All rights reserved.

Page 24: G l a r i m y Training on Struts 2 · G l a r i m y Training on Struts 2 Krishna Mohan Koyya, M.Tech, DBM, PMP Technology Consultant & Corporate Trainer krishna@glarimy.com |

Tomcat with Eclipse• Installing Eclipse 3.4 (Ganymede)

– Assumption• JDK is already installed• Tomcat are already installed but not started (stop it, otherwise)

– Download http://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/galileo/R/eclipse-jee-galileo-win32.zip

– Unzip to C:\Program Files– Rename it to Eclipse for convenience

• Running Eclipse– Double click on eclipse.exe under Eclipse– Verify that J2EE perspective is opened

• Configuring Tomcat– Go to File->New->Other->Server->Server->Next– Select Apache-Tomcat v6.0 Server and click Next– Enter ‘C:\Program Files\Tomcat’ for ‘Tomcat installation directory’ and click

‘Finish’• Running Tomcat from Eclipse

– Select ‘servers’ tab (right-lower portion)– Right click on Tomcat and click ‘Start’– Select ‘Unblock’ if security alert pops-up

G l a r i m y

© 2009, Glarimy. All rights reserved.

Page 25: G l a r i m y Training on Struts 2 · G l a r i m y Training on Struts 2 Krishna Mohan Koyya, M.Tech, DBM, PMP Technology Consultant & Corporate Trainer krishna@glarimy.com |

© 2008, Glarimy. All rights reserved.

G l a r i m yG l a r i m y

© 2009, Glarimy. All rights reserved.

For Technical [email protected]

FAQ, Tutorials, Presentations, Samples, Quiz

http://www.glarimy.com

For Appointments091-9731 4231 66

Thank Youwww.glarimy.com