! Introduction to J2EE (1) - J2EE Servlet/JSP/JDBC iseminar.. 1544-3355 ( ) iseminar Chat. 1
Who Are We? Business Solutions Consultant Oracle Application Server 10g Business Solutions Consultant Oracle10g 2
J2EE iseminar Series Agenda Day 1 J2EE Servlet JSP (JavaServer Pages) Day 2 Enterprise JavaBean Web Services J2EE 3
Java 2 Java 2 (J2SE) API J2EE J2SE Tools/Utilities/Deployment User Interface Kits (Swing, AWT) Core API s Integration API s J2SE Java Virtual Machine 4
Java 2 (J2EE) J2SE (Java 2 Standard Edition) API 5
J2EE Client Tier Web Tier Business Tier Enterprise Information System (EIS) Tier Web Browser Applets JSP Pages Servlets Enterprise JavaBeans Database and legacy systems Application Clients 6
Application Applet HTML Web Browser Applets Web Tier Business Tier EIS/Database Tier Application Clients 7
JSP (JavaServer Pages) (CSS, ) Client Tier JSP Pages Servlets Business Tier EIS/Database Tier 8
Enterprise JavaBeans (EJB) Client Tier Web Tier Enterprise JavaBeans EIS/Database Tier 9
J2EE J2EE J2EE Lifecycle 10
J2EE Client Machine J2EE Server Browser Servlets JSP Pages Application Client Application Client Container Web Container EJB EJB EJB Container Database 11
J2EE J2EE J2EE (deployment descriptor) 12
J2EE myj2eeapp.ear appclient.jar webapp.war ejb.jar applicationclient.xml web.xml ejb-jar.xml application.xml 13
D E M O N S T R A T I O N J2EE Application 14
J2EE Benefits, 15
J2EE iseminar Series Agenda J2EE Concepts Java 2 / J2EE Platform Architecture Benefits JSP (JavaServer Pages) 16
JSP - J2EE 17
API HTML ( ) XML, WML, GIF JSP (JavaServer Pages) public class HelloServlet extends HttpServlet { public void doget(httpservletrequest request, HttpServletResponse response) throws ServletException, IOException { PrintWriter out = response.getwriter(); out.setcontenttype( text/html ); out.println("<html><body>"); out.println( <h1>hello There!</h1>"); out.println("</body></html>"); out.close(); } 18
Http Client HttpServlet Request Response request ; response ; Session public class HelloServlet extends HttpServlet { public void doget(httpservletrequest request, HttpServletResponse response) throws ServletException, IOException { PrintWriter out = response.getwriter(); out.setcontenttype("text/html"); out.println("<html><body>"); out.println("<h1>hello "+request.getparameter("name")+"</h1>"); out.println("</body></html>"); out.close(); } 19
(Life Cycle) 1 2 3 Load Initialize Server Operations Client (Browser) Requests 0 N Destroy 4 20
JSP (JavaServer Pages) HTML cf. HTML <HTML> <BODY> <P>Hello! <BR> Today is: <%= new java.util.date() %> </BODY> </HTML> 21
JavaServer Pages JSP Scriptlets <% %> Directives <%@... %> Expressions <%= %> Declarations <%! %> <jsp:usebean />, <jsp:setproperty />... JSP HTML 22
D E M O N S T R A T I O N Java Servlets and JavaServer Pages (JSP) 23
Agenda J2EE Servlet JSP (JavaServer Pages) JDBC SQL PL/SQL Java Stored Procedures 24
JDBC JDBC JDBC calls Driver Database commands Database Database java.sql javax.sql JDBC 25
JDBC URL Thin driver: jdbc:oracle:thin:@<host>:<port>:<sid> jdbc:oracle:thin:@dbdev.acme.com:1521:orcl OCI driver: jdbc:oracle:oci:@<tnsnames entry> jdbc:oracle:oci:@dbdev Server-Side internal driver: jdbc:oracle:kprb: 26
JNDI DB URL flexible, portable JNDI API J2EE LDAP CORBA/COS RMI DNS File System JNDI Lookup JDBC Connection Database Context ctx = new InitialContext(); OracleDataSource ods = (OracleDataSource)ctx.lookup("jdbc/TestDB"); Connection conn = ods.getconnection(); 27
connection Stateless PooledConnection PooledConnection JDBC Connection Database PooledConnection 28
Connect Issue statement Process results Close DriverManager.registerDriver (new oracle.jdbc.oracledriver()); Connection conn = DriverManager.getConnection ("jdbc:oracle:thin:@myhost:1521:orcl", scott","tiger"); Statement stmt = conn.createstatement(); ResultSet rset = stmt.executequery ("SELECT employee_id, last_name FROM employees"); while (rset.next()) { } int empid = rset.getint("employee_id"); String empname = rset.getstring("last_name"); System.out.println(empId + : + empname); rset.close(); stmt.close(); conn.close(); 29
: PreparedStatement 1. : (? ) 2. value 3. Statement int empid = 101; PreparedStatement pstmt = conn.preparestatement("update employees SET job_title =? WHERE employee_id =? "); pstmt.setstring(1, "Sales Rep"); pstmt.setint(2, empid); pstmt.executeupdate(); 30
PL/SQL : CallableStatement 1. : (? ) 2. Output 3. Input 4. Statement 5. CallableStatement cstmt = conn.preparecall("{call? := MYFUNC(?)}"); cstmt.registeroutparameter(1, Types.VARCHAR); cstmt.setint(2, 1001); cstmt.execute(); var = cstmt.getstring(1); 31
PL/SQL : CallableStatement 1. : (? ) 2. Output 3. Input 4. Statement 5. CallableStatement cstmt = conn.preparecall("{call? := MYFUNC(?)}"); cstmt.registeroutparameter(1, Types.VARCHAR); cstmt.setint(2, 1001); cstmt.execute(); var = cstmt.getstring(1); 32
Java Stored Procedures stored procedure PL/SQL stored procedure 33
D E M O N S T R A T I O N JDBC 34
Enterprise JavaBeans CMP JavaServer Pages J2EE (ADF ) TopLink JPublisher JDBC JNDI,, 35
Summary J2EE Servlets J2EE JSP JDBC SQL PL/SQL Java Stored Procedure 36
For More Information http://launch.oracle.com PIN: 7505395, http://java.sun.com/j2ee, API Documentation http://otn.oracle.com/sample_code http://otn.oracle.com/tech/java/java_db, Documentation Discussion Forum 37
J2EE iseminar Series Agenda Day 1 J2EE Servlet JSP (JavaServer Pages) Day 2 Enterprise JavaBean Web Services J2EE 38
Q U E S T I O N S A N S W E R S 39
otn.oracle.com, otn.oracle.co.kr Join Over 3,000,000 Developers! Free Technical Advice Free Software Downloads otn.oracle.com/tech/java, otn.oracle.co.kr/tech/java 40