SlideShare a Scribd company logo
SoftLeader Tech. Corp.
李日貴 jini
王文農 steven
Java 熱門 Framework 運用與比較
About us..
• Demo codes
http://code.google.com/p/javatwo2012-java-framework-comparison/

• My facebook page
https://www.facebook.com/EnterpriseJava

• Javaworld@Tw ( javaworld.com.tw )
jini

atpqq
JavaEE Multi-Tiers architecture



HttpServletRequest


                     Web    Business   DAO    DB
                     Tier     Tier     Tier

HttpServletResponse
Lots of frameworks
Java Persistence
    ( DAO )
JPA 2
• 簡化 JDBC
• Native SQL
• 設定容易
• XML or Annotation
Javatwo2012 java frameworkcomparison
Customer.java

public class Customer {

    private Long id;

    private String name;

    private Integer age;

    // getters and setters

}
Customer-mapper.xml

<mapper
namespace=“javatwo2012.dao.mybatis.Customer”>

 <select id=“getCustomerById”
parameterType=“Long” resultType=“customer”>

   <!-- select SQL with #id -->

 </select>

</mapper>
mybatis-config.xml

<configuration>

 <settings> … </settings>

 <mappers>

    <mapper
resource=“javatwo2012/dao/mybatis/Customer-
mapper.xml”/>

 </mappers>

</configuration>
CustomerDao.java

SqlSession session =
sqlSessionFactory.openSession();

try {

  Customer customer =
session.selectOne(“javatwo2012.dao.mybatis.Cust
omer.getCustomerById”, new Long(101));

} finally {

    session.close();

}
• 完整 ORM
• 易於更換資料庫
• 多種查詢機制
• 支援多種 Cache
• 多元的資料 Initialize
Customer.java

@Entity

@Table(name=“CUSTOMER”)

public class Customer {

    @Id

    @GeneratedValue(strategy=GenerationType.Identity)

    @Column(name=“ID”)

    private Long id;

    // getters and setters

}
hibernate-cfg.xml

<hibernate-configuration>

  <session-factory>

  <property name=“dialect”>DB_Dialect</property>

  <mapping class=“javatwo2012.dao.hibernate.Customer”/>

  </seesion-factory>

</hibernate-configuration>
CustomerDao.java

public Customer findById(Long id) {

 SessionFactory sessionFactory = new
Configuration().configure().buildSessionFactory();

    Session session = sessionFactory.openSession();

    Criteria crit = session.createCriteria(Customer.class);

    crit.add(Restrictions.idEq(id));

    return (Customer) crit.uniqueResult();

}
• JavaEE 標準
        • 吸收了各家的優點
JPA 2   • 多種查詢機制
        • 支援多種 Cache
        • 多元的資料 Initialize
        • Transaction Control
Customer.java

        @Entity

        @Table(name=“CUSTOMER”)

        public class Customer {
JPA 2
            @Id

            @GeneratedValue(strategy=GenerationType.Identity)

            @Column(name=“ID”)

            private Long id;

            // getters and setters

        }
persistence.xml

        <persistence>

          <persistence-unit name=“javatwo2012demo” transaction-
        type=“RESOURCE_LOCAL” >

JPA 2      <provider>org.hibernate.ejb.HibernatePersistence</provider>

           <properties>..</properties>

         </persistence-unit>

        </persistence>
CustomerDao.java

        public Customer findById(Long id) {

         EntityManagerFactory emFactory =
        Persistence.createEntityManagerFactory(“javatwo2012demo”);

JPA 2       EntityManager manager = emFactory.createEntityManager();

            return (Customer) manager.find(Customer.class, id);

        }
項目
                       JPA 2
  學習容易度     容易    複雜    複雜

  查詢 API    少     多     多

 SQL優化容易度   較簡單   複雜    複雜

資料庫方言依賴程度   高     低     低

   效能       佳     佳    依實作而定

  可移植性      普通    佳    依實作而定

  社群支援      多     多     多
