13
Packaging Web Modules To build the hello1 application with NetBeans IDE, follow these instructions: 1. Select File→Open Project. 2. In the Open Project dialog, navigate to: tut-install/javaeetutorial5/examples/web/ You can download it from here http://java.net/projects/javaeetutorial/downloads/download/javaeetutorial 5.zip 3. Select the hello1 folder. 4. Select the Open as Main Project check box. 5. Click Open Project Folder. 6. In the Projects tab, right-click the hello1 project and select Build Project. Deploying a WAR File

Packaging Web Modules - Faculty Web - Faculty …ksuweb.kennesaw.edu/~kqian/CS_4903_and_6143_Ent… · Web viewPackaging Web Modules To build the hello1 application with NetBeans

  • Upload
    others

  • View
    1

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Packaging Web Modules - Faculty Web - Faculty …ksuweb.kennesaw.edu/~kqian/CS_4903_and_6143_Ent… · Web viewPackaging Web Modules To build the hello1 application with NetBeans

Packaging Web Modules

To build the hello1 application with NetBeans IDE, follow these instructions:

1. Select File→Open Project.2. In the Open Project dialog, navigate to:

tut-install/javaeetutorial5/examples/web/You can download it from here http://java.net/projects/javaeetutorial/downloads/download/javaeetutorial5.zip

3. Select the hello1 folder.4. Select the Open as Main Project check box.

5. Click Open Project Folder.6. In the Projects tab, right-click the hello1 project and select Build Project.

Deploying a WAR File

In a packaged web module for deployment on the Application Server, the context root is stored in sun-web.xml.

To edit the context root, do the following:

1. Expand your project tree in the Projects pane of NetBeans IDE.

Page 2: Packaging Web Modules - Faculty Web - Faculty …ksuweb.kennesaw.edu/~kqian/CS_4903_and_6143_Ent… · Web viewPackaging Web Modules To build the hello1 application with NetBeans

2. Expand the Web Pages and WEB-INF nodes of your project.

3. Double-click sun-web.xml.

4. In the editor pane, click Edit As XML.

5. Edit the context root, which is enclosed by the context-root element.

To deploy a WAR with NetBeans IDE, do the following:

1. Select File→Open Project.2. In the Open Project dialog, navigate to your project and open it.

3. In the Projects tab, right-click the project and select Deploy Project.

Page 3: Packaging Web Modules - Faculty Web - Faculty …ksuweb.kennesaw.edu/~kqian/CS_4903_and_6143_Ent… · Web viewPackaging Web Modules To build the hello1 application with NetBeans
Page 4: Packaging Web Modules - Faculty Web - Faculty …ksuweb.kennesaw.edu/~kqian/CS_4903_and_6143_Ent… · Web viewPackaging Web Modules To build the hello1 application with NetBeans

Updating a Packaged Web ModuleThis section describes how to update the hello1 web module that you packaged.

First, change the greeting in the file tut-install/javaeetutorial5/examples/web/hello1/web/index.jsp to

<h2>Hi, my name is Jogi. What’s yours?</h2>

To update the project in NetBeans IDE:

← Right-click on the project and select Build Project.

← Right-click on the project and select Deploy Project.

Page 5: Packaging Web Modules - Faculty Web - Faculty …ksuweb.kennesaw.edu/~kqian/CS_4903_and_6143_Ent… · Web viewPackaging Web Modules To build the hello1 application with NetBeans

Configuring Web Applications

Mapping URLs to Web Components

Setting the Component Alias

The hello2 application has two servlets that need to be mapped in the web.xml file. You can edit a web application’s web.xml file in NetBeans IDE by doing the following:

1. Select File→Open Project.2. In the Open Project dialog, navigate to:

tut-install/javaeetutorial5/examples/web/

3. Select the hello2 folder.4. Select the Open as Main Project check box.

5. Click Open Project Folder.

6. Expand the project tree in the Projects pane.

7. Expand the Web pages node and then the WEB-INF node in the project tree.

Page 6: Packaging Web Modules - Faculty Web - Faculty …ksuweb.kennesaw.edu/~kqian/CS_4903_and_6143_Ent… · Web viewPackaging Web Modules To build the hello1 application with NetBeans

8. Double-click the web.xml file inside the WEB-INF node.

The following steps describe how to make the necessary edits to the web.xml file, including how to set the display name and how to map the servlet components. Because the edits are already in the file, you can just use the steps to view the settings.

To set the display name:

1. Click General at the top of the editor to open the general view.

2. Enter hello2 in the Display Name field.

Page 7: Packaging Web Modules - Faculty Web - Faculty …ksuweb.kennesaw.edu/~kqian/CS_4903_and_6143_Ent… · Web viewPackaging Web Modules To build the hello1 application with NetBeans

To perform the servlet mappings:

1. Click Servlets at the top of the editor to open the servlets view.2. Click Add Servlet.

