SlideShare a Scribd company logo
Creating Modern Java Web
Applications Based on
and
ApacheCon: Core Europe 2015 by   ( )Johannes Geppert @jogep
About me
Apache Member and Struts PMC Member
Software Developer @ 
Living and working in Leipzig
About Struts2
Action based Java
web framework
Built upon a
Request/Response
cycle
Clean architecture
Easy to extend
with plugins
Conceptual Overview
Struts 2.5 is on the way!
Cleanup and Maintenance!
Switch to Java7
Increased Security with
SMI
xwork­core merged into
struts­core
Removal of deprecated
plugins
Dojo Plugin
Code Behind Plugin
JSF Plugin
Struts1 Plugin
Support for bean validation
Now as a (built­in) plugin available
Log4j2 as new Logging Layer
Replacement for Struts2
Logging Layer
Support for multiple
logging implementations
Better performance
Beta2 is available!
Why AngularJS?
 AngularJS is a structural framework for dynamic web apps.
It lets you use HTML as your template language and lets
you extend HTML's syntax to express your application's
components clearly and succinctly. Angular's data binding
and dependency injection eliminate much of the code you
would otherwise have to write. And it all happens within the
browser, making it an ideal partner with any server
technology.
https://docs.angularjs.org/guide/introduction
AngularJS ­ Overview
Google Trends
AngularJS, React, Backbone and ember.js
Blue line is the trend for AngularJS
Quickstart with Maven
Archetypes
mvn archetype:generate ­B  
         ­DgroupId=com.mycompany.mysystem 
         ­DartifactId=myWebApp 
         ­DarchetypeGroupId=org.apache.struts 
         ­DarchetypeArtifactId=struts2­archetype­angularjs 
         ­DarchetypeVersion=<CURRENT_STRUTS_VERSION> 
         ­DremoteRepositories=http://struts.apache.org
cd myWebApp
mvn jetty:run
Open Browser http://localhost:8080
REST Based Actions
with Struts2 REST Plugin
REST ­ Action Mapping
HTTP method URI Class.method Paramete
GET /order OrderController.index  
GET /order/1 OrderController.show id="1"
POST /order OrderController.create  
PUT /order/1 OrderController.update id="1"
DELETE /order/1 OrderController.destroy id="1"
Configure the REST Plugin
Add the rest plugin to the dependencies
<dependency>
  <groupId>org.apache.struts</groupId>
  <artifactId>struts2­rest­plugin</artifactId>
  <version>${struts2.version}</version>
</dependency>
Disable restrictToGET default behaviour
<constant name="struts.rest.content.restrictToGET" value="false"/>
Create packages for applications
<constant name="struts.convention.default.parent.package"
             value="rest­angular"/>
<package name="rest­angular" extends="rest­default">
    <default­action­ref name="index" />
</package>
<package name="data" extends="rest­angular" namespace="/data">
</package>
REST ­ Content Type Handler
/order/1 or /order/1.action Dispatcher (e.g. JSP)
/order/1.xml XML Handler
/order/1.json JSON Handler
Easy to build e.g. for CSV result
Built­in Jackson support for JSON serialization
<bean type="org.apache.struts2.rest.handler.ContentTypeHandler"
        name="jackson"
        class="org.apache.struts2.rest.handler.JacksonLibHandler"/>
<constant name="struts.rest.handlerOverride.json"
        value="jackson"/>
Live Demo
https://github.com/apache/struts­examples/tree/master/rest­
angular
Exception Handling
Custom Exception
Interceptor
protected String doIntercept(ActionInvocation actionInvocation)
                            throws Exception {
    try{
        return actionInvocation.invoke();
    } catch (Exception exception) {
        Map<String, Object> errors = new HashMap<>();
        HttpHeaders httpHeaders = new DefaultHttpHeaders()
            .disableCaching().withStatus(HttpServletResponse.SC_BAD_REQUEST)
                            .renderResult(Action.INPUT);
        if(exception instanceof SecurityException) {
            errors.put(ACTION_ERROR, "Operation not allowed!");
            httpHeaders.setStatus(HttpServletResponse.SC_FORBIDDEN);
        }  else { errors.put(ACTION_ERROR, exception.getMessage()); }
        return manager.handleResult(actionInvocation.getProxy().getConfig(),
                            httpHeaders, errors);
    }
}
Extend the Default
Interceptor Stack
<package name="data" extends="rest­angular" namespace="/data">
    <interceptors>
        <interceptor name="dataError"
            class="....ExceptionHandlerInterceptor"/>
        <interceptor­stack name="dataDefaultStack">
            <interceptor­ref name="dataError"/>
            <interceptor­ref name="restDefaultStack"/>
        </interceptor­stack>
    </interceptors>
    <default­interceptor­ref name="dataDefaultStack"/>