Java Web
 ( MVC )
• Annotation Driven
• AJAX inside
• UnitTest
• REST Integration
• Multi-Languages
• HTML5 + CSS3
• Action-Based   • Component-Based




                        JSF 2
web.xml

<filter-class>

org.apache.struts2.dispatcher.ng.StrutsPrepareAndExecu
teFilter

</filter-class>
struts.xml

<struts>

 <package name=“javatwo2012” extends=“struts-default”>

 <action name=“hello” class=“…HelloAction”>

      <result>/hello.jsp</result>

      <result name=“input”>/hello.jsp</result>

 </action>

 </package>

</struts>
HelloAction.java

public class HelloAction extends ActionSupport {

    private String message;

    public String getMessage() { return this.message; }

    public String execute() {

        return SUCCESS;

    }

}
hello.jsp

<%@ taglib prefix=“s” uri=“/sturts-tags”%>

<s:property value=“message”/>
AuthAction.java

public class AuthAction extends ActionSupport {

    public String validate() {

        if( … ) {

            addFieldError(“account”, “Account can’t be empty”);

        }

    }

    public String execute() {    …. }

}
Javatwo2012 java frameworkcomparison
• 優點
– 很多人用, 工作機會多
– 豐富的 Taglibs
– 很多擴充的 plugins
• 缺點
– struts.xml
– 需要用 result 對應
– Source-Codes 混亂
web.xml

<filter-class>

net.sourceforge.stripes.controller.StripesFilter

</filter-class>



<servlet-class>

net.sourceforge.stripes.controller.DispatcherServlet

</servlet-class>
HelloActionBean.java

public class HelloActionBean implements ActionBean {

    private ActionBeanContext context;

    pirvate String message;

    @DefaultHandler

    public Resolution init() {

         message = “Hello Stripes !”

         return new ForwardResolution(“/hello.jsp”);

    }

}
hello.jsp

${actionBean.message}
AuthActionBean.java

@Validate(required=true)

private String account;

@Validate(required=true, minlength=4, maxlength=6)

private String password;
login.jsp

<%@taglib prefix=“stripes”
uri=“http://stripes.sourceforge.net/stripes.tld” %>

<stripes:errors/>

<stripes:form action=“/Auth.action” focus=“account”>

 <stripes:text id=“account” name=“account”/>

 <stripes:password id=“password” name=“password”/>

 <stripes:submit name=“login” value=“LOGIN”/>

</stripes:form>
Javatwo2012 java frameworkcomparison
• 優點
 – 利用 ActionContext 處理
   HttpServletRequest
 – 使用 Resolution 作為 forward /
   redirect 物件
 – 在 JSPs 中直接使用
   ${actionBean.obj}
• 缺點
 – 很少人使用
 – 開發週期長
  – V1.5.6(2011-03-14), v1.5.7(2012-05-18)
web.xml

<servlet>

 <servlet-name>spring</servlet-name>

 <servlet-class>

    org.springframework.web.servlet.DispatcherServlet

 </servlet-class>

</sevlet>



/WEB-INF/spring-servlet.xml
spring-servlet.xml

<beans …>

 <context:component-scan base-package=“javatwo2012.mvc”/>

 <bean
class=“org.springframework.web.servlet.view.InternalResourceViewResolver
”>

     <property name=“prefix” value=“/WEB-INF/jsp/”/>

     <property name=“suffix” value=“.jsp”/>

  </bean>

</beans>
HelloController.java

@Controller

public class HelloController {

    @RequestMapping(“/hello”)

    public String hello(ModelMap model) {

         model.addAttribute(“message”, “Hello SpringMVC !”);

         return “hello”;

     }

}
LoginForm.java

public class LoginForm {

    @NotEmpty

    private String account;

    @NotEmpty

    @Size(min=4, max=6)

    private String password;

}
AuthController.java

