Lesson 1.4 leads you through the creation of a JSP and a Faces
JSP to test your application.
Before you begin, you must complete Lesson 1.3. In this lesson you
will:
- Create a JSP to test your Java™ application.
- Run the JSP in the WebSphere® test environment.
- Create a Faces JSP to test your Java application.
- Run the Faces JSP in the WebSphere test environment.
- First you will create a JSP: Click File > New
> Other > J2C.
- In the Select a wizard page, select Web Page, Web Service,
or EJB from J2C Java bean.
- Click Next.
- In the J2C Java bean selection page, click Browse.
- In the Find J2C bean page, type an asterisk (*) in the Select
entries field.
- In the Matching types field, select PhoneBookImpl.
- Click OK.
- In the J2C Java bean selection page, click Next.
- In the Deployment Information page, select Simple JSP.
- Click Next.
- In the JSP Creation page, select . Generate simple JSPs
with default input modes.
- In the JSP folder field, enter a JSP Folder name, such as SampleJSP.
- Click Finish.
- Next you will run your JSP: Right-click TestClient.jsp and
select Run on Server.
- A browser window with the Test Client will launch. Click on runPhoneBook method.
- Use the following values as Inputs:
- Type IVTNO in the In__trcd field.
- Type 0 in the In___zz field.
- Type LAST1 in the In__name1 field.
- Type DISPLAY in the In__cmd field.
- Type 59 in the In__ll field.
- Type 93 in the size field.
- Click Invoke, and this output will appear
in the Result field.

- Now submit another command to add a phone book entry. Click on runPhoneBookmethod.
- Use the following values as Inputs:
- Type 59 in the In__ll field.
- Type 0 in the In___zz field.
- Type IVTNO in the In__trcd field.
- Type Add in the In__cmd field.
- Type Jane in the In__name2 field.
- Type Doe in the In__name1 field.
- Type 55555 in the In__zip field.
- Type 5-5555 in the In__extn field.
- Type 93 in the size field.
- Click Invoke, and this output will appear
in the Result field.

- Now submit another command to display the phone book entry you
just added. Click on runPhoneBook method.
- Use the following values as Inputs:
- Type 59 in the In__ll field.
- Type IVTNO in the In__trd field.
- Type 0 in the In___zz field.
- Type DISPLAY in the In__cmd field.
- Type Doe in the In__name1 field.
- Type 93 in the size field.
- Click Invoke, and this output will appear
in the Result field.

- Now you will create a Faces JSP to deploy the J2C Java bean:
- Expand the IMSPhoneBook project, and find the WebContent folder.
- Right click on WebContent folder in your IMSPhoneBook project
and select New > Other > Web > Faces JSP file.
- Type Test in the Name field.
- Accept defaults for all other fields.
- Click Finish.
- Next you will add the Java bean to faces JSP: Once you have
created the Faces JSP file, the page should open Test.jsp in the Design page.
If the workspace does not open in the Design page of the editor, expand the WEB-INF folder
under the WebContent folder. Right click on Test.jsp,
select Open With, and click on Page Designer.
Test.jsp will open in the Design page.
- The Palette view should appear on the right panel. If it does not
appear, in the top menu, click on Window > Show view > Palette.
- In the Datafolder of the Palette view, click
on the JavaBean option of the Palette.
- Drag and drop the JavaBean to the Test.jsp editor; the Add JavaBean
wizard will open.
- Select Add new JavaBean.
- In the Name field, type phonebookLookup.
- Click the open book icon,
, beside the Class field. The Class
Selection window appears.
- In the Class Selection page, type PhoneBookImpl in
the Search field.
- Deselect the Add input/output controls to display the
JavaBean on the Web page check box.
- Click Finish.
- You will see PhoneBookImpl in the Page Data
view.
- Adding input and output controls to the faces JSP: Right-click phonebookLookup
Java Bean in the Page Data view, and click Add New
JavaBean Method.
- From the list of available methods, click on runPhoneBook.
- Click OK.
- Expand phonebookLookup Java Bean in the
Page Data view, and select the runPhoneBook() method.
- Drag and drop the runPhoneBook() method
onto the editor. The Insert JavaBean wizard appears.
- In the Create controls for: field, select Inputting
data.
- In the Fields to display field, select None,
to clear the form.
- In the Fields to display field, select these
input fields
- arg.in__trcd
- arg.in__zz
- arg.size
- arg.in__name1
- arg.in__cmd
- arg.in__ll
- Click Finish.
- Accept defaults for the other fields.
- Click Next.
- In the Configure Data Controls page, select Create controls
for displaying the results.
- In the Fields to display field, select None,
to clear the form.
- In the Fields to display field, select these
output fields
- out__zz
- out__zip
- out__extn
- out__msg
- out__cmd
- out__ll
- out__name2
- out__name1
- size
- Click Finish.
- Save your Faces JSP page, by pressing Ctrl-S or
by clicking File > Save in the toolbar.
- Now you will test the Faces JSP: Select the Servers tab.
Start the test server, if it is not already running. To start the server,
right click on the WebSphere Application Server v6.0 and
click Start.
- Right click on Test.jsp (the faces JSP that you just created) in
the Project Explorer view, and select Run < Run on Server.
- Select WebSphere Application Server v6.0 and
click Finish.
- The browser will open to Test.jsp.Use the following values as Inputs:
- Type IVTNO in the In__trcd field.
- Type 59 in the In__ll field.
- Type 0 in the In___zz field.
- Type DISPLAY in the In__cmd field.
- Type LAST1 in the In__name1 field.
- Type 93 in the size field.
Note: Ensure that there are no extra spaces in the text box before your
entry.
- Click Submit.
- You will see the output displayed in your browser.
Congratulations! You have completed the PhoneBook tutorial.