PATH Documentation > WebObjects

 

Creating a JSP-Based Application

This section shows you how to create a simple JSP-based WebObjects application. In it you learn how to use the <wo:component> tag in a JSP page.

  1. Launch Project Builder and create a WebObjects Application project called JSP_Example.
  2. In the Enable J2EE Integration pane of the Project Builder Assistant, select Deploy in a JSP/Servlet Container.
  3. In Project Builder, create a component called Hello (make sure you assign it to the Application Server target). Edit the component using WebObjects Builder so that it looks like Figure 3-1.

    Figure 3-1 The Hello component in WebObjects Builder

    [image: ../art/hello_wo.gif]

  4. Set the servlet application directory.
    1. In Project Builder click Targets, then click the JSP_Example target the Targets list.
    2. Click Build Settings, then scroll down until you see the Build Settings list.
    3. Locate the SERVLET_WEBAPPS_DIR build setting and enter the path of your servlet container's application directory, as shown in Figure 3-2.

      Figure 3-2 Telling Project Builder where to put the WAR file

      [image: ../art/bs_webapps.gif]


  5. Using Finder, navigate to the Servlet Resources folder, located in the JSP_Example folder, and create a folder called jsp.
  6. Using a text editor, create a file with the following contents:
    <%-- Welcome.jsp --%>
    
    <%@ taglib uri="/WOtaglib" prefix="wo" %>
    
    <HTML>
    
    <HEAD>
        <TITLE>Welcome to JSP in WebObjects</TITLE>
    </HEAD>
    
    <BODY>
        <wo:component className="Hello">
        </wo:component>
    </BODY>
    
    </HTML> 
  7. Save the file as Welcome.jsp in the jsp directory.
  8. Build the JSP_Example project (if necessary, restart your servlet container).

You should now be able to connect to your application. In Tomcat, you use the following URL:

http://localhost:8080/JSP_Example/jsp/Welcome.jsp

A page similar to the one in Figure 3-3 should appear in your browser. (Otherwise, consult your servlet container's documentation to make sure that it's configured properly.)


Figure 3-3 The output of Welcome.jsp

[image: ../art/welcome_jsp.gif]

 


© 2002 Apple Computer, Inc. (Last Updated January 3, 2002)