3. In the Add Servlet dialog, enter GreetingServlet in the Servlet Name field.

4. Enter servlets.GreetingServlet in the Servlet Class field.

5. Enter /greeting in the URL Pattern field.

6. Click OK.

7. Repeat the preceding steps, except enter ResponseServlet as the servlet name, servlets.ResponseServlet as the servlet class, and /response as the URL pattern

To package the example with NetBeans IDE, do the following:

In the Projects tab, right-click the hello2 project and select Build Project. To deploy the example using NetBeans IDE, right-click on the project in the Projects pane and

select Deploy Project.

To run the application, first deploy the web module, and then open the URL http://localhost:8080/hello2/greeting in a browser.

Page 8: Packaging Web Modules - Faculty Web - Faculty …ksuweb.kennesaw.edu/~kqian/CS_4903_and_6143_Ent… · Web viewPackaging Web Modules To build the hello1 application with NetBeans

Declaring Welcome Files

To specify a welcome file in the web application deployment descriptor using NetBeans IDE, do the following:

1. Open the project if you haven’t already.2. Expand the project’s node in the Projects pane.

3. Expand the Web Pages node and then the WEB-INF node.

4. Double-click web.xml.

5. Do one of the following, making sure that the JSP pages you specify are actually included in the WAR file:

1. Click Pages at the top of the editor pane and enter the names of the JSP pages that act as welcome files in the Welcome Files field.

Page 9: Packaging Web Modules - Faculty Web - Faculty …ksuweb.kennesaw.edu/~kqian/CS_4903_and_6143_Ent… · Web viewPackaging Web Modules To build the hello1 application with NetBeans

2. Click XML at the top of the editor pane, specify the JSP pages using welcome-file elements and include these elements inside a welcome-file-list element. The welcome-file element defines the JSP page to be used as the welcome page.

Setting Initialization Parameters

To add a context parameter using NetBeans IDE, do the following:

1. Open the project if you haven’t already.2. Expand the project’s node in the Projects pane.

3. Expand the Web Pages node and then the WEB-INF node.

4. Double-click web.xml.

5. Click General at the top of the editor pane.

6. Select the Context Parameters node.

7. Click Add.

8. In the Add Context Parameter dialog, do the following:

Page 10: Packaging Web Modules - Faculty Web - Faculty …ksuweb.kennesaw.edu/~kqian/CS_4903_and_6143_Ent… · Web viewPackaging Web Modules To build the hello1 application with NetBeans

1. Enter the name that specifies the context object in the Param Name field.

2. Enter the parameter to pass to the context object in the Param Value field.

3. Click OK.

Alternatively, you can edit the XML of the web.xml file directly by clicking XML at the top of the editor pane and using the following elements to add a context parameter:

← A param-name element that specifies the context object← A param-value element that specifies the parameter to pass to the context object

← A context-param element that encloses the previous two elements

To add a web component initialization parameter using NetBeans IDE, do the following:

1. Open the project if you haven’t already.2. Expand the project’s node in the Projects pane.

3. Expand the Web Pages node and then the WEB-INF node.

4. Double-click web.xml.

5. Click Servlets at the top of the editor pane.

6. After entering the servlet’s name, class, and URL pattern, click the Add button under the Initialization Parameters table.

7. In the Add Initialization Parameter dialog:

1. Enter the name of the parameter in the Param Name field.

2. Enter the parameter’s value in the Param Value Field.

3. Click OK.

Alternatively, you can edit the XML of the web.xml file directly by clicking XML at the top of the editor pane and using the following elements to add a context parameter:

← A param-name element that specifies the name of the initialization parameter← A param-value element that specifies the value of the initialization parameter

← An init-param element that encloses the previous two elements

Mapping Errors to Error Screens

To set up error mappings using NetBeans IDE, do the following:

1. Open the project if you haven’t already.2. Expand the project’s node in the Projects pane.

3. Expand the Web Pages node and then the WEB-INF node.

Page 11: Packaging Web Modules - Faculty Web - Faculty …ksuweb.kennesaw.edu/~kqian/CS_4903_and_6143_Ent… · Web viewPackaging Web Modules To build the hello1 application with NetBeans

4. Double-click web.xml.

5. Click Pages at the top of the editor pane.

6. Expand the Error Pages node.

7. Click Add.

8. In the Add Error Page dialog:

1. Click Browse to locate the page that you want to act as the error page.

2. Enter the HTTP status code that will cause the error page to be opened in the Error Code field.

3. Enter the exception that will cause the error page to load in the Exception Type field.

4. Click OK.

Alternatively, you can click XML at the top of the editor pane and enter the error page mapping by hand using the following elements:

← An exception-type element specifying either the exception or the HTTP status code that will cause the error page to be opened.

← A location element that specifies the name of a web resource to be invoked when the status code or exception is returned. The name should have a leading forward slash (/).

← An error-page element that encloses the previous two elements.