CIS 764 Tutorial: Log-in Application - People

2y ago
35 Views
2 Downloads
771.73 KB
25 Pages
Last View : 16d ago
Last Download : 2m ago
Upload by : Milena Petrie
Transcription

CIS 764 Tutorial: Log-in ApplicationJavier Ramos RodriguezPurposeThis tutorial shows you how to create a small web application that checks theuser name and password.OverviewThis tutorial will show how to use the EJB 3.0 specification and the Java ServerFaces (JSF) in Jdeveloper. We will show that JSF are very useful to validate theinputs.ScenarioIn this tutorial we’ll create a persistence object Student from a table STUDENT.We will create a session bean to manage the entity object (entity bean) andwe’ll use JSF as View-Controller.PrerequisitesYou’ll need to have access to an Oracle Database and the Jdeveloper 10g IDE.You also need a connection to the database.1

Step 1. Creating the STUDENT table.1. Open the Jdeveloper and on the navigator select connections. Then, goto the Oracle database connection and right-click on SQLworksheet.2. In the SQL worksheet window, copy and paste this SQL code:create table STUDENT ( login varchar2(50) primary key,passwd varchar2(50) NOT NULL, name varchar2(90) NOTNULL, email varchar2(90) NOT NULL);2

3. Click on the “Execute SQL Statement” button and the query will beexecuted.Step 2. Configuring the ApplicationIn this section we will create the persistence object using entity beans.1. In JDeveloper, click the Applications tab. In the Applications navigator,right-click Applications and select New Application from the shortcutmenu.3

2. In the Create Application dialog box, enter JSFLoginTutorial as theapplication name, and select the JSF, JSP, EJB template option. ClickOK.4

3. In the JSFLoginTutorial application, right-click in ViewController projectand then click on properties.4. Choose Dependences tab and click on the Model.5

6

Step 3. Creating the Persistence Model1. In the Applications navigator, right-click the JSFLoginTutorial node andchoose the New option.2. In the New Gallery dialog box, expand the Business Tier node inCategories. In the Items list, select CMP Entity Beans from tables.Click OK.7

3. Click Next on the Welcome page of the "Create CMP Entity Beans fromTables" wizard. In Step 1 of 5, select the Enterprise JavaBeans 3.0(J2EE 5.0) option, and then click Next.4. In Step 2 of 5, select the Oracle connection as the connection name.8

5. In step 3 of 5, click the Query button, and then select the STUDENTtable from the Available list and shuttle them to the Selected list. ClickNext.6. In step 4 of 5, enter model as the package name. Click Next.9

7. Click Next in step 5 of 5 and then Finish to create the entity beans.10

Step 4. Creating the Business Model1. Right-click the JSFLoginTutorial project node in the Applicationsnavigator and select the New option from the context menu. Open theBusiness Tier category and choose the Session Bean item. Click OK.11

2. Click Next on the Welcome page of the Create Enterprise JavaBeanwizard. In step 1 of 3, enter StudentSessionEJB as the EJB name.Leave the options unchanged, and then click Next.3. Leave everything unchanged in steps 2 and 3 and click Finish.12