</package>
Dispatch an error event
Extend the generic _request method in DataService
$http(req).success(function(data) {
    def.resolve(data);
}).error(function(data, code) {
    def.reject(data);
    if(data.actionError) {
        $rootScope.$emit('data­error', {  msg: data.actionError });
    }
});
Listen to error events
e.g in a Controller
$rootScope.$on('data­error', function(event, alert) {
    console.log(alert.msg);
});
Live Demo
https://github.com/apache/struts­examples/tree/master/rest­
angular
Bean Validation
Client and Server side
New bean validation plugin
Setup bean validation
Specify a validation http status code
like "Not Acceptable"
<!­­ Set validation failure status code ­­>
<constant name="struts.rest.validationFailureStatusCode" value="406"/>
Change rest interceptor stack
Default validation interceptor is using the old validation
interceptor
Copy the rest default interceptor stack
Define the new one
<interceptor name="beanValidation"
    class="....interceptor.BeanValidationInterceptor"/>
Replace the "validation" reference with "beanValidation"
reference in the stack
Live Demo
https://github.com/apache/struts­examples/tree/master/rest­
angular
Multi­Language Support
Where do we need it?
Frontend Validation Backend
Resource Bundles
Split them up!
<constant name="struts.custom.i18n.resources"
                            value="frontend,validation,exceptions"/>
Sample for validation messages
#validation_en.properties
validation.order.client = Client name can not be blank
validation.order.amount = Order amount needs to be between 10 and 666
#validation_de.properties
validation.order.client = Kunden Name darf nicht leer sein
validation.order.amount = Anzahl muss zwischen 10 und 666 sein
Language Controller
public class LanguageController extends RestActionSupport
    implements ModelDriven<Map<String, String>> {
    private Map<String, String> model;
    public String index() throws Exception {
        ResourceBundle bundle = getTexts("frontend");
        this.model = bundle.keySet().stream()
            .collect(Collectors.toMap(
                key ­> key, key ­> bundle::getString));
        return Action.SUCCESS;
    }
    public Map<String, String> getModel() { return model; }
}
Setup Angular Translate
(function() {
'use strict';
angular
.module('app', ['ngRoute', 'ui.bootstrap', 'pascalprecht.translate']);
})();
$translateProvider.registerAvailableLanguageKeys(['en', 'de']);
$translateProvider.fallbackLanguage('en');
$translateProvider.useUrlLoader('data/language.json', {
    queryParameter: 'request_locale'
});
$translateProvider.determinePreferredLanguage();
With translate filter in templates
{{'order.client' | translate}}
In validation messages
@NotBlank(message = "validation.order.client")
@Min(value = 10, message = "validation.order.amount")
@Max(value = 666, message = "validation.order.amount")
In java code
throw new RuntimeException(getText("exception.not.supported"));
Live Demo
https://github.com/apache/struts­examples/tree/master/rest­
angular
Thank you!
https://twitter.com/jogep
Resources
 ­ 
 ­ 
 ­ 
 ­ 
 ­ 
Apache Struts Project https://struts.apache.org
Struts2 Maven Archetypes https://struts.apache.org/docs/struts­2­maven­archetypes.html
Struts2 Examples https://github.com/apache/struts­examples
AngularJS https://angularjs.org
Angular Translate https://angular­translate.github.io
Attributions
Leipzig Pictures by 
 by 
 by 
 by 
 by 
 by 
 by 
Ruthe Cartoon by 
 by 
 by 
 by 
 by 
 by 
Johannes Geppert
Model in the wind tunnel DLR ­ German Aerospace Center
Road Nicola
Clean Up Allen Goldblatt
Beans Matthew
Matrix pills ThomasThomas
Shaking Hands Aaron Gilson
ruthe.de
Language Scramble Eric Andresen
Windows Box Perfection Rachel Kramer
Krakow Door John Finn
1949 Ford Coupe ­ flat head V8 engine dave_7
Questions Alexander Henning Drachmann

More Related Content

