Mindmajix

Creating and deploying a web application

As you can see, the application server provides a straightforward way to configure the Web container. In order to run a web application, you need to learn how to organize its specific configuration files and which libraries are needed to render the web application.

JBoss AS 7 is a Java EE 6-compatible application server and thus, it can be used to deploy a wide range of web applications. Today, one of the most common approaches to building your application is using the Java Server Faces technology, which is an evolution of JSP technology.

Currently, JBoss AS 7 supports the JSF release 2.1 using the Mojarra implementation, although there are plans for supporting MyFaces implementation too.

Note

The purpose of this example is to teach the reader how to create, configure, and deploy a Java EE 6 application on JBoss AS 7. If you want to learn the best practices for developing a Java EE 6 application on AS 7, you should check out the quick-start examples that are available along with the server distribution.

Creating a new Dynamic Web Project

There are several options for creating a JSF project using Eclipse Enterprise. The most basic option will be creating a new Dynamic Web Project from the menu. Let’s call this project as7project and use as target runtime the JBoss AS 7 runtime, which we installed at the beginning of the book.

Screenshot_59

Configuring JSF 2.1 support for a web application requires very little effort. As a matter of fact, you can do it in two single steps: first, declare in your web application configuration file (web.xml) your FacesServlet and what kind of URL patterns will be directed to it.

Note The FacesServlet is a servlet that manages the request processing lifecycle for web applications that are utilizing JavaServer Faces to construct the user interface. Here’s the web.xml file that needs to be placed in the WEB-INF folder of your application:

<web-app xmlns=”http://java.sun.com/xml/ns/javaee”xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”xsi:schemaLocation=”http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd”version=”3.0″>

<display-name>WebExample</display-name>

<welcome-file-list>

<welcome-file>index.html

</welcome-file>
<welcome-file>index.htm</welcome-file>

<welcome-file>index.jsp</welcome-file>

<welcome-file>default.html</welcome-file>

<welcome-file>default.htm</welcome-file>

<welcome-file>default.jsp</welcome-file>

</welcome-file-list>

<servlet>

<servlet-name>Faces Servlet</servlet-name>

<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>

<load-on-startup>1</load-on-startup>

</servlet>

<servlet-mapping>

<servlet-name>Faces Servlet</servlet-name>

<url-pattern>*.xhtml</url-pattern>

</servlet-mapping>

</web-app>

Next, you need to create a minimal JSF configuration file, named faces-config.xml, which will be placed in the WEB-INF folder of your application. This file declares the JSF release that we are going to use, in our case 2.1. <?xml version=”1.0″ encoding=”UTF-8″?>

<faces-config   xmlns=”http://java.sun.com/xml/ns/javaee”xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”xsi:schemaLocation=”http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_1.xsd”version=”2.1″>

</faces-config>

Please note that Eclipse is actually able to install these files for you by activating the Java Server Faces Facets . Right-click on your project and select Project Properties. From there, you will find under the Project Facets option a set of configuration options that can be automatically added to your project. In our case, Eclipse will exactly do the file configuration that we did manually.

Screenshot_60


0 Responses on Creating and deploying a web application"

Leave a Message

Your email address will not be published. Required fields are marked *

Copy Rights Reserved © Mindmajix.com All rights reserved. Disclaimer.
Course Adviser

Fill your details, course adviser will reach you.