Download presentation
Presentation is loading. Please wait.
1
Objectives:1. Investigate the Web application deployment descriptor 2. Install and deploy Tomcat and struts 3. Design and deploy a struts application Struts Deployment
2
Topics To learn how to create and deploy WAR files Deployment Descriptor (web.xml) Installing and Configuring Tomcat Installing Struts The struts-config.xml file Designing a Struts Application Deploying a Struts Application
3
Packaging a Web Application for Deployment Servlet Specification 2.2 specified the use of a single web archive file - *.war An extension of the.jar file Has the same form as the.zip file (.jar and.war)
4
Why use a WAR file? Simplify deployment Easy to install Single file to each server in cluster Improve security No access between Web applications Packaging for third-party applications
5
Structure of a WAR File beans WEB-INF classes Package directories lib web.xml Class files JAR files JSP pages, HTML documents, image files app.war Class files Content directories tlds TLD files
6
Creating a WAR file Use the jar command line tool Use.war for the extension of the file name
7
Accessing the WAR File All WAR contents are associated with a top-level URL directory: http://myserver.com/app/… URLs for assets in top-level and content directories are assigned automatically. URLs for WEB-INF assets must be explicitly specified.
8
Configuring WEB-INF Assets Primarily controlled via the deployment descriptor: WEB-INF/web.xml Deployment descriptor is an XML document: <!DOCTYPE web-app PUBLIC -//Sun Microsystems, Inc.//DTD Web Application 2.2//EN" "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd"> Has the root element of: …
9
Elements of a Web Application Application configuration Context parameters Servlet configuration Session Configuration Servlet Mapping MIME types Default pages Custom Tag Libraries
10
Application Configuration wdk/widget/image/illustration/button/dctmlogo16 x16.gif wdk/widget/image/illustration/button/dctmlogo32 x32.gif Sample Library Services Client This web application provides an example of how to leverage library services.
11
Context Parameters Name/value pairs that become available in the ServletContext object using the getInitParameter() method dbUser joe dbPwd zebra
12
Servlet Configuration A web application’s servlets are specified in the deployment descriptor via the tag and its subelements Mandatory tags for each servlet definintion: tag - specifies a logical name for the servlet tag - specifies the Java class that implements the servlet Optional tags:,, parameters passed to the init() method of the servlet signifies that the servlet should be loaded into JVM at container startup. Value of the element signifies its relative order. It may be an empty tag
13
Servlet Configuration MyGreatServlet com.BigCompany.RJServlet Great Servlet GreatnessLevel 6 1
14
Servlet Mapping Used to hide the implementation of the application by giving a servlet a logical name in the form of a URI MyGreatServlet /GServ
15
Session Configuration Sets the session timeout … 60 …
16
MIME Types Maps file extensions to MIME Types pdf application/pdf html text/html
17
Default Pages and Distributable Servlets default.html index.jsp specifies which file within an application directory should be displayed when a URL is requested that contains only a directory has no content signals whether an application can run in multiple JSP containers simultaneously
18
Custom Tag Libraries … /greatTags /WEB- INF/tlds/greatTags_1_0.tld …
19
Tomcat JSP/Servlet Container Open-source Java-based Web application container Initially through the Jakarta project of the Apache Software Foundation Runs servlets on Catalina container portion Runs JSP on Jasper container portion Sun’s reference implementation for servlet and JSP specifications http://tomcat.apache.org
20
Installing and Configuring Tomcat Make sure a current and compatible version of the Java SDK, Standard Edition is installed Acquired at http://java.sun.com/javase http://java.sun.com/javase Extract Tomcat server from downloaded archive Set JAVA_HOME to location of Java SE installation
21
Testing Tomcat Installation Open up a command prompt window or shell Navigate to the Tomcat installation directory Start the Tomcat server bin\startup Open your browser and type in the following URL http://localhost:8080
22
Verify JSP Container Operation Select JSP Examples link
23
Jakarta Struts Project Open-source Java-based Web application development framework Initially developed through the Jakarta project of the Apache Software Foundation Provides control layer based on standard technologies Servlets JavaBeans ResourceBundles XML http://struts.apache.org
24
Supporting Web Applications with Struts Extract Struts files from downloaded archive For each Web Application Copy JAR files to /WEB-INF/lib directory Make sure a web.xml file exists in /WEB-INF Create a struts-config.xml file and store in /WEB-INF Deployment descriptor for Struts applications Integrates the MVC components into a working application
25
Struts and JBoss Go to http://struts.apache.orghttp://struts.apache.org Download version 1 release Extract Struts files from downloaded archive Copy struts-taglib and struts-core file to: $JBOSS/server/all/deploy/jboss-web.deployer $JBOSS/server/all/lib Copy all commons*.jar files to: $JBOSS/server/all/deploy/jboss-web.deployer When creating Web application: copy struts tlds to WEB-INF/tlds directory in application war file create appropriate web.xml file add struts-config.xml file to WEB-INF directory
26
A basic struts-config.xml file http://jakarta.apache.org/struts/dtds/struts- config_1_3.dtd <message-resources parameter=“company.ApplicationResources” />
27
Tag-Library Descriptors To use specialized struts tags Specify a taglib entry in web.xml Copy struts-html.tld to /WEB-INF/tlds /struts-html.tld /WEB-INF/tlds/struts- html.tld
28
Steps for Designing a Struts Application Define and create all the Views Add ActionForms used to support views Create the controller components ActionServlet Action Define View-Controller relationships in struts- config.xml Describe the struts components to the Web server web.xml Run the application
29
Creating the Views Views composed of HTML JSP Struts tag libraries Bean HTML Logic
30
Struts-specific Form Tags The struts HTML tag library offers struts- specific functionality Product ID:
31
Flow of Control Upon submission of JSP View, ActionForm object will be created, populated with the request parameters, and stored in the session. The action referenced by the will be invoked and passed a reference to the populated ActionForm.
32
ActionForm Properties are populated by request parameters of the same name Struts uses JavaBean reflection Design patterns must be followed private String product; public void setProduct(String prod); public String getProduct(); reset() method restores baseline state
33
Define the Form Bean Make the form bean known to the struts framework Declare the following element in struts-config.xml
34
Create the Controller Composed of two components A single implementation of org.apache.struts.action.ActionServlet Dispatching component One or more implementations of org.apache.struts.action.Action Performs business logic Entry point is execute() method
35
Controller-View Flow Within the execute() method, targets are determined which dictate the next page in the Web application sequence. The execute() method returns an instance of ActionForward.. target = new String(“success”); return (mapping.findForward(target));
36
Deploying Actions Add an entry to the section of struts- config.xml <action path="/Lookup" type="ssps.LookupAction" name="lookupForm” input="/prompt.jsp">
37
Deploy the Struts Application Define the ActionServlet to the Web application Inform the ActionServlet of the location of struts-config.xml Specify that the ActionServlet is preloaded
38
Deploy the Struts Application – web.xml action org.apache.struts.action.ActionServlet config /WEB-INF/struts-config.xml 1
39
Deploy the Struts Application – web.xml action *.do
40
Review To learn how to create and deploy WAR files Deployment Descriptor (web.xml) Installing and Configuring Tomcat Installing Struts The struts-config.xml file Designing a Struts Application Deploying a Struts Application
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.