@Controller

public class AuthController {

    @RequestMapping(“/auth/doLogin”)

   public String hello(@Valid LoginForm loginForm,
BindingResult result) {

         if( result.hasErrors() ) return “login”;

         //..

     }

}
login.jsp

<%@ taglib prefix=“form”
uri=“http://www.springframework.org/tags/form”%>

<form:form action=“/auth/doLogin” commandName=“loginForm”>

<form:input path=“account”/><form:errors path=“account”/>

<form:password path=“password”/><form:errors
path=“password”/>

<input type=“submit” value=“LOGIN”/>

</form:form>
Javatwo2012 java frameworkcomparison
• 優點
 –   彈性且清晰的框架
 –   View 端可整合多種解決方案
 –   強大的 RESTful 支援
 –   JSR 303 Bean Validation
• 缺點
 – 過於彈性, 規範不易
 – 沒有內建 AJAX
web.xml

<context-param>

<param-name>tapestry.app-package</param-name>

<param-value>javatwo2012.mvc.tapestry.web</param-value>

</context-param>



<filter-name>app</fitler-name>

<filter-class>org.apache.tapestry5.TapestryFilter</filter-class>
javatwo2012.mvc.tapestry.web

• components
  – Layout.java

• pages
  – Hello.java
  – Hello.tml

• services
  – AppModule.java
Login.java

public class Login {

    @Property

    private String account;

    @Property

    private String password;

    public Class<?> onSuccess() {

        return Welcome.class;

    }

}
Login.tml

<html xmlns:t=“…”>

 <t:form t:id=“loginForm”>

 <t:textField t:id=“account” value=“account” validate=“required”/>

  <t:passwordField t:id=“password” value=“password”
validate=“required, minLength=4, maxLength=6”/>

  <t:submit value=“LOGIN”/>

</html>
Javatwo2012 java frameworkcomparison
• 優點
 – 物件開發容易
 – 執行效能卓越
 – 異常報告完整
• 缺點
 – 學習曲線高
 – 使用者較少, 工作數量也不多
web.xml

<filter-class>

org.apache.wicket.protocol.http.WicketFilter

</filter-class>

<init-param>

  <param-name>applicationClassName</param-name>

  <param-value>javatwo2012.mvc.wicket.HelloApp</param-value>

</init-param>
HelloApp.java

public class HelloApp extends WebApplication {

    public Class<? extends Page> getHomePage() {

        return HelloPage.class;

    }

}
HelloPage.java

public class HelloPage extends WebPage {

    public HelloPage() {

        add( new Label(“message”, “Hello Wicket !!”);

    }

}

HelloPage.html

<span wicket:id=“message”> Message on here </span>
• 優點
 – Swing-based UI 動態開發方式
 – 元件可重複使用性高
 – 熱血的社群
• 缺點
 –   學習曲線高
 –   Server-side 所需硬體較高 ( cpu/ram)
 –   效能調校需要長足經驗
 –   使用者較少, 工作數量也不多
web.xml

        <servlet-class>

        Javax.faces.webapp.FacesServlet

        </servlet-class>
JSF 2
HelloBean

        @ManagedBean

        @SessionScoped

        public class HelloBean {
JSF 2       private String message = “Hello JSF 2.0 !”;

            private String getMessage() {

                return message;

            }

        }
hello.xhtml

        <html xmlns:f=“http://java.sun.com/jsf/core”

              xmlns:h=“http://java.sun.com/jsf/html”>

          <h:head><title>JSF 2.0 Hello</title></h:head>
JSF 2     <h:body>

                  #{helloBean.message}

           </h:body>

        </html>
AuthBean

        public class AuthBean {

            public String checkLogin() {

                if(true) {

JSF 2              forward=“login”;

                   return “Login Success”;

                } else { return “Login Failed”; }

            }

            public String doLogin() { return forward; }

        }
login.xhtml

        <form id=“loginForm”>