DOC
Bao cao da lap trinh manh
DOCX
Phân tích thiết kế hệ thống thông tin PTIT
PDF
Luận văn: Xây dựng ứng dụng Android xem video trực tuyến, HAY
PDF
Tong hop cau hoi trac nghiem hdh
PPTX
Tổng quan về an toàn và bảo mật thông tin
PDF
BÁO CÁO ĐỒ ÁN MÔN HỌC ĐIỆN TOÁN ĐÁM MÂY ĐỀ TÀI: TÌM HIỂU VÀ SỬ DỤNG AMAZON WE...
PDF
Phân tích mã độc cơ bản - báo cáo thực tập
PPTX
Slide An toàn mạng nâng cao PTIT
Bao cao da lap trinh manh
Phân tích thiết kế hệ thống thông tin PTIT
Luận văn: Xây dựng ứng dụng Android xem video trực tuyến, HAY
Tong hop cau hoi trac nghiem hdh
Tổng quan về an toàn và bảo mật thông tin
BÁO CÁO ĐỒ ÁN MÔN HỌC ĐIỆN TOÁN ĐÁM MÂY ĐỀ TÀI: TÌM HIỂU VÀ SỬ DỤNG AMAZON WE...
Phân tích mã độc cơ bản - báo cáo thực tập
Slide An toàn mạng nâng cao PTIT

What's hot (20)

PPT
Bai07 bo nho
PPTX
Chess with Java
DOC
Quy trinh lap dat tram bts 3900 huawei
DOCX
BÁO CÁO CÔNG NGHỆ PHẦN MỀM 8 điểm-QUẢN LÝ CỬA HÀNG BÁN MÁY ẢNH
PPTX
Ossec – host based intrusion detection system
DOC
[14HCB]-Tìm Hiểu Weka
PPTX
Trí tuệ nhân tạo "Game cờ Caro"
DOC
Giáo trình Phân tích, thiết kế hệ thống thông tin
DOCX
Chuyên Đề Công Nghệ Phần Mềm PTIT
DOCX
Bài Giảng Vi Xử Lý ICTU
PDF
Tieng Anh chuyen nganh CNTT
PDF
Chuong 1. cnpm
DOCX
Báo cáo môn đảm bảo chất lượng phần mềm
PDF
Đề tài: Xây dựng ứng dụng Android nghe nhạc trên internet, HOT
PPTX
Tìm hiểu về Arduino và một số dự án với Arduino
PDF
Giáo trình hệ điều hành PTIT
PPTX
Tổng quan về quy trình Scrum
PDF
Hệ điều hành (chương 3)
PDF
XÂY DỰNG GAME CỜ VUA CHƠI QUA MẠNG
DOC
Mathlab cho xu ly anh
Bai07 bo nho
Chess with Java
Quy trinh lap dat tram bts 3900 huawei
BÁO CÁO CÔNG NGHỆ PHẦN MỀM 8 điểm-QUẢN LÝ CỬA HÀNG BÁN MÁY ẢNH
Ossec – host based intrusion detection system
[14HCB]-Tìm Hiểu Weka
Trí tuệ nhân tạo "Game cờ Caro"
Giáo trình Phân tích, thiết kế hệ thống thông tin
Chuyên Đề Công Nghệ Phần Mềm PTIT
Bài Giảng Vi Xử Lý ICTU
Tieng Anh chuyen nganh CNTT
Chuong 1. cnpm
Báo cáo môn đảm bảo chất lượng phần mềm
Đề tài: Xây dựng ứng dụng Android nghe nhạc trên internet, HOT
Tìm hiểu về Arduino và một số dự án với Arduino
Giáo trình hệ điều hành PTIT
Tổng quan về quy trình Scrum
Hệ điều hành (chương 3)
XÂY DỰNG GAME CỜ VUA CHƠI QUA MẠNG
Mathlab cho xu ly anh
Ad

Viewers also liked (20)

PDF
An introduction to Struts 2 and RESTful applications
PDF
Crash course of Mobile (SS7) privacy and security
PDF
The Web Development Eco-system with VSTS, ASP.NET 2.0 & Microsoft Ajax
PDF
M&L Webinar: “Open Source ILIAS Plugin: Interactive Videos"
KEY
Writing Your First Plugin
PPTX
AngularJS Animations
PPTX
Connections Plugins - Engage 2016
PPTX
Building ColdFusion And AngularJS Applications
PDF
Why should you publish your plugin as open source and contribute to WordPress?
PDF
Angular js best practice
PDF
Find WordPress performance bottlenecks with XDebug PHP profiling
PPTX
HTTP, JSON, REST e AJAX com AngularJS
PDF
Fighting Against Chaotically Separated Values with Embulk
PPTX
Open Source Monitoring Tools
PDF
Plugin-based software design with Ruby and RubyGems
KEY
Monitoring solutions comparison
PDF
An easy guide to Plugin Development
PDF
Worldwide attacks on SS7/SIGTRAN network
PDF
XSS再入門
PPT
Gstreamer plugin devpt_1
An introduction to Struts 2 and RESTful applications
Crash course of Mobile (SS7) privacy and security
The Web Development Eco-system with VSTS, ASP.NET 2.0 & Microsoft Ajax
M&L Webinar: “Open Source ILIAS Plugin: Interactive Videos"
Writing Your First Plugin
AngularJS Animations
Connections Plugins - Engage 2016
Building ColdFusion And AngularJS Applications
Why should you publish your plugin as open source and contribute to WordPress?
Angular js best practice
Find WordPress performance bottlenecks with XDebug PHP profiling
HTTP, JSON, REST e AJAX com AngularJS
Fighting Against Chaotically Separated Values with Embulk
Open Source Monitoring Tools
Plugin-based software design with Ruby and RubyGems
Monitoring solutions comparison
An easy guide to Plugin Development
Worldwide attacks on SS7/SIGTRAN network
XSS再入門
Gstreamer plugin devpt_1
Ad

