Creating Web Application with BEA WebLogic Workshop. Jeff (Yefim) Zhuk

Similar documents
Data Service Patterns Jeff Zhuk

Writing Servlets and JSPs p. 1 Writing a Servlet p. 1 Writing a JSP p. 7 Compiling a Servlet p. 10 Packaging Servlets and JSPs p.

From the book. Integration-Ready Architecture and Design. Cambridge University Press

JDBC [Java DataBase Connectivity]

JavaEE Interview Prep

Struts interview questions

Java Technologies Resources and JNDI

Java EE Application Assembly & Deployment Packaging Applications, Java EE modules. Model View Controller (MVC)2 Architecture & Packaging EJB Module

Oracle Retail Accelerators for WebLogic Server 11g

web.xml Deployment Descriptor Elements

Prototype 1.0 Specification

This course is intended for Java programmers who wish to write programs using many of the advanced Java features.

BEAWebLogic. Portal. White Paper: Content Personalization. Version 8.1 Document Revised: May 2004 By: Greg Smith

Author - Ashfaque Ahmed

Welcome To PhillyJUG. 6:30-7:00 pm - Network, eat, find a seat 7:00-7:15 pm - Brief announcements 7:15-8:30 pm - Tom Janofsky's presentation

WHAT IS EJB. Security. life cycle management.

AquaLogic BPM Enterprise Configuration Guide

Oracle Entitlements Server 11gR2 Integration Guide Published: May 2013

BEAWebLogic. Portal. Tutorials Getting Started with WebLogic Portal

Advance Java. Configuring and Getting Servlet Init Parameters per servlet

MVC, 2. MVC

J2EE Development. Course Detail: Audience. Duration. Course Abstract. Course Objectives. Course Topics. Class Format.

Refactoring to Seam. NetBeans. Brian Leonard Sun Microsystems, Inc. 14o

Advanced Web Technology - Java Server Faces

Contents. 1. JSF overview. 2. JSF example

ive JAVA EE C u r r i c u l u m

Building Web Applications With The Struts Framework

CS506 Web Design & Development Final Term Solved MCQs with Reference

Application Development in JAVA. Data Types, Variable, Comments & Operators. Part I: Core Java (J2SE) Getting Started

Struts Lab 3: Creating the View

Lab1: Stateless Session Bean for Registration Fee Calculation

Fast Track to Java EE 5 with Servlets, JSP & JDBC

JSP. Common patterns

The Struts MVC Design. Sample Content

Vendor: SUN. Exam Code: Exam Name: Sun Certified Web Component Developer for J2EE 5. Version: Demo

Web Applications. and. Struts 2

Lab2: CMP Entity Bean working with Session Bean

Module 3 Web Component

Fast Track to Java EE

Jakarta Struts: An MVC Framework

Tutorial: Developing a Simple Hello World Portlet

Questions and Answers

Server Extensions Developer Guide

Readme File. Hyperion System 9 BI+ Application Builder.NET Release 9.2 Readme. Hyperion System 9 BI+ Application Builder.NET Release 9.

Application Development Issues. Overview: Velocity: what is it, what is it good for? Part 1: Code Generators Part 2: Web Applications With Velocity

COURSE DETAILS: CORE AND ADVANCE JAVA Core Java

OES Permission Checks in ADF Task Flows

Copyright. Restricted Rights Legend. Trademarks or Service Marks. Copyright 2003 BEA Systems, Inc. All Rights Reserved.

Enterprise Java Technologies (Part 1 of 3) Component Architecture. Overview of Java EE. Java Servlets

Chapter 1. JOnAS and JMX, registering and manipulating MBeans

Perceptive Interact for Salesforce Enterprise

Enhydra 6.2 Application Architecture. Tanja Jovanovic

CIS 764 Tutorial: Log-in Application

ADVANCED JAVA COURSE CURRICULUM

Java.. servlets and. murach's TRAINING & REFERENCE 2ND EDITION. Joel Murach Andrea Steelman. IlB MIKE MURACH & ASSOCIATES, INC.

CSE 510 Web Data Engineering

Struts. P. O. Box Austin, TX Fax: +1 (801) (877) 866-JAVA

Oracle 10g: Build J2EE Applications

Rational Application Developer 7 Bootcamp

Jakarta Struts: Declarative Exception Handling

OIG 11G R2 Field Enablement Training

Introduction... xv SECTION 1: DEVELOPING DESKTOP APPLICATIONS USING JAVA Chapter 1: Getting Started with Java... 1

SAS AppDev Studio TM 3.4 Eclipse Plug-ins. Migration Guide

How to Publish Any NetBeans Web App