          <h:inputText id=“account” value=“#{authBean.account}”
        required=“true”/> <h:message for=“account” style=“color:red”/>

JSF 2     <h:inputSecret id=“password” value=“#{authBean.password}”
        required=“true”>

             <f:validateLength minimum=“4” maximum=“6”/>

          </h:inputSecret>

          <h:commandButton id=“loginBtn” value=“LOGIN”
        actionListener=“#{authBean.checkLogin}”
        action=“#{authBean.doLogin}”/>

        </form>
JSF 2
• 優點
         –   JavaEE 標準, 官方支援
         –   具有非常多實作專案
         –   進入門檻低
         –   有視覺化設計的 IDE 介面
JSF 2
        • 缺點
         – 大多元件需要使用 SessionScope 浪
           費 Server-side 資源
         – 大量與繁瑣的 JSPs (xhtml) 開發
hello.gwt.xml

<module>

  <inherits name=“com.google.gwt.user.User” />

  <source path=“client”/>

  <entry-point class=“javatwo2012.mvc.gwt.client.Hello” />

</module>
client/HelloService.java

@RemoteServiceRelativePath(“hello”)

public interface HelloService extends RemoteService {

    public String getMessage();

}

client/HelloServiceAsync.java

public interface HelloServiceAnsyc {

    void getMessage(AsyncCallback<String> callback);

}
client/Hello.java

public class Hello implements EntryPoint {

 private final HelloServiceAsync helloService =
GWT.create(HelloService.class);

    private final Label message = new Label();

    public void onModuleLoad() {

    RootPanel.get().add(message);

    helloService.getMessage(new AsyncCallback<String>() {

          public void onSuccess(String result) { .. }

          public void onFailure(Throwable caught) { … }

    });

}
server/HelloServiceImpl

public class HelloServiceImpl extends RemoteServiceServlet
implements HelloService {

    public String getMessage() {

        return “Hello GWT !”;

    }

}
web.xml

<servlet-class>

Javatwo2012.mvc.gwt.server.HelloServiceImpl

</servlet-class>
hello.jsp

<script type=“text/javascript” language=“javascript”
src=“…/nocache.js”></script>
hello.gwt.xml

<module>

  <inherits name=“com.google.gwt.user.User” />

  <source path=“client”/>