Similar to Creating modern java web applications based on struts2 and angularjs (20)

PDF
Java web applications based on new Struts 2.5 and AngularJS (ApacheCon NA 2016)
PDF
Top 10 python frameworks for web development in 2020
PDF
Tech Stack - Angular
PPTX
S02 hybrid app_and_gae_restful_architecture_v2.0
PPT
Eclipsist2009 Rich Client Roundup
PPTX
CTE 323 - Lecture 1.pptx
DOCX
PPTX
Reason to choose Angular JS for your Web Application
PDF
NodeJs Frameworks.pdf
PDF
Spring Framework Tutorial | VirtualNuggets
PDF
Java 9 and Beyond
PPTX
Django Seminar
PPT
Java for Recruiters
DOCX
Project report for final year project
PDF
Top 11 Front-End Web Development Tools To Consider in 2020
PPTX
5 Treding Java Frameworks Offshore Developers Should About
PPTX
Top 10 Front End Development Technologies to Focus in 2018
PDF
Eclipse & java based modeling platforms for smart phone
PPT
Spring ppt
PPTX
Introduction Java Web Framework and Web Server.
Java web applications based on new Struts 2.5 and AngularJS (ApacheCon NA 2016)
Top 10 python frameworks for web development in 2020
Tech Stack - Angular
S02 hybrid app_and_gae_restful_architecture_v2.0
Eclipsist2009 Rich Client Roundup
CTE 323 - Lecture 1.pptx
Reason to choose Angular JS for your Web Application
NodeJs Frameworks.pdf
Spring Framework Tutorial | VirtualNuggets
Java 9 and Beyond
Django Seminar
Java for Recruiters
Project report for final year project
Top 11 Front-End Web Development Tools To Consider in 2020
5 Treding Java Frameworks Offshore Developers Should About
Top 10 Front End Development Technologies to Focus in 2018
Eclipse & java based modeling platforms for smart phone
Spring ppt
Introduction Java Web Framework and Web Server.

Recently uploaded (20)

PDF
Event Presentation Google Cloud Next Extended 2025
PDF
cuic standard and advanced reporting.pdf
PDF
KodekX | Application Modernization Development
PPTX
breach-and-attack-simulation-cybersecurity-india-chennai-defenderrabbit-2025....
PDF
REPORT: Heating appliances market in Poland 2024
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Advanced IT Governance
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
GDG Cloud Iasi [PUBLIC] Florian Blaga - Unveiling the Evolution of Cybersecur...
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Chapter 2 Digital Image Fundamentals.pdf
PDF
Omni-Path Integration Expertise Offered by Nor-Tech
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
SAP855240_ALP - Defining the Global Template PUBLIC.pdf
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
PDF
[발표본] 너의 과제는 클라우드에 있어_KTDS_김동현_20250524.pdf
PPTX
Telecom Fraud Prevention Guide | Hyperlink InfoSystem
PDF
Modernizing your data center with Dell and AMD
Event Presentation Google Cloud Next Extended 2025
cuic standard and advanced reporting.pdf
KodekX | Application Modernization Development
breach-and-attack-simulation-cybersecurity-india-chennai-defenderrabbit-2025....
REPORT: Heating appliances market in Poland 2024
Review of recent advances in non-invasive hemoglobin estimation
Advanced IT Governance
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
GDG Cloud Iasi [PUBLIC] Florian Blaga - Unveiling the Evolution of Cybersecur...
NewMind AI Weekly Chronicles - August'25 Week I
Chapter 2 Digital Image Fundamentals.pdf
Omni-Path Integration Expertise Offered by Nor-Tech
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
SAP855240_ALP - Defining the Global Template PUBLIC.pdf
Dropbox Q2 2025 Financial Results & Investor Presentation
NewMind AI Monthly Chronicles - July 2025
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
[발표본] 너의 과제는 클라우드에 있어_KTDS_김동현_20250524.pdf
Telecom Fraud Prevention Guide | Hyperlink InfoSystem
Modernizing your data center with Dell and AMD

Creating modern java web applications based on struts2 and angularjs