Author: David D, Research Scientist [email protected]1 Java Web Development 1) - Use JSP, like PHP, for Dynamic Web Application. Code implementation is included. 2) JSP - Model 1 Architecture: JSP for the View + Java Bean as the Model, which is the Business Logic, Database Access, Data. Code implementation is included. 3) JSP - Model 2 Architecture JSP for the View + Java Bean as the Model + Servlet as the Controller 4) JAVA in Enterprise Java for larger scale development - Modern Enterprise Java Cloud & Framework - JavaEE / J2EE Few notes: Research Scientists (R&D), our job is to do research in order to help improve things for better, benefits for every one, good for innovation, good for businesses, good for society, open and advanced. When building web application, you choose JAVA vs. Non Java, scripting Technologies. A lot of developers use non-JAVA Technologies because JAVA is complexity. But the price you pay for its power, robust, solid, and its ability to build complex application. This is a Roadmap for Java Web & Enterprise Application Development. Businesses, Investors, HR, Developers, Bosses, Managers understand Web Development in order to make right decision for your business, not depend on others. A CEO said :" - This is hard skill. If we get wrong people to build product, web application. Then it costs business, waste Time & Money to re-build, re-design. Then we get help from developers in other countries here. As a result, we lost business to competitors, lost competitiveness, lost comparativeness. Let's Build software, website for the next 20 years. "
26
Embed
Java Web DevelopmentJSPs ( Java Server Page ) are, like PHP pages, server-side scripting pages. JSP pages need to be processed on a web server like Tomcat before being sent to the
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
JSPs ( Java Server Page ) are, like PHP pages, server-side scripting pages.
JSP pages need to be processed on a web server like Tomcat before being sent to the client’s browser.
JSP page is translated into Java servlet before being executed. JSP technology is convenient way to code the Servlet.
Client Architecture Web Application - JSP ( Java Server Page ) alone.
JSP stand alone = PHP. Both is scripting language. JAVA is not scripting language. JAVA is Object Oriented
Programming. PHP is not JAVA, thus can't use Java Object Oriented. JSP can use Java Object.
Dynamic Web Application - All web applications, such as, PHP, JSP ... had Client (Web Browser), Application Server ( Tomcat, Apache, Web
Spere ... ), and Database Server ( MySql, Oracle, Ms Sql Server ..). AWS ( Amazon Web Services host used Tomcat ).
- In Client-Tier Architecture has no Funtional Logics or the Business Logics Tier. This Tier or Layer is responsible for:
Process commands, makes business rules, do calculations, connect database, and process data.
- Client-Tier Architecture is not MVC Architecture because no Model - View - Controller. Client-Tier has no
separation between User Interface, Presentation, or the View, and Functonal Logic, Data Access or the Model, and
no Controller.
This Client Architecture first used by PHP web scripting language, when no Cloud Computing. PHP was created in
1994 by Rasmus Lerdorf. JSP was created later by Sun Microsystems in 1998.
For web developers see JAVA difficulty, PHP is an alternative solution for their web development.
How stand-alone JSP Dynamic Web Application Works? Users open web browser, request JSP pages, such as, click on Login link or type: www.company.com/login.jsp, or
type: www.company.com/login, if the website mapped login.jsp into /login.
This login request is sent to Web Server. Then JSP, executed by web server, connect to database, get data,
manupulate data, calculate data.. Then sent HTTP response with data embedded in JSP webpage, back to users.
Just stand alone, JSP is a scripting language like PHP. It has extension jsp, such as, login.jsp like login.php.
JSP stand-lone works, executes, design web application just like PHP. But, JSP combined with other Technologies like
Java Bean or Java Class, Java Servlet, Enterprise Java, JSP will become a very powerful technology for
web application and enterprise web app that no one can compare.
See example code How-to Implement this Architecture provided below.
MVC Architecture.
MVC 3-Tier Architecture is about the separation between the GUI, Presentation, or
the View, and the Model = all about data , or the Business Logics,
Database Data Access ... The Controller receives input, HTTP request, and
manage, handle, direct inputs to the model, or the view for manipulate, execute, or
display. It acts like Head Office dispatcher traffic control, direct & manage congested traffics of user's inputs, requests to flow better. MVC Architecture made easy, not spaghetti code, and clear development for Enterprise Application Development, because its separation of concern between tier.
Modern Enterprise Java by design is for MVC. But you need to know How-to design, architect, and write code to make MVC work. Building few small scale website projects doesn't help, and see big differences. We write code, build large scale Cloud Enterprise Application, Cloud E-commerce Application, Cloud Database Application, Cloud POS Application, large scale E-Business Apps, larger scale powerful Business Website Application. => Then integrate all software All-in-One system so we can see differences.
MVC is no spaghetti design
MVC Benefits To design MVC, use Modern Enterprise Java. By design, Modern Enterprise Java is MVC, but
know How. Having MVC is better than no architecture, spaghetti.
- Separation of concerns between Developers:
Benefits for web development because different developer has different roles, such as, Front-end web developers,
like Web Content /Graphic Design, GUI/ Screen Web Designer, just focus on the design of the View. And the back-
end developers, Java Software Developers, database Developers, just focus on the Model, which is about data,
database development.
- Separation of concerns between Roles:
Benefits for making web application robust, solid, fast, resource efficiency, high performing, security ... For example,
- The View or web browser just focus on displaying/ rendering Data. Thus make Client or web browser thin
Client, fast like static Html page. No heavy lifting connect/ access database for the View.
- The Model: just focus on the Business Logics, the Data & Database, Model data. Such as, Get/ Save/ Update/
Insert Data. Retrieve Data, Manipulate data ... All about Data.
- The Controller: just focus on manage users request, user input, URL matching.., such as, when user click on
Login or user type www.compan.com/login... It acts like Head Office dispatch traffics controller. It directs &
manages congested traffics of user's request at website to flow better.
- Separation of concerns = Clear web development. We know which role to focus the web development.
- Easy support multi devices, since the View contains only data, just for display/ render data.
NOTE: JSP stand alone or Client Architecture doesn't have MVC. The Client or web browser does all tasks, all roles.
The Client is = the View, the Model, and the Controller. No separation of concerns. It is like one person who does
every task. Put too much pressure on the Client ( the web browser )
JSP + Java Bean - Model 1 Architecture JSP page calls a Bean component such as a JavaBean, and the bean will directly or indirectly access the database,
generally through JDBC. Data result embedded in JSP page, sent back to users.
The Bean or Java Bean is just a Java Class or Java Object, such as, login.java after compiled is login.class.
Java Bean class ( login.class) stored on Application Server like Tomcat in folder /WEB-INF/classes.
Java Bean is used for Business Logic, for access database, process data in
database, for all about data, model data ... In MVC Architecture ( Model View
Control) , Java Bean is the Model.
Model 1 Architecture = the Model ( the Bean ), the View ( JSP ). No Controller.
In this 2-Tier Architecture, Java Bean ( the Model ) is used for Business Logic, for connect, access to database...
The Bean is embedded to call in JSP page. There is no need to instance or create new object for Java Bean.
The Bean get data, process data, model data, then sent the result of data back in JSP page for presentation ( the
View ). In this Web Application 2-Tier Architecture has no Controller.
When PHP created in 1994, more than 22 years ago. JSP. Sun Microsystems created JSP, Servlet in 1998, 18 years
ago. Recently, Enterprise Java and 3-Tier Architecture, MVC is popular for Enterprise Solution.
See example code How-to Implement this Model 1 Architecture provided below.
JSP + Java Bean + Servlet - Model 2 Architecture
Model-View-Control of MVC Software Architect is popular, adapted by Software Developers to build their software
JSP + Java Bean. Model 1 Architecture. JSP page also call a bean component such as a JavaBean, and the bean will directly or indirectly access the database,
generally through JDBC.
Separation of Business Logic from Page Presentation -- Calling JavaBeans
We use Java Bean or Java Object to define business logic. In MVC Architecture, it is called Model.
JavaBeans is embedded in JSP page, that are invoked from the JSP page.
Java Bean or Bean is just a Java Class.
After compiled, it is a Java Class, such as, Admin.java -> Admin.class
In Application Server like Tomcat, Bean Class is stored in: /WEB-INF/classes or /WEB-INF/classes/db
JSP is stored in folder /ROOT/*jsp or /ROOT/app/*.jsp
we mapped http://localhost:8080/jsp/connect_bean.jsp into url = http://localhost:8080/jsp/connect_bean
NOTE: /jsp/ or any folder name like /app/ is ok. For example: http://localhost:8080/app/connect_bean
MVC 3-Tier Architecture - Enterprise Java:
Enterprise Java Cloud, and Enterprise JavaEE/J2EE
3-Tier MVC in Modern Enterprise Java Architecture, by design is MVC
Architecture, for Cloud Computing Web Application Development,
Software as a Service (SaaS)
Unlike JSP+JAVA BEAN + SERVLET is very much Web Application, Enterprise Java Cloud is by design is
Enterprise Java Application, large scale Java Development.
It is true MVC (Model-View-Control ) Architecture.
=> Compared to JSP + JAVA BEAN + SERVLET Web Application, this Enterprise Java Cloud is so much better,
advanced, efficient, robust, and enterprise for large scale Java Development.
Since it is better, efficient, robust, advanced, enterprise, this technology should be used to
replace the old JSP + JAVA BEAN + SERVLET Technology. Move forward to the better. Save Time & Money for Web Application, Cloud Software Development (SaaS).
It is light, fast, robust, and efficient. Good for Cloud.
It is Enterprise large scale Java development.
Modern Enterprise Java Cloud used Framework
For handling and managing database connectivity, database resource, connection pool, access database,
process data, security, POJO, and resources more efficient, more robust, more powerful, and reduce bugs.
It built in many components, APIs, Libs that helps reduce cost of software development.
Java Bean is replace by POJO ( Plain Old Java Object ). POJO includes different Java Components, such as,
DAO ( Data Access Object ), DM ( Domain or PD ), Impl for implement Interfaces.
Enterprise Java Cloud used Dependency Injection to insert POJO.
It has its own the Controller that is built-in mechanism to know how to direct & manage traffics of
users better ( Not Servlet Controller like JSP-JAVA BEAN-SERVLET Architecture ) => But you need to
know how to setup, and program the Controller to make it work. POJO is injected in Controller. POJO access database get data, manipulate data, return data.
JSP in Enterprise Java Cloud is used for just the View. It is just like a static HTML. No access database,
no database connectivity. No Java Bean (Java Object) embedded like Model 1 Architecture.
JSTL or JSP Standard Tag Library (JSTL) is used sometimes to process data.
Data is process by POJO, then send data to JSP page for displaying data, rendering data.
Data is put in Model used: ModelMap model ;
Such as: model.put ("customer", customer); = Put POJO Customer Data Object in Model.
model.put("lstProduct", lstProduct); = Put Array List of products in model data
Then the Model of Data is returned by ModelAndView() function API by:
return new ModelAndView ("ViewCustomerInvoiceData", "model", model);
where ViewCustomerInvoiceData.jsp is just a JSP page.
JSP in Modern Enterprise Java Cloud is used just for View only. No access
database. That's why the web browser run very fast, because its job just to display/ render data.
The Model or Plain Old Java Object ( POJO like Superman ) will do the heavy
lifting jobs like connect/ access, read data in database, and all about data.
MVC 3-Tier Architecture - JavaEE / J2EE This is heavy duty Enterprise Java supported by Oracle for big businesses, financial institutions, banks to implement
Web Application with Oracle back-end. Oracle is a relational database.
Relational Database Oracle is very popular used by big businesses, big corporation. Oracle is 160 Billions company,
its Oracle database is number 1 database used in today market.
However, Relational Database Oracle is not popular among Social Media companies, like Linked IN, because data
used by social media company format more like texture ( a lot of text, message, twitter feeds, video, images.. For
example, you can't store images, photos in Relational Table. ), document data, very different with Business
data like Customer, Invoice, Order, Product ....
Only Relational Data & SQL has JOIN, very powerful feature in database for get data and JOIN them
from different data point, data source. Other databases used by Social Media DON'T HAVE JOIN, DON'T
USE DATABASE SCHEME. DON'T USE RELATIONAL TABLE.
In JavaEE / J2EE, Oracle specification, you see code like:
In JavaEE/ J2EE, Servlet, JSP, Java Bean is used limited in Web Container.
In recently, Oracle release a new version of Enterprise Java JavaEE / J2EE.
1) The old J2EE deploys heavy Entity Beans for accessing database. While The new J2EE deploys Java Persistence Entity is a lightweight persistence domain object, to access data which is generalized to address issues of portability, faster, more efficient, more powerful handling & tracking & managing Cascade Parent - Child Relationship, complex Join Multi Relationship for Relational Database. - Before The new J2EE, there was no easy way to share data throughout the application. 2) In The new J2EE, Entity Bean can be effortlessly converted to DAO and vice versa. - This is not possible in The old J2EE. 3) The new J2EE has Dependency Injection. It performs better. It uses Java Object POJO. - The old J2EE does not implement POJO, and no DI. 4) The new J2EE elimination of Home interface (= Home and Object interfaces are no longer required – you need the Business Interface only) faster, lighter, more efficient. Gives simpler lookup process in The new J2EE than in The old J2EE. - The old J2EE is heavy when it comes to writing Home and Remote interfaces. 5) The new J2EE are faster than JNDI For reference of objects, deployed by The old J2EE. 6) The new J2EE simple POJO doesn’t need to execute container call back methods such as ejbActive, ejbStore .. which are used by The old J2EE. 7) The code is difference between two.
persistence.xml Persistence Unit used for Configure & Register Customer class, Order class & Oracle Database connectivity. <?xml version="1.0" encoding="UTF-8"?>
public long getCustomerId() { return customerId; } public void setCustomerId (long customerId) { this.customerId = customerId; } // getter and setter Order data for @OneToMany public List<Order> getOrders() { return orders; } public void setOrders (List<Order> orders) { this.orders = orders; } // ...more ... }
Example of public interface CustomerEjbDAOLocal.java import javax.ejb.Local; @Local public interface CustomerEjbDAOLocal { public void addCustomer(Customer customer); public void editCustomer(Customer customer); public void deleteCustomer( long CustomerId); public Customer getCustomer( long customerId); public List<Customer> getAllCustomers(); public void enterNewOrder (long customerId, Order newOrder); public void removeOrder(Order order); public List<Order> getOrdersById (long customerId); public void removeCustomer (long customerId); // .... more }
public void removeCustomer (long customerId) { Customer customer = em.find(Customer.class, customerId); if ( customer != null) em.remove(customer); } } @Override public void deleteCustomer (long customerId) { // Query query = em.createQuery("DELETE FROM Customer cust where cust.CustomerId = :id"); // query.setParameter("id", CustomerId).executeUpdate(); em.createNamedQuery ("Customer.deleteCustomer").setParameter("id", CustomerId).executeUpdate(); } @Override public Customer getCustomer (long customerId) { return em.find (Customer.class, customerId); } @Override public void removeCustomer (long customerId) { Customer customer = em.find(Customer.class, customerId); em.remove(customer); } @Override public List<Customer> getAllCustomers() { return em.createNamedQuery("Customer.getAllCustomer").getResultList(); } @Override public void removeOrder(Order order) { getOrders().remove(order); order.setCustomer(null); } @Override public void enterNewOrder (long customerId, Order newOrder) { Customer cust = em.find(Customer.class, customerId ); if ( cust != null ) { cust.getOrders().add(newOrder); newOrder.setCustomer(cust); } // .... more }
Summary Not including Java Bean, Servlet, Enterprise Java Cloud, JavaEE/J2EE,
just JSP alone is as powerful as PHP. Both scripting language, PHP is not JAVA.
However, for Cloud Computing Web Application, for Software as a Service
(SaaS), you should use Enterprise Java for large scale software development.
I explain different levels of Java Development from small scale to large scale:
- From JSP Client Architecture -> JSP + JAVA BEAN Model 1 Architecture -> JSP+JAVA BEAN+ SERVLET
Model 2 Architecture for Web App -> To Enterprise Java Application 3-Tier MVC.