  <entry-point class=“javatwo2012.mvc.gwt.client.Hello” />

</module>
Javatwo2012 java frameworkcomparison
• 優點
 –   Rich-client
 –   有 GWT Designer 支援
 –   UI 編寫容易, 無須理解 Javascript ?
 –   有許多延伸實作的專案
• 缺點
 – 學習曲線高
 – 開發效率慢
 – 都是在 Java 上開發
Conclusion

More Related Content

PDF
Java Web Programming [3/9] : Servlet Advanced
PDF
Java Web Programming [2/9] : Servlet Basic
PDF
Java Web Programming [6/9] : MVC
PDF
The Rails Way
PDF
Java Web Programming [7/9] : Struts2 Basics
PDF
JBoss Seam vs JSF
PDF
Java Web Development with Stripes
PDF
Stripes Framework
Java Web Programming [3/9] : Servlet Advanced
Java Web Programming [2/9] : Servlet Basic
Java Web Programming [6/9] : MVC
The Rails Way
Java Web Programming [7/9] : Struts2 Basics
JBoss Seam vs JSF
Java Web Development with Stripes
Stripes Framework

What's hot (20)

PDF
Java Web Programming [4/9] : JSP Basic
PDF
JavaServer Faces 2.0 - JavaOne India 2011
PPTX
Resthub lyonjug
PDF
Suportando Aplicações Multi-tenancy com Java EE
PDF
AtlasCamp 2010: Understanding the Atlassian Platform - Tim Pettersen
PDF
AtlasCamp 2013: Modernizing your Plugin UI
PDF
Lecture 9 - Java Persistence, JPA 2
PDF
What's new in Java EE 7
PDF
Introducing Rendr: Run your Backbone.js apps on the client and server
PDF
Java Web Programming on Google Cloud Platform [2/3] : Datastore
PDF
Java Web Programming on Google Cloud Platform [3/3] : Google Web Toolkit
PPTX
Implicit object.pptx
PDF
Lecture 5 JSTL, custom tags, maven
PDF
TechDays 2013 Jari Kallonen: What's New WebForms 4.5
PPSX
JSP - Part 2 (Final)
PDF
Fifty Features of Java EE 7 in 50 Minutes
PDF
10 J D B C
PDF
Rich Portlet Development in uPortal
PPSX
ASP.Net Presentation Part3
Java Web Programming [4/9] : JSP Basic
JavaServer Faces 2.0 - JavaOne India 2011
Resthub lyonjug
Suportando Aplicações Multi-tenancy com Java EE
AtlasCamp 2010: Understanding the Atlassian Platform - Tim Pettersen
AtlasCamp 2013: Modernizing your Plugin UI
Lecture 9 - Java Persistence, JPA 2
What's new in Java EE 7
Introducing Rendr: Run your Backbone.js apps on the client and server
Java Web Programming on Google Cloud Platform [2/3] : Datastore
Java Web Programming on Google Cloud Platform [3/3] : Google Web Toolkit
Implicit object.pptx
Lecture 5 JSTL, custom tags, maven
TechDays 2013 Jari Kallonen: What's New WebForms 4.5
JSP - Part 2 (Final)
Fifty Features of Java EE 7 in 50 Minutes
10 J D B C
Rich Portlet Development in uPortal
ASP.Net Presentation Part3
Ad

Viewers also liked (20)

PDF
Java 開發者的函數式程式設計
PDF
GCPUG meetup 201610 - Dataflow Introduction
PDF
lambda/closure – JavaScript、Python、Scala 到 Java SE 7
PDF
從 Web Site 到 Web Application,從 Web Services 到 Mobile Services
PPT
lwdba – 開放原始碼的輕量級資料庫存取程式庫
PDF
JCConf 2015 - Google Dataflow 在雲端大資料處理的應用
PDF
深入淺出 Web 容器 - Tomcat 原始碼分析
PDF
千呼萬喚始出來的 Java SE 7
PDF
Java SE 8 的 Lambda 連鎖效應 - 語法、風格與程式庫
PDF
淺談JavaFX 遊戲程式
PDF
Joda-Time & JSR 310 – Problems, Concepts and Approaches
PDF
淺談 Groovy 與 AWS 雲端應用開發整合
PDF
淺談 Groovy 與 Gradle
PDF
JDK8 Functional API
PDF
淺談 Java GC 原理、調教和 新發展
PDF
如何用JDK8實作一個小型的關聯式資料庫系統
PPT
Java SE 8 技術手冊第 15 章 - 通用API
PPTX
全文搜尋引擎的進階實作與應用
PDF
Spock:願你的測試長長久久、生生不息
PPTX
Block chain
Java 開發者的函數式程式設計
GCPUG meetup 201610 - Dataflow Introduction
lambda/closure – JavaScript、Python、Scala 到 Java SE 7
從 Web Site 到 Web Application,從 Web Services 到 Mobile Services
lwdba – 開放原始碼的輕量級資料庫存取程式庫
JCConf 2015 - Google Dataflow 在雲端大資料處理的應用
深入淺出 Web 容器 - Tomcat 原始碼分析
千呼萬喚始出來的 Java SE 7
Java SE 8 的 Lambda 連鎖效應 - 語法、風格與程式庫
淺談JavaFX 遊戲程式
Joda-Time & JSR 310 – Problems, Concepts and Approaches
淺談 Groovy 與 AWS 雲端應用開發整合
淺談 Groovy 與 Gradle
JDK8 Functional API
淺談 Java GC 原理、調教和 新發展
如何用JDK8實作一個小型的關聯式資料庫系統
Java SE 8 技術手冊第 15 章 - 通用API
全文搜尋引擎的進階實作與應用
Spock:願你的測試長長久久、生生不息
Block chain
Ad

Similar to Javatwo2012 java frameworkcomparison (20)

PDF
In The Brain of Cagatay Civici: Exploring JavaServer Faces 2.0 and PrimeFaces
PDF
Unit 07: Design Patterns and Frameworks (3/3)
PDF
Java EE7 Demystified
PDF
Symfony2 - from the trenches
PDF
Dropwizard
PDF
Spring 3: What's New
PDF
Symfony2 from the Trenches
PDF
From 0 to Spring Security 4.0
KEY
Integrating Wicket with Java EE 6
PDF
jQuery and Rails: Best Friends Forever
PPTX
Spring Framework Petclinic sample application
PPTX
Let's react - Meetup
PPTX
Spring Web Flow. A little flow of happiness.
PDF
Servlets 3.0 - Asynchronous, Extensibility, Ease-of-use @ JavaOne Brazil 2010
PPTX
Java EE 8 security and JSON binding API
PDF
Apache Wicket Web Framework
PDF
AnkaraJUG Kasım 2012 - PrimeFaces
PDF
Javascript ui for rest services
PPT
presentation on java server pages vs servlet.ppt
In The Brain of Cagatay Civici: Exploring JavaServer Faces 2.0 and PrimeFaces
Unit 07: Design Patterns and Frameworks (3/3)
Java EE7 Demystified
Symfony2 - from the trenches
Dropwizard
Spring 3: What's New
Symfony2 from the Trenches
From 0 to Spring Security 4.0
Integrating Wicket with Java EE 6
jQuery and Rails: Best Friends Forever
Spring Framework Petclinic sample application
Let's react - Meetup
Spring Web Flow. A little flow of happiness.
Servlets 3.0 - Asynchronous, Extensibility, Ease-of-use @ JavaOne Brazil 2010
Java EE 8 security and JSON binding API
Apache Wicket Web Framework
AnkaraJUG Kasım 2012 - PrimeFaces
Javascript ui for rest services
presentation on java server pages vs servlet.ppt

More from Jini Lee (9)

PDF
Dev ops 顛覆新時代創新論壇
PPTX
Quartz
PPTX
Javaee7 jsr356-websocket
PPTX
Java8 javatime-api
PPTX
Maji BP
ODP
Tencent case study-2015
PPTX
投資組合規劃 Group8
PPTX
SoftLeader Jackson Training
PPTX
Software project-part1-realworld
Dev ops 顛覆新時代創新論壇
Quartz
Javaee7 jsr356-websocket
Java8 javatime-api
Maji BP
Tencent case study-2015
投資組合規劃 Group8
SoftLeader Jackson Training
Software project-part1-realworld

Recently uploaded (20)

PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Encapsulation theory and applications.pdf
PDF
KodekX | Application Modernization Development
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PPTX
Cloud computing and distributed systems.
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
cuic standard and advanced reporting.pdf
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
Modernizing your data center with Dell and AMD
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PPT
Teaching material agriculture food technology
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Unlocking AI with Model Context Protocol (MCP)
NewMind AI Weekly Chronicles - August'25 Week I
Encapsulation theory and applications.pdf
KodekX | Application Modernization Development
Chapter 3 Spatial Domain Image Processing.pdf
Cloud computing and distributed systems.
Spectral efficient network and resource selection model in 5G networks
cuic standard and advanced reporting.pdf
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Modernizing your data center with Dell and AMD
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Teaching material agriculture food technology
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
The Rise and Fall of 3GPP – Time for a Sabbatical?
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
NewMind AI Monthly Chronicles - July 2025
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Dropbox Q2 2025 Financial Results & Investor Presentation

Javatwo2012 java frameworkcomparison