Sunteți pe pagina 1din 12

JSP and Servlets in J2EE

Danny Coward Java Servlet specification lead, Sun Microsystems


Slide 1

Agenda
" The

role of JSPs and Servlets in the J2EE platform " Why and when to use JSPs and Servlets in J2EE platform " A particular example " Conclusion

Sun Microsystems Inc

Slide 2

Multi-Tiered Enteprise Apps


Browser Pure HTML Application XML JSP Java Application EJB Enterprise Information Systems EJB EJB

J2EE Platform Web Server Servlet

Sun Microsystems Inc

Slide 3

Web Components in J2EE


" Web Components form the window to J2EE " Allows web layer to focus on what its good

at - presentation " Allows reuse of business logic elsewhere " Allows scalability

Sun Microsystems Inc

Slide 4

J2EE Services
" Security " Naming " Database " Transactions " Enterprise Java " JavaMail

Beans (EJB)

Sun Microsystems Inc

Slide 5

Migrate or not ?
" If

you want to make your business logic re-usable to other parts of the organisation " If you want to take advantage of a secure, robust, transactional infrastructure " If you want to connect into an interoperable environment and access Information Systems

Sun Microsystems Inc

Slide 6

How to Migrate
" Separate semantics within a web application " Use JSP and Servlet components as

presentation layer for data " Move business logic out of web components into separate components e.g. Tag Libraries " Migrate business logic to EJB

Sun Microsystems Inc

Slide 7

Interaction with EJB: Example


" Example: Online music store " Web front end, with functionality
" Browse " Sign

to:-

catalog

in purchases using 'shopping cart'

" Make

Sun Microsystems Inc

Slide 8

Example application contents:" Web Layer:" Static content " Catalog browsing JSPs " Checkout form Servlet " EJB layer " Catalog entity bean " Shopping cart session " Account entity bean
"

bean

Sun Microsystems Inc

Slide 9

Code example: Checkout Servlet


import javax.naming.*; // create JNDI initial context Context context = new InitialContext(); // lookup EJB Home Object objref = context.lookup("java:comp/env/AccountEJB"); HelloHome hello = PortableRemoteObject.narrow(objref, HelloHome.class); Hello ejb = hello.create(); servletOutput.println("<bold>You ordered " + ejb.getOrderCount() + " CDs today.</bold>");
Sun Microsystems Inc Slide 10

Resources
" www.java.sun.com/j2ee " J2EE Reference Implementation
" Samples

" APM
" Best

practices document application

" Example

Sun Microsystems Inc

Slide 11

Summary

" The

web layer is the window into J2EE

Sun Microsystems Inc

Slide 12

S-ar putea să vă placă și