4. Open the StudentSessionEJB file in the navigator and add the nextmethod.public boolean checkLogin(String login, String passwd)throws NamingException {return getEntityManager().createQuery("select object(o) from Student o where((o.login LIKE :login) AND (o.passwd LIKE :passwd))").setParameter("login", ().isEmpty();}This will query the database to check if the login and password given by theuser are in the database.5. Open the StudentSessionEJB interface and add the methodsdeclarations.boolean checkLogin(String login, String password) throwsNamingException;13

6. Right-click in StudentSessionEJBBean and click on New Sample JavaClient.14

7. In Client Class name write model.ModelFacade and click ok.8. Delete the main method and create the next method that is going tocheck if the login and password are stored in the database.public boolean checkLogin(String login, String password) {boolean check true;try {final Context context getInitialContext();StudentFacade studentFacade (StudentFacade) context.lookup("StudentFacade");check studentFacade.checkLogin(login, password);// true empty resutls} catch (NamingException e) {e.printStackTrace();}return !check;}15

Step 5. Create the Control-Flow Diagram1. In the application navigator, select the ViewController project and in theWenContent\WEB INF folder open the faces-config.xml file.2. In the editor, drag and drop a JSF page from the component palette.Change the name to login.jsp. Then, drag and drop another JSF page tothe diagram and change the name to main.jsp. Finally, drag and dropthe JSF Navigation Case component from the palette and connect thelogin.jsp page to the main.jsp page. Change the name to go main.16

Step 6. Create the JSF pages.1. Double-click in the login.jsp page in the diagram. The Create JSF JSPWizard Welcome screen displays. Click Next to continue. In step 1,leave everything unchanged.2. In Step 2, choose Automatically Bind Components Using a NewlyCreated Managed Bean.17

3. In Step 3, Choose not to use error page.4. In Step 4, choose the default libraries, JSF Core and JSF HTML.18

5. In Step 5, Choose the page title. Click next and then finish.19

Step 7. Edit the JSP page.1. The JSP editor will appear. In the top of the page enter some text:Welcome. Format the text to H1 by clicking the left-hand dropdown list atthe top of the Visual Editor, and choosing Heading 1. Then, apply a CSSstyle sheet. Select the CSS page in the Components section in the topright of your screen. Then drag the JDeveloper style sheet onto your newJSP. You should see an immediate change in the appearance of youpage.2. In the Component palette choose JSF HTML and click on Panel Grid.In the new window choose 2 in number of columns and click finish.20

3. Now drag and drop the next components one after the other as show inthe figure: OutputLabel, InputText, OutputLabel, InputSecret,CommandButton and Messages.4. Change the outputLabel1 name to Login and the outputLabel2 name toPassword. Also, change the commandButton name to Submit, to dothis go to the property inspector window and change the value label.21

Step 8. Implementing the behavior1. Double click in the Submit button. The Login.java file will open to edit theaction. Copy and paste the next code:public String commandButton1 action() {boolean check false;Stringmessage new String();Stringlogin inputText1.getValue().toString();Stringpasswd inputSecret1.getValue().toString();if ((login.length() 4) (passwd.length() 4)) {message "Invalid inputs";} else {ModelFacade check log new ModelFacade();if (!check log.checkLogin(login, passwd)) {message "Wrong username or password";} else {check e(null,new FacesMessage(message));if (check) {return "go main";} else {return "failure";}}This code will check that the inputs are valid and also will ask the model tocheck if the username and password are valid.22

2. Import the model.ModelFacade package.23

Step 9. Create the main page and run the application.1. Double click in main.jsp in the JSF navigation flow diagram. Create theJSP page like before and it will open in the editor. Enter some text andapply the style sheet.2. Right-Click in the login.jsp page and then run.24

Main Page:25

CIS 764 Tutorial: Log-in Application Javier Ramos Rodriguez Purpose This tutorial shows you how to create a small web application that checks the user name and password. Overview This tutorial will show how to use the EJB 3.0 specification and the Java Server Faces (JSF) in Jdeveloper. We will show that JSF are very useful to validate the inputs.

Related Documents:

CIS 175 Java II CMSC 150 CIS 178 Java Programming I CIS 260JA CIS 179 Java Programming II CIS 260JA or CIS # CIS 189 Python MIS 150 CIS 303 Intro to Data Base CIS # CIS 332 Data Base and SQL CIS 255 CIS 338 SQL/Oracle CIS # CIS 346 Data Base Design CIS # CIS 402 COBOL CIS # CIS 451 PLTW - Comp Sci Applications CIS #

cis-Cyclobutane-1,2-dicarboxylicAnhydride 62 cis-l,2-Bis(hydroxymethyl)cyclobutane 62 cis-l,2-Bis(bromomethyl)cyclobutane 62 cis-l,2-Bis(cyanomethyl)cyclobutane 62 cis-l,2-CyclobutanediaceticAcid 62 DimethylCyclobutane-cis-1,2-di-cC-bromoacetate 62 cetate withSodiumHydride 62

CIS Microsoft Windows 7 Benchmark v3.1.0 Y Y CIS Microsoft Windows 8 Benchmark v1.0.0 Y Y CIS Microsoft Windows 8.1 Benchmark v2.3.0 Y Y CIS Microsoft Windows 10 Enterprise Release 1703 Benchmark v1.3.0 Y Y CIS Microsoft Windows 10 Enterprise Release 1709 Benchmark v1.4.0 Y Y CIS .

the CIS’s suitability to be a Qualifying CIS; or 5. winding up of an Qualifying CIS; and (l) in addition to the requirements in (a) – (k) above, the CIS Operator must be subject to the requirements in its Home Jurisdiction. 1.10 A CIS Operator which participates in this Framework is de

Peter-Michael Osera posera@cis.upenn.edu Richard Eisenberg eir@cis.upenn.edu Christian DeLozier delozier@cis.upenn.edu Santosh Nagarakatte santoshn@cis.upenn.edu Milo M. K. Martin milom@cis.upenn.edu Steve Zdancewic stevez@cis.upenn.edu August 5, 2013 Core Ironclad is a c

Chapter 8 Answers (continued) 34 Answers Algebra 2Chapter 8 Practice 8-3 1. 44 256 2. 70 1 3. 25 32 4. 101 10 5. 51 5 6. 8-2 7. 95 59,049 8. 172 289 9. 560 1 10. 12-2 11. 2-10 12. 38 6561 13. log 9 81 2 14. log 25 625 2 15. log 8 512 3 16. 13 169 2 17. log 2 512 9 18. log 4 1024 5 19. log 5 625 4 20. log 10 0.001 -3 21. log 4 -22.5 -223. log 8 -1 24. log

Gravely 764 Pro Engine w/ Heavy Duty Air Cleaner 26.5 HP / 764 CC 52 IN. 991258 Gravely 764 Pro Engine w/ Heavy Duty Air Cleaner 26.5 HP / 764 CC 60 IN. Performance and comfort don’t need to be mutually exclusive. The Pro-Turn Z has wrapped them both in a new, bol

Institute (ANSI) A300 Part 7-2006 Vegetation Management standards and the International Society of Arboriculture best management practices. IVM has continued to evolve over the last decade, with examples of expanded emphasis of work on: 1) broad assessment of environmental impact, 2) building social awareness and responsibility; and 3) elevated focus on safety and reliability of service. The .