1 / 30

Java Web应用开发:J2EE和Tomcat

蔡 剑 , Ph.D. Java Web应用开发:J2EE和Tomcat. 本讲内容. EJB 层技术 ( II) Transaction and Security Resource Connection Deployment Web Services. RDMS. JDBC. Web Container. JSPs. ( X)HTML XML. Servlets. HTTP. JSTL. JavaMail. Mail Server. J2EE Application Server. JAX RPC. Mgmt. Java

valmai
Download Presentation

Java Web应用开发:J2EE和Tomcat

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 蔡 剑, Ph.D. Java Web应用开发:J2EE和Tomcat

  2. 本讲内容 • EJB层技术 (II) • Transaction and Security • Resource Connection • Deployment • Web Services

  3. RDMS JDBC Web Container JSPs (X)HTML XML Servlets HTTP JSTL JavaMail Mail Server J2EE Application Server JAX RPC Mgmt Java Application RMI JAXR JACC JNDI JDBC JMS JAF JTA Applet SAAJ JMX CORBA Server IIOP EJB Container Application Client Container Message Beans Session Beans Entity Beans Client Application Directory Service JNDI JAX RPC Mgmt JMS JAX RPC Mgmt Message Queue JAXR JACC JNDI JDBC JMS JAF JTA JAXR JMS SAAJ JMX SAAJ JMX Review: J2EE Framework

  4. Model • Encapsulates application state • Responds to state queries • Exposes application functionality • Notifies views of changes State Change State Query Change Notice • View • Renders the models • Request updates from models • Sends user gestures to Controller • Allows controller to select View • Controller • Define application behavior • Maps user actions to model updates • Select view for response • One for each functionality View Selection User gestures Web Application Architecture: MVC Model

  5. Transaction Concept begin transaction debit checking account credit savings account update history log commit transaction

  6. CMT Transaction Management public void transferToSaving(double amount) throws InsufficientBalanceException { checkingBalance -= amount; savingBalance += amount; try { updateChecking(checkingBalance); if (checkingBalance < 0.00) { context.setRollbackOnly(); throw new InsufficientBalanceException(); } updateSaving(savingBalance); } catch (SQLException ex) { throw new EJBException ("Transaction failed due to SQLException: " + ex.getMessage()); } }

  7. BMT Transaction Management : JDBC public void ship (String productId, String orderId, int quantity) { try { con.setAutoCommit(false); updateOrderItem(productId, orderId); updateInventory(productId, quantity); con.commit(); } catch (Exception ex) { try { con.rollback(); throw new EJBException("Transaction failed: " + ex.getMessage()); } catch (SQLException sqx) { throw new EJBException("Rollback failed: " + sqx.getMessage()); } } }

  8. BMT Transaction Management : JTA public void withdrawCash(double amount) { UserTransaction ut = context.getUserTransaction(); try { ut.begin(); updateChecking(amount); machineBalance -= amount; insertMachine(machineBalance); ut.commit(); } catch (Exception ex) { try { ut.rollback(); } catch (SystemException syex) { throw new EJBException ("Rollback failed: " + syex.getMessage()); } throw new EJBException ("Transaction failed: " + ex.getMessage()); }

  9. Transaction Allowance

  10. Updating Multiple Databases

  11. Resource Connections

  12. Database Connection   private String dbName    = "java:comp/env/jdbc/SavingsAccountDB";   InitialContext ic = new InitialContext();   DataSource ds = (DataSource) ic.lookup(dbName);   Connection con = ds.getConnection();

  13. EJB Deployment: Security Declare

  14. Programmatic Security in the EJB Tier public String getUser() { return context.getCallerPrincipal().getName(); } boolean result = context.isCallerInRole("Customer");

  15. Propagating Security Identity

  16. Web Deployment: Security Declare

  17. Packaging Modules • EJB模块,其包含ejb文件及相应类 • Web模块,其包含网络层的组件及资源 • 应用客户模块,其包含应用客户类 • 资源适配器模块,其包含java连接器(connector),资源适配器,和帮助库函数及相关资源。

  18. Deployment Configuration Files • EJB 部署描述文件 • 网络层部署描述文件 web.xml • 应用客户部署描述文件 • 资源适配器部署描述文件

  19. EJB Deployment: Packaging

  20. EJB and Web Services J2EE1.4 Web Services SOAP EJB2.1 Container Stateless Session Bean SOAP .Net Web Services SOAP Perl Web Services

  21. Web Services

  22. Web Services Support • Web services are Web-based enterprise applications that use open, Extensible Markup Language (XML)-based standards and transport protocols to exchange data with calling clients. • The J2EE platform provides the XML APIs and tools you need to quickly design, develop, test, and deploy Web services and clients that fully interoperate with other Web services and clients running on Java-based or non-Java-based platforms. • It is easy to write Web services and clients with the J2EE XML APIs. No low-level programming is needed because the XML API implementations do the work of translating the application data to and from an XML-based data stream that is sent over the standardized XML-based transport protocols. • The translation of data to a standardized XML-based data stream is what makes Web services and clients written with the J2EE XML APIs fully interoperable.

  23. Web Services Concept

  24. Web Services

  25. Web Services Standards

  26. Three Players of WS

  27. SOAP

  28. UDDI

  29. WSDL

  30. J2EE Web Services

More Related