JSF Tools Reference Guide. Version: M5

Perceptive Interact for Salesforce Enterprise

Three hours UNIVERSITY OF MANCHESTER SCHOOL OF COMPUTER SCIENCE. Date: Friday 21 st May Time:

KonaKart Portlet Installation for Liferay. 2 nd January DS Data Systems (UK) Ltd., 9 Little Meadow Loughton, Milton Keynes Bucks MK5 8EH UK

LTBP INDUSTRIAL TRAINING INSTITUTE

Oracle 1Z Java EE 6 Web Component Developer(R) Certified Expert.

BEA WebLogic. Server. MedRec Clustering Tutorial

PES INSTITUTE OF TECHNOLOGY, SOUTH CAMPUS DEPARTMENT OF MCA INTERNAL TEST (SCHEME AND SOLUTION) II

Appendix C WORKSHOP. SYS-ED/ Computer Education Techniques, Inc.

Apcoordinator User's Guide J2X ENZ2(00)

IBM Operational Decision Manager Version 8 Release 5. Configuring Operational Decision Manager on WebLogic

Setting Up the Development Environment

Page 1

NetBeans IDE Field Guide

Wiring Your Web Application with Open Source Java

Supplement IV.E: Tutorial for Tomcat For Introduction to Java Programming By Y. Daniel Liang

Session 8. JavaBeans. Reading & Reference. Reading. Reference. Session 8 Java Beans. 2/27/2013 Robert Kelly, Head First Chapter 3 (MVC)

Learning vrealize Orchestrator in action V M U G L A B

Creating Domain Templates Using the Domain Template Builder 11g Release 1 (10.3.6)

1. Configuring Azure and EBP for a simple demo

JAVA SYLLABUS FOR 6 MONTHS

Tutorial: Using Java/JSP to Write a Web API

Table of Contents. Introduction... xxi

Backend. (Very) Simple server examples

CSC 8205 Advanced Java

PSD1B Advance Java Programming Unit : I-V. PSD1B- Advance Java Programming

Advanced Topics in Operating Systems. Manual for Lab Practices. Enterprise JavaBeans

Web Application Architecture (based J2EE 1.4 Tutorial)

Perceptive Nolij Web. Administrator Guide. Version: 6.8.x

A JavaBean is a class file that stores Java code for a JSP

IT6503 WEB PROGRAMMING. Unit-I

Attunity Connect and BEA WebLogic (Version 8.1)

OSCAR Documentation ) Developers For developer registration the java and jsp files involved are the following

CodeCharge Studio Java Deployment Guide Table of contents

The team that wrote this redbook

Sun Sun Certified Web Component Developer for J2EE 5 Version 4.0

Transcription:

Creating Web Application with BEA WebLogic Workshop Jeff (Yefim) Zhuk author of the book Integration-Ready Architecture and Design by Cambridge University Press Software Engineering With XML, Java,.NET, Wireless, Speech and Knowledge Technologies

Creating Web Application with BEA WebLogic Workshop Reusable solutions for Data Intensive Web Applications Using BEA WebLogic Workshop 8.1 Use Page Flow Facilities Provide Java code in the LoginController and Login Bean classes Add configuration facilities Build and Run

e-business e-government e-training Login Common Use Cases Policy Maker Admin Change Business Rules Change User Roles Access Rules: Accessibility Single Sign-On Role based Access User Privacy Control Device Independence User Registrar Registration Recognize Common Problems and Use Design Patterns Member Customize Search Content Management Knowledgebase User Profile Content Management Authoring, Update, Versioning Forms, Permits, Applications Scheduling events/facilities Workflow Routing Planning and Approval Document/Photo Imaging Task Tracking and Reporting Data and Service Evaluation Collaboration Collaboration Email Conferencing Instant Messaging Privilege-based Data/Service Sharing Search Search for Data and Services GIS (Maps and Routes) Linking Related Cases Content-based Subscription

Struts-config.xml Action-JSP map Client(s) Web Browser Http Post/Get Data Intensive Web Application Submit Form Display Page Web Tier Generic Data Action Extract business data Receive the Forward value and map to a JSP Web Tier JSPs (Forms) App Sever A set of Specific Actions use DataService to execute dynamic queries and provide object processing PooledConnection Create Select Update Insert Delete Database Read SQL and replace variables with field values from a form The DataAction alone with the DataService implement common functions and provide generic application behavior. SQL Statement Resources

