1 / 27

CS420 Software Engineering in Practice

CS420 Software Engineering in Practice. Lab Review, Project J2EE Architecture, & JSPs. J2EE application Structure. J2EE Application. DD = Deployment Descriptor. J2EE DD. .ear file. EJBs. Web component. Web DD JSP files Servlet Class Pictures (GIF/JPG) HTML files. EJB DD EJB class

bonita
Télécharger la présentation

CS420 Software Engineering in Practice

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. CS420 Software Engineering in Practice Lab Review, Project J2EE Architecture, & JSPs

  2. J2EE application Structure J2EE Application DD = Deployment Descriptor J2EE DD .ear file EJBs Web component Web DD JSP files Servlet Class Pictures (GIF/JPG) HTML files EJB DD EJB class Remote class Home class .jar file .war file

  3. Standard deployment descriptors • Enterprise Archive (ear) file • Application.xml inside the META-INF directory • Java Archive (jar) file • ejb-jar.xml inside the META-INF directory • Web Archive (war) file • web.xml inside the WEB-INF directory

  4. Java Server Pages (JSPs) • JSPs are built on servlet technology. • JSPs are an HTML page with special tags embedded. • JSP tags can contain Java code. • JSP file extension is .jsp rather than .htm or .html. • The JSP engine parses the .jsp and creates a Java servlet source file. It then compiles the source file into a class file.

  5. What happens when you access JSP? • User traverses to a JSP page (.jsp) and browser makes the request. • The JSP request gets sent to the Web server. • The Web server recognizes .jsp and passes the JSP file to the JSP Servlet Engine. • If the JSP file has been called the first time, the JSP file is parsed. • The next step is to generate a Servlet from the JSP file. All the HTML required is converted to println statements. • The Servlet source code is compiled into a class. • The Servlet is instantiated, calling the init and service methods. • HTML from the Servlet output is sent via the Internet. • HTML results are displayed on the user's web browser

  6. Creating your first JSP page <html> <head> <title>My first JSP page </title> </head> <body> <%@ page language="java" %> <% out.println("Hello World"); %> </body> </html> Type the code above into a text file. Name the file helloworld.jsp. Place this in the correct directory on your JSP web server and call it via your browser

  7. JSP Tags • Scriptlet tag (previous example) • Declaration tag • Expression tag • Directive tag • Action tag

  8. Declarative Used for declaring variables or methods (no output). Before the declaration you must have <%! At the end of the declaration, the developer must have %> Code placed in this tag must end in a semicolon ( ; ). Declarations are used with JSP expressions or scriptlets. Example: <%! private int counter = 0 ; private String get Account ( int accountNo) ; %>

  9. Expression Tag Expression tag ( <%= %>) This tag allows the developer to embed any Java expression and is short for out.println(). A semicolon ( ; ) does not appear at the end of the code inside the tag. For example, to show the current date and time. Date : <%= new java.util.Date() %>

  10. Directive tag ( <%@ directive ... %>) A JSP directive gives special information about the page to the JSP Engine. There are three main types of directives: 1)     page - processing information for this page. 2)     Include - files to be included. 3)     Tag library - tag library to be used in this page.

  11. Import Directive • Import : Import all the classes in a java package into the current JSP page. This allows the JSP page to use other java classes. • <%@ page import = "java.util.*" %>

  12. Include directive Allows a JSP developer to include contents of a file inside another. Typically include files are used for navigation, tables, headers and footers that are common to multiple pages. Two examples of using include files: This includes the html from privacy.html found in the include directory into the current jsp page. <%@ include file = "include/privacy.html" %> or to include a naviagation menu (jsp file) found in the current directory. <%@ include file = "navigation.jsp" %>

  13. Tag Lib directive A tag lib is a collection of custom tags that can be used by the page. <%@ taglib uri = "tag library URI" prefix = "tag Prefix" %> Custom tags were introduced in JSP 1.1 and allow JSP developers to hide complex server side code from web designers.

  14. Scriptlet tag ( <% ... %> ) Between <% and %> tags, any valid Java code is called a Scriptlet. This code can access any variable or bean declared. For example, to print a variable. <% String username = “Orest" ; out.println ( username ) ; %>

  15. Action tag There are three main roles of action tags : 1)     enable the use of server side Javabeans 2)     transfer control between pages 3)     browser independent support for applets. To use a Javabean in a JSP page use the following syntax: <jsp : usebean id = " ...." scope = "application" class = "com..." /> The following is a list of Javabean scopes: page - valid until page completes. request - bean instance lasts for the client request session - bean lasts for the client session. application - bean instance created and lasts until application ends.

  16. Another Example declares two variables; one string used to stored the name of a website and an integer called counter that displays the number of times the page has been accessed. There is also a private method declared to increment the counter. The website name and counter value are displayed. <HTML> <HEAD> <TITLE> JSP Example</TITLE> </HEAD> <BODY> <font face=verdana color=darkblue> JSP loop <BR> <BR> <%! public String writeThis(int x) { String myText=""; for (int i = 1; i < x; i++) myText = myText + "<font size=" + i + " color=darkred face=verdana>VisualBuilder JSP Tutorial</font><br>" ; return myText; } %> This is a simple example <br> <%= writeThis(8) %> </font> </BODY> </HTML>

  17. Implicit Objects The implicit objects are : Request Response Out Session PageContent Application Config Page   Page object Represents the JSP page and is used to call any methods defined by the servlet class. Config object Stores the Servlet configuration data. Request object Access to information associated with a request. This object is normally used in looking up parameter values and cookies.

  18. JBOSS Deployment of JSPs 0) Create a HelloWorld folder for storing your JSP and DD. 1) Write JSP File This JSP simply displays a greeting along with the current date and time. 2) Create Deployment Descriptor In the "HelloWorld" folder, create a sub folder called "WEB-INF", and in that folder create a file named "web.xml" as: web.xml <web-app><display-name>Hello World</display-name></web-app> The deployment descriptor provides information to JBoss about your web application. 3) Create WAR Builder & Deployer In the "HelloWorld" folder, create a file called "Deploy.bat" as: Deploy.bat set JAVA_HOME=C:\Program Files\Java\jdk1.5.0_06set JBossHome=C:\Apps\JBoss\jboss-4.0.3SP1"%JAVA_HOME%\bin\jar.exe" -cvf helloworld.war *.jsp WEB-INFcopy helloworld.war %JBossHome%\server\default\deploypause This script uses Java's JAR utility to zip up the appropriate contents into a WAR file.

  19. JSP Deployment (cont) 4) Do It Run the "Deploy.bat" file. 5) Test Your Web Page In a browser, open "http://localhost:8080/helloworld" and click on the "hi.jsp" link.Now explore the JBoss console at "http://localhost:8080".  Click on "JBoss Web Console" and expand "J2EE Domains", "Manager", and "JBoss".  Select "helloworld.war" to see information about your web application.

  20. J2EE application Structure J2EE Application DD = Deployment Descriptor J2EE DD .ear file EJBs Web component Web DD JSP files Servlet Class Pictures (GIF/JPG) HTML files EJB DD EJB class Remote class Home class .jar file .war file

  21. Our Project: Location Based Service Applications

  22. Project Statement ?

  23. Requirements. Import requirements (non-functional): 1. Scalability and Reliability2. Open Source (costs) 3. Performance

  24. Non-Functional Requirements Drive Architecture and Technology • J2EE (JBoss) Open Source • (Yahoo Java script API) • MySQL Open Source

  25. Phase 1. • Develop .war/jar files • .war file contains html and jsps that can create “java objects” based on user/password from user • .jar file contains entity EJBs that can store information into MySQL

  26. Divide into Teams • Exchange Contact Info • Start Planning a time table • Who’s the leader? • What are the roles? • Who’s the liaison with the other team?

More Related