Sequence Diagram DataAction Specific Service Action DataService Client Events/Operations Http Post/Get Extract data from the page and call a proper service Request SQL execution with SQL statement name and map of parameters Specific processing; Work with objects and prepare data for JSP Pass data saved in data beans, Session, or Request objects to JSP Generic data processing: Retrieve SQL from resources; Replace run-time variables; Execute SQL, process ResultSet (if any) and return a list of object-beans Map the Forward value to a proper JSP (via Struts-config.xml) and display the next JSP page

HTTPServlet Action OMD DataAction keys: HashMap execute() abstract perform() SpecificAction1 SpecificAction2 specificdata specificdata perform() perform() Uses DataService DataSource getdata(sqlname, map, bean.class) : List setdata(sqlname, map) setdatasource(ds)

Generic DataAction Code public class DataAction extends Action { private static Logger log = Logger.getLogger("DataAction"); protected HashMap keys; public ActionForward execute(actionmapping map,.) { // generic code in the execute() method String forwardto = null; keys = preparekeys(request); // capture form and other key data try { // perform specific action implemented in a subclass forwardto = perform(request); catch(exception e) { log.severe(getclass().getname() + " e="+e); // prepare message for a generic error page request.setattribute("msg", e.getmessage()); throw e; forward = map.findforward(forwardto); // ActionMapping map return (forward); public String perform(httpservletrequest request) throws Exception { return null;

Specific Action Implementation public class LoginAction extends DataAction { public String perform(httpservletrequest request) throws Exception { List beans = DataService.getData("getLogin", keys, LoginBean.class); if(beans.size() == 1) { // SUCCESS! //Create instance of SessionBean and bind it to session SessionBean sessionbean = new SessionBean(); LoginBean bean = (LoginBean) beans.get(0); sessionbean.setusername(bean.getloginname()); session.setattribute( sessionbean, sessionbean); return success ;. return failure ;

Start a New Project in SampleApp area File Open Open Application: /bea/weblogic81/samples/ workshop/sampleapp Then right-mouse-click on the SampleApp New Project Enter: WebExample

Start a New Page Flow 1 3 2 One two three and bingo, You created a starting point! Do not forget to name this page flow in the step 2.

Flow View and Action View

Source View /** * @jpf:controller * @jpf:view-properties view-properties:: * <view-properties> * :: */ public class LoginController extends PageFlowController { /** * This method represents the point of entry into the pageflow * @jpf:action * @jpf:forward name="success" path="index.jsp" */ protected Forward begin() { return new Forward("success");

Create a Form and a FormBean 2. Provide the action name for the form as checklogin and press the NEW button to create a new form. WebLogic creates CheckLoginForm bean that will store properties (values) of the new form. 1. Double-click on the index.jsp file Set the Design View and find the Form in the Palette on the left pane. Drag-n-drop the form in the page on the right Provide two names for the properties: loginname and password and press OK. You created a form and a supporting form bean. 3. Double-click on the LoginController and check Flow View, Action View, and Source View.

Customize Your Action You will instruct the checklogin() method to pass control to the welcome.jsp page in the case of success or back to the index.jsp in the case of failure. Enter two new lines in the header of the checklogin() method: /** * @jpf:action * @jpf:forward name= success" path="welcome.jsp" * @jpf:forward name= failure" path="index.jsp" */ protected Forward checklogin(checkloginform form) { return new Forward("success");

Re-arrange the Flow View Drag-n-drop the checklogin and the welcome.jsp icons to clarify the Flow View. Then with right-mouse click create the welcome.jsp page.

Add Jar files to the Application Build Facilities

Import Extra Libraries to WEB-INF/lib

Create the Login Bean Class 1. Right-mouse click on the project and create NEW FOLDER beans 2. Right-mouse click on the beans folder and create NEW JAVA CLASS 3. Name it Login

package beans; LoginBean Class Example import java.util.hashmap; import java.util.logging.logger; /** * The LoginBean class matches the record selected by the getlogin.sql */ public class LoginBean { private String loginname; private String password; // add getter and setter methods for data members above!!! public String getloginname() { return loginname; // TODO more getter and setter methods

The CheckLogin() Method in the LoginController /** * @jpf:action * @jpf:forward name="success" path="welcome.jsp" * @jpf:forward name="failure" path="index.jsp" * Note, that the data access is performed with the DataService.getData() that * uses the SQL statement-file getlogin.sql stored in the sqllocation */ protected Forward checklogin(checkloginform form) { HashMap keys = new HashMap(); keys.put("loginname", form.getloginname()); keys.put("password", form.getpassword()); List logins = DataService.getData("getLogin", keys, LoginBean.class); String result = "failure"; if(logins!= null && logins.size() == 1) { result = "success"; getsession().setattribute("result", result); return new Forward(result);

Example of Using the Session in the JSP Add the scriplet to the index.jsp <body> <p> <% String result = (String) session.getattribute("result"); if(result!= null && result.equals("failure")) { out.println("please try again"); else { out.println("enter your login name and password"); %> <netui:form action="checklogin"> <table> <tr> <td colspan="2" align="center"> </td> </tr> <tr valign="top"> <td>login Name:</td>

Build and Debug 1. Right-mouse click on the project and select the Build your project option Watch for the output in the Build console at the bottom right 2. Right-click on the Controller and select DEBUG START from the menu See logger output in the main console (find it in the MS DOS window)

ServletContextListener Reads Config public class MyServletContextListener implements ServletContextListener { public void contextinitialized(servletcontextevent sce) { ServletContext servletcontext = sce.getservletcontext(); String sqllocation = servletcontext.getinitparameter( sqllocation"); String jndiname = "java:"+servletcontext.getinitparameter("datasource"); InitialContext context = new InitialContext(); DataSource datasource = (DataSource)context.lookup(jndiName); com.its.util.dataservice.setsqllocation(sqllocation); com.its.util.dataservice.setdatasource(datasource); public void contextdestroyed(servletcontextevent sce) { ---------------------------------------------------- WEB.XML ---------------------------------- <listener> <listener-class>com.its.actions.myservletcontextlistener</listener-class> </listener> <context-param> <param-name>sqllocation</param-name> <param-value>sql</param-value> </context-param> <context-param> <param-name>datasource</param-name> <param-value>specificdatasourcenameprovidedinjboss_ds_file</param-value> </context-param>

Then add the <context-param> entries with DataSource, etc. Configure the Application via web.xml Find the configuration file wml.xml in the WEB-INF directory, edit the <listener> entry.

Install WebLogic Workshop Build your Web Application using the last section material Build the Login page according to the section material Add Product and Registration pages Prepare SQL statements for existing data and store as files in the sqllocation that is set in the web.xml and MyServletContectListener (No SQL is needed if application creates data from scratch) Create bean classes like the LoginBean that support data structures used with data access and in the forms. Create the LoginController with the checklogin() method. Note, that the data access in the controller is performed with the DataService.getData() method that uses the SQL statement-file getlogin.sql stored in the sqllocation Prepare HashMap to replace SQL <<keys>> with run-time values

DataService API Include the library com.its.util.jar in the CLASSPATH and import com.its.util.dataservice @param directoryname to set the location where your SQL statement files are stored public static void setsqllocation(string directoryname) @param drivername your jdbc driver name public static void setdrivername(string drivername) @param set Connection URL for database access public static void setconurl(string connectionurl) // execute insert/delete/update SQL statements stored in the sqllocation @ param sqlstatementname for example getlogin stored as the getlogin.sql @ param map of key-values to replace SQL <<keys>> with run-time values @ return numberofrowseffected public static int setdata(string sqlstatementname, HashMap map) @ param sqlstatementname for example getlogin stored as the getlogin.sql @ param map of key-values to replace SQL <<keys>> with run-time values @ param beanclass (e.g. LoginBean.class) supports records retrieved by the SQL statement @ return list of objects of the beanclass public static List getdata(string sqlstatementname, HashMap map, Class beanclass) @param datasource your DataSource specified in JNDI context public static void setdatasource(datasource datasource)

DataService Usage Example // set DataService env variables in the initialization procedure (MyServletContextListener) DataService.setDataSource(DataSource ds); // use JNDI to get DataSource DataService.setSqlLocation(sqlLocation); //dsname and sqllocation from web.xml // This code belongs to the LoginController in the WebLogic example by JZ HashMap map = new HashMap(); // map to replace run-time variables in SQL map.put("loginname", form.getloginname()); map.put("password", form.getpassword()); List users = DataService.getData("getLogin", map, LoginBean.class); If(users!= null && users.size() == 1) { // success // successful login // Prepare SQL statements and store them in the sqllocation // /WEB-INF/sql/getLogin.sql select statement to check login // Note that run-time variable names are in the tags <<.. >> or follow the : character select username, password from LoginTable where username = '<<loginname>>' and password = '<<password>>' // Alternative to specify replacement keys is the ":" character select username, password from LoginTable where username = ':loginname' and password = ':password'

More DataService API // If application creates data from scratch less or no SQL is needed // SQL is created on-the-fly by DataService implementation boolean createtable(string tablename, Class class) Example: DataService.createTable( LoginTable, LoginBean.class); int insert(string tablename, Object[] objects) Example: LoginBean[] logins; // array of beans populated in an action int nrows = DataService.insert( LoginBean, logins);