FeaturesPluginsDocs & SupportCommunityPartners

NetBeans IDE 4.0 Midnight Cookie Company Tutorial

The Midnight Cookie Company application that you will build in this tutorial will show you how to do the following:

This application uses the JavaServer Pages Standard Tag Library (JSTL) to fetch dynamic data and to internationalize the JSP pages used in this application.

This tutorial should take approximately two hours to complete.

NetBeans IDE 4.0Quick Start Guide for Web Applications

Starting with NetBeans 4.0 or Java for the first time? See the NetBeans IDE 4.0 Quick Start Guide for Web Applications. Once you have completed it, you will be ready to build on your knowledge with this tutorial!


Setting Up Your Environment


Obtaining the required source files

To create the Midnight Cookie Company application, you need the midnight.zip file, which contains the source files on which you build the application. The source files include the WEB-INF folder, which contains the classes, docs, tlds and lib folders that you will use in this tutorial.

  1. In your file system, create a folder for the unzipped application files. From now on, we will refer to this folder as $UNZIPHOME.
  2. Click here to download the file.
  3. Use an application that unzips files to unzip the midnight.zip file to $UNZIPHOME.
  4. $UNZIPHOME now has a WEB-INF folder, which contains the following files and folders:

    File or Folder
    Description
    web.xml Deployment descriptor for the web application.
    classes Contains the resource bundle property files that are used to internationalize the pages and contains the com/midnightcookies/taghandlers folder. The taghandlers folder contains the class files for the ContentHandler tag handler, the ButtonHandler tag handler, and the LinksHandler tag handler. The ContentHandler includes the contents of the specified JSP file. The ButtonHandler prints a submit button with a localized message. The LinksHandler displays a set of links, including a separator, from the tag attribute.
    docs Contains the header.jsp file, the index.jsp file, and the nonesuch.jsp file. During the tutorial, you will create the main.jsp page and place it in this folder. Also contains the cookies folder, which includes the CookieCutter.jsp file and the CookieMake.jsp file. During the tutorial, you will create the Tray.jsp page and place it in this folder. The about folder contains the about.jsp file, which outlines this web application's architecture.
    lib Contains the standard.jar file and the jstl.jar file. These two files contain the implementation for the JSTL. The standard.jar contains the TLDs and the tag handlers. The jstl.jar file contains other application program interfaces (APIs) that are needed.
    tlds Contains the proprietary midnight.tld.

Developing the Application


Creating a web project from the provided source files

  1. Choose File > New Project (Ctrl-Shift-N). Under Categories, select Web. Under Projects, select Web Project with Existing Sources. Click Next.
  2. In Location, click Browse to select the web application's document root. The document root is $UNZIPHOME, the folder to which you unzipped the midnight.zip file.
  3. In Project Name, type Midnight. Change the Project Location to any folder on your computer. From now on, we will refer to this folder as $PROJECTHOME. Notice that the Context Path is /Midnight. Click Next.
  4. Click Finish. The IDE creates the $PROJECTHOME/Midnight project folder. The project folder contains all of your sources and project metadata, such as the project Ant script. The Midnight project opens in the IDE. You can view its logical structure in the Projects window and its file structure in the Files window.

Creating a front controller using a servlet

A front controller is responsible for routing incoming user requests and can enforce navigation in web applications. A front controller provides a single entry point through which requests for several resources in a web application pass. A front controller can reduce duplication of code in JSP pages, especially in cases where several resources require the same processing. For more information on front controllers, see the "Front Controllers" section of the Building Web Components programming series book, which is available on the documentation page of the Sun™ ONE Studio Developer Resources web site.

  1. Expand the Midnight project node and the Source Packages node.
  2. Right-click the com.midnightcookies package node and choose New > File/Folder. Under Categories, select Web. Under File Types, select Servlet. Click Next.
  3. Enter FrontController in the Class Name text box and make sure that the com.midnightcookies package is selected in the Package drop-down. Click Next.
  4. Change the value of the URL Mappings text box to the following:
     /docs/*, /
    Note that the "," in the line above is a delimiter between URL mappings. It enables you to create multiple URL mappings for each servlet.

  5. Click Finish.

    FrontController.java opens in the Source Editor.

  6. Expand the Web Pages node and the WEB-INF node. Double-click the web.xml node. The content of the deployment descriptor file, web.xml, is displayed in the Source Editor. Notice that the servlet mapping entries include the following mappings, which you defined in step 4 above:

    The servlet mapping "/docs/*" prevents the FrontController servlet from forwarding pages to itself, while the servlet mapping "/" gives the FrontController servlet a servlet mapping to handle a request such as http://hostname:portnumber/midnight/.

Adding the methods to process requests and to create a cookie

Now you will edit the FrontController.java file to include the logic needed to process the requests received by the web application. You will modify the processRequest method and create a new method called createCookie, which demonstrates how to create a cookie used in a web application.

  1. In the Projects window, expand the FrontController.java node and the FrontController class node. The Fields node, Constructors node, Methods node, and Bean Patterns node are displayed.

  2. Expand the Methods node and double-click the processRequest node. The Source Editor displays the processRequest method.

  3. In the Source Editor, right-click the left margin and select Show Line Numbers from the contextual menu.

  4. Replace the processRequest method (lines 39 through 54) with the following code.

    
     protected void processRequest(HttpServletRequest request, HttpServletResponse response)
       throws ServletException, IOException {
         String id = request.getRequestURI();
         id = id.substring(request.getContextPath().length());
         getServletContext().log
           ("Midnight Cookies FrontController received a request for " + id);
    
         // The page variable holds the path to the page that will be included
         // in the content area of the template page /WEB-INF/docs/main.jsp.
         // It is passed to the template in a request attribute.
         String page;
    
         // If no request is received or if the request received is
         // for the root, serve /WEB-INF/docs/index.jsp
         if (id == null || id.trim().equals("") || id.equals("/")){
             page = "/WEB-INF/docs/index.jsp";
         }
    
         // If a request received is for a file that does not end in
         // .jsp or .html, there was an error. Include the
         // error page (nonesuch.jsp) and set the nonesuch attribute with
         // the path requested.
         else if (!id.endsWith(".jsp") && !id.endsWith(".html")) {
             page = "/WEB-INF/docs/nonesuch.jsp";
             request.setAttribute("nonesuch", id);
         }
         else {
             page = "/WEB-INF".concat(id);
    
             if (id.equals("/docs/cookies/CookieMake.jsp")) {
                 Cookie cookie = createCookie(request);
                 if (cookie == null) {
                     page = "/WEB-INF/docs/cookies/CookieCutter.jsp";
                 }
                 else {
                     response.addCookie(cookie);
                     request.setAttribute("cookie", cookie);
                 }
             }
         }
    
         request.setAttribute("page", page);
         try {
             request.getRequestDispatcher("/WEB-INF/docs/main.jsp").forward(request, response);
         }
         catch(Throwable t) {
             getServletContext().log(t.getMessage());
         }
     }
    

    Note: After you enter code (either by typing or copying and pasting) into the Source Editor, place the cursor in the Source Editor and press Ctrl-Shift-F to automatically reformat the code.

    The line with the call to the createCookie method is underlined and marked as an error, similar to the following illustration. This is because the method does not exist yet. You will create the createCookie method in the steps below.

    Source Editor with the call to the createCookie method marked as an error because the createCookie method does not exist yet.

    When you place the cursor over the error box (the small red square with a white cross in the left margin of the Source Editor), the IDE describes the error.

  5. In the Source Editor, place the cursor just after the getServletInfo method near the bottom of the file.

  6. Copy the the following code and paste it in the Source Editor to create the createCookie method.
        private Cookie createCookie(HttpServletRequest request) {
    
            String name = (String)request.getParameter("name");
            if (name == null || name.trim().equals("")) {
                request.setAttribute("noname", "noname");
                request.setAttribute("error", "true");
    	    return null;
            }
    
            String value = (String)request.getParameter("value");
            if (value == null || value.trim().equals("")) {
                request.setAttribute("novalue", "novalue");
                request.setAttribute("error", "true");
    	    return null;
            }
    
    	System.out.println(name);
    	System.out.println(value);
    
    	Cookie cookie = null;
    	try {
    	    cookie = new Cookie(name, value);
    	}
    	catch(IllegalArgumentException ex) {
    	    // Probably an illegal name
    	    ex.printStackTrace();
    	    request.setAttribute("error", "true");
    	    request.setAttribute("noname", "badname");
    	    return null;
    	}
    
    	String maxage = request.getParameter("maxage");
    	if (maxage != null && !maxage.trim().equals("")) {
    	    try {
    		cookie.setMaxAge(Integer.parseInt(maxage));
    	    }
    	    catch(NumberFormatException nfe) {
    		nfe.printStackTrace();
    		request.setAttribute("badnumber", "badnumber");
    		request.setAttribute("error", "true");
    		return null;
    	    }
    	}
    
    	String domain = request.getParameter("domain");
    	if (domain != null && !domain.trim().equals("")) {
    	    cookie.setDomain(domain);
    	}
    
    	String path = request.getParameter("path");
    	if (path != null && !path.trim().equals("")) {
    	    cookie.setPath(path);
    	}
    
    	String secure = request.getParameter("secure");
    	if (secure != null && secure.equals("on")) {
    	    cookie.setSecure(true);
    	} else {
    	    cookie.setSecure(false);
    	}
            return cookie;
        }
    
    

    Note: After you enter code (either by typing or copying and pasting) into the Source Editor, place the cursor in the Source Editor and press Ctrl-Shift-F to automatically reformat the code.

  7. Press Ctrl-S to save the document. The asterisk in the file's tab in the Source Editor disappears. This asterisk appears whenever there are changes that have not been saved to disk.

  8. In the Projects window, right-click the FrontController.java node and select Compile File to check that there were no errors introduced in the steps you have completed. The Output window displays messages from the compiler, including any errors. You can double-click the links in the error messages to locate the source of the error. Resolve all errors listed in the Output window before continuing with the tutorial.

Creating the JSP page that receives all the requests

The main.jsp page receives all the requests that the FrontController servlet processes. A dynamic include statement and a LinksHandler are used to create the page.

  1. Right-click the Midnight project node and choose New > JSP, name the JavaServer Pages file main.

  2. Click Browse, browse to the WEB-INF/docs folder, and select it. The WEB-INF/docs folderin should now be displayed in the Folder text box. Click Finish. main.jsp opens in the Source Editor.

  3. In the Source Editor, replace the contents of the main.jsp file with the following code:
    
      <%@page contentType="text/html;charset=UTF-8"%>
      <%@page buffer="none"%>
      <%-- The <midnight:content/> tag which handles the contents section
      is simplistically implemented to use an include. Hence this page
      cannot be buffered --%>
    
      <%@taglib prefix="midnight" uri="/WEB-INF/tlds/midnight.tld"%>
    
      <html>
        <head><title>The Midnight Cookie Company</title></head>
        <body text="#996633" link="#cc6600" vlink="#993300" alink="#000000">
            <span font-style="sans-serif">
                <TABLE border="0">
    		<tr>
    		    <table border="0">
    			<tr><td width="80" height="100">&nbsp;</td>
    			    <td width="500" height="100"
    
    				text="#996633" bgcolor="#ffff99"
    				valign="center"halign="center">
    				<jsp:include page="/WEB-INF/docs/header.jsp"
    					     flush="true"/>
    			    </td>
    		        </tr>
    			<tr><td width="90" height="300"
    				text="#996633" bgcolor="#ffff99"
    				valign="top">
    				<midnight:links separator="<br>"/>
    			    </td>
    			    <td width="500" height="300"
    				valign="top"cellpadding="15"
    				cellspacing="15">
    				<midnight:content/>
    			    </td>
    		        </tr>
    		    </table>
    		</tr>
    		<tr><td width="580" height="50" text="#996633"
    			bgcolor="#ffff99" valign="top">
    			<midnight:links separator="|"/>
    		    </td>
    		</tr>
    	    </span>
    	</TABLE>
        </body>
      </html>
    
    
  4. Note: After you enter code (either by typing or copying and pasting) into the Source Editor, place the cursor in the Source Editor and press Ctrl-Shift-F to automatically reformat the code.

  5. Press Ctrl-S to save your changes.

Creating the parameter files used to handle user input

The parameter files that you create in this section illustrate the use of tags from tag libraries to handle internationalization. They also show how input is passed through the Request parameters, specifically through the JSP expression language (EL) expression ${param.input}, which is set in the input field of the Input.jsp page.

  1. Right-click the docs node and select New > Folder from the contextual menu. Type parameters in the Name text field and click Finish. The new parameters folder appears in the Projects window under the docs node.

  2. Right-click the parameters node and choose New > JSP. Notice how JSP appears on the New menu. This is because the New menu includes your most recent choices. Type Input in the JSP File Name text field and make sure that WEB-INF/docs/parameters is selected in the Folder text box. Click Finish. Input.jsp opens in the Source Editor.

  3. In the Source Editor, replace the contents of the Input.jsp file with the following code:
    
      <%@page contentType="text/html;charset=UTF-8"%>
      <%@taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt" %>
      <%@taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
      <%@taglib prefix="midnight" uri="/WEB-INF/tlds/midnight.tld"%>
    
      <fmt:setBundle basename="com.midnightcookies.Midnight" var="bundle"
    	       scope="page"/>
    
      <h3><fmt:message key="provide_input" bundle="${bundle}"/></h3>
      <form method="POST" action="Output.jsp">
            <table>
                <tr>
    		<td><fmt:message key="type_input" bundle="${bundle}"/>:<td>
    		<%-- The value of the Input field will be placed in a
    		      request parameter named "input" and it will be
    		      passed to Output.jsp --%>
    		<td><input type="text" size="20" name="input" value=""></td>
                </tr>
    	    <tr>
    		<td><fmt:message key="submit" bundle="${bundle}"
    		                 var="buttonLabel" scope="page"/>
                         <midnight:button/>
                    </td>
                    <td></td>
                </tr>
            </table>
      </form>
    
    
  4. Press Ctrl-S to save your changes.

  5. Create an Output.jsp file in the Parameters folder using the same method that you used to create the Input.jsp file.

  6. In the Source Editor, replace the contents of the Output.jsp file with the following code:
    
      <%@page contentType="text/html;charset=UTF-8"%>
      <%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt" %>
      <%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
    
      <fmt:setBundle basename="com.midnightcookies.Midnight" var="bundle" scope="page"/>
      <h3><fmt:message key="display_input" bundle="${bundle}"/></h3>
      <fmt:message key="datareceived" bundle="${bundle}"/>:
    
      <!--The following line gets the value of the request parameter named
      "input". This is a demo application. For security reasons, one should
      never echo user input without parsing first. -->
      <c:out value="${param.input}"/>
    
    
  7. Press Ctrl-S to save your changes.

Using JSTL to handle internationalization

The Tray.jsp page that you create in this section illustrates the use of the JSTL, instead of scripting, to internationalize the page. The CookieCutter.jsp file, CookieMaker.jsp file, and resource bundle property files have been provided with the midnight.zip file. You can take a closer look at those files and the Tray.jsp file for examples of how internationalization is handled in this application.

  1. Expand the docs node to expose the cookies node.

  2. Create a Tray.jsp file in the cookies folder using the same method that you used to create the other JSP files. Make sure that you put it in the cookies folder.

  3. In the Source Editor, replace the contents of the Tray.jsp file with the following code:
    
      <%@page contentType="text/html;charset=UTF-8"%>
      <%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
      <%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt" %>
    
      <fmt:setBundle basename="com.midnightcookies.Midnight" var="bundle" scope="page"/>
      <h3><fmt:message key="cookies" bundle="${bundle}"/></h3>
    
      <table border="1">
         <tr>
            <th halign="center">#</th>
    	<th align="left">
    	    <fmt:message key="name" bundle="${bundle}"/>
            </th>
            <th align="left">
    	    <fmt:message key="value" bundle="${bundle}"/>
            </th>
         <tr>
         <%-- We have to use expression to get at an array.
              If we use ${cookie} then we get a map and
              the entries are not automatically cast --%>
         <% request.setAttribute("cookies", request.getCookies()); %>
         <c:set var="i" value="0"/>
    
         <c:forEach var="ck" items="${cookies}">
    	<c:set var="i" value="${i+1}"/>
    	<tr>
    	    <td><c:out value="${i}"/></td>
    	    <td><c:out value="${ck.name}"/></td>
    	    <td><c:out value="${ck.value}"/></td>
            </tr>
        </c:forEach>
      </table>
    
          
  4. Press Ctrl-S to save your changes.

Wrapping up

Once you have completed the development stage as described above, the views in the Projects window and Files window should look as follows:

Projects window with files of completed Midnight Cookie Company application            Files window with files of completed Midnight Cookie Company application


Running and Monitoring the Application


Running the application

This step shows you how to execute the web application using the bundled Tomcat web server. If the default web server has been changed, you can make Tomcat the default server for all web applications by following the steps in Setting the Default Web Server.

  • In the Projects window, right-click the Midnight project node and choose Run Project from the contextual menu.

    A progress monitor window appears as the application is prepared and deployed to the web server.

    The web browser launches with the URL set to http://hostname:port/midnight. The following example shows the web browser running on a Microsoft Windows platform.

    Contents of web browser after the web application was executed.

    If you receive an error while trying to execute this application, see Troubleshooting Execution Problems for some possible solutions.

    The HTTP Monitor appears by default when you run a web application. The following sections illustrate how you can use the HTTP Monitor to monitor requests, sessions, and cookies.

Monitoring requests and sessions

  1. In the HTTP Monitor window, select the last entry under the Current Records node.

    The last entry represents the request for the midnight web application.

  2. Select the Request tab and you see information similar to the following.

    HTTP Monitor displaying records in the Request tab after the web application was executed.

  3. Select the Session tab and you see information similar to the following.

    Session Tab in HTTP Monitor after the web application was executed.


  4. In your web browser, click the Parameters link to display the Input.jsp page.

    Your web browser displays information similar to the following.

    Web browser displaying Input.jsp page

  5. In the Type Input text field, type hello and click Submit data.
  6. Your web browser displays the contents of the Output.jsp page, similar to the following.

    Web browser displaying Output.jsp page

  7. In the HTTP Monitor, select the last entry under the Current Records and select the Request tab.

    The HTTP Monitor displays information similar to the following.

    HTTP Monitor displaying the records in the Request tab.

Monitoring cookies

  1. In your web browser, click the Cookies link.
  2. Your web browser displays the CookieCutter.jsp page.

  3. In the Name text field, type cookie, and in the Value text field, type chocolate.

    Web browser displaying CookieCutter.jsp page with Name and Value text fields populated.

  4. Click "Make me a cookie now!".

    Your web browser displays information similar to the following.

    Web browser after entering values in the Name and Value text fields

  5. In the HTTP Monitor, select the last entry under the Current Records node.

  6. The Cookies tab in the HTTP Monitor displays information similar to the following.

    HTTP Monitor records after Cookie is made.

  7. In your web browser, click Cookie tray, and your web browser displays information similar to the following.

  8. Browser displaying the Tray.jsp page.

  9. In the HTTP Monitor, select the last entry under the Current Records node and select the Cookies tab.
  10. The HTTP Monitor displays information similar to the following.

    Cookies tab in the HTTP Monitor after Tray.jsp page is displayed.

  11. Select the Request tab and the HTTP Monitor displays information similar to the following.

    Request tab on the HTTP Monitor after Tray.jsp page is displayed.

  12. In the HTTP Monitor, right-click the same entry (GET Tray.jsp) under the Current Records node and choose Edit and Replay from the contextual menu. In the Edit and Replay dialog box, click the Cookies tab and click Add Cookie. Set the name to Ingredient and the value to Sugar. Click Send HTTP Request. The browser redisplays the page with the new cookie.

Monitoring requests for non-existent pages

  1. In your web browser, type a URL for a page that does not exist to see how the nonesuch.jsp page is used. For example, you might type http://localhost:8084/Midnight/docs/Bake.jsp for the URL and your web browser displays something similar to the following.
  2. Web browser displaying contents of nonesuch.jsp after request was made for the non-existent Bake.jsp page

  3. In the HTTP Monitor, select the Request tab and you will see information similar to the following.
  4. HTTP Monitor's Request tab after the call to non-existent Bake.jsp page.

    Notice that the content of nonesuch.jsp page is displayed in place of the non-existent Bake.jsp page.

Enabling internationalization

  1. Modify the language preference used by your web browser to either French or Swedish in order to see the internationalization feature of this Midnight Cookie Company web application.
  2. Note that you might have to add these two languages to the list of languages currently available to your web browser.

  3. Reload or refresh the pages you have viewed in the previous steps.

    Notice how the links in the left navigation bar, the links on the bottom of the pages, and the contents of some of the application's JSP pages have been translated to the language you have chosen.

    The web application uses the resource bundle property files to help translate some of the pages used in this web application. So, the translation is only as extensive as the contents of the resource bundle property files.


Troubleshooting Execution Problems

If you received an error while executing the Midnight Cookie Company application, following are some hints on some possible solutions to the problems:

You received an exception when the IDE tried to launch the browser you specified.

Check that the correct path is configured for the browser that you have specified to use with the IDE:

  1. Select Tools > Options from the main window of the IDE.

  2. Expand the IDE Configuration node and then expand Server and External Tool Settings.

  3. Select Web Browsers.

  4. Check that the correct path to your browser is set. If not, click on the browse button or type the correct path. If your default browser is Netscape 6.0 or 7.0, set the DDE Server property to have the value of NETSCAPE6.

You received a File Not Found error when attempting to display the JSP page.

If you set your web browser to use a proxy server, your web browser will attempt to route all files you want to view through the proxy server, including local files. You need to add localhost and your machine name to the list of bypassed hosts in your web browser's settings. For additional information, see the online help page entitled "Accessing Local Files Through a Proxy" in the core IDE help in the IDE. (Choose Help > Help Sets > Core IDE Help. From the Table of Contents. Expand the Configuring the Environment node and then the Using a Web Browser node.

You received a File not found error when you executed the web application.

Check the names of the JSP files you created in this tutorial. Make sure that you did not enter the .jsp file extension when you typed the name of the object in the New wizard. Rename the files, if necessary to do so.


Applying What You Have Learned


Add an Exit link that takes the user to a page that says "Goodbye" in the appropriate language

  1. Right-click the com/midnightcookies/Midnight.properties file and choose Open from the contextual menu. Add the following keywords and values.

    Keyword Default French Swedish
    exit Exit Sortie Utgång
    closingRemark Goodbye Au revoir Hej då

    Use &aring; to display the å character.

  2. Add an Exit.jsp content file. Use the message tag from the fmt tag library to display the message for the closingRemark keyword (Hint: look at Output.jsp). Don't forget to add a taglib directive for the fmt tag library.

  3. Open the com/midnightcookies/taghandlers/LinksHandler.java file in the Source Editor and add a link to the Exit.jsp file. Use the exit keyword to get the link text from the properties bundle. Compile the class.

  4. Execute the web application.

Exploring Further

Below are some other web application features that you might want to explore.

Examining the Midnight tag library

Expand the tlds/Midnight node to see the list of tags in the library. Look at the the Links tag in the Source Editor and at its Attributes to see that it takes a separator attribute.

Making frequently used tag libraries available from the IDE

Place the JSTL JAR files in a permanent place. Choose Tools > Library Manager from the main menu and add the JAR files. You can now add these tag libraries to any web application by right-clicking the project node in the Projects or Files window and choosing Properties. In the Project Properties dialog box, you can use the Compiling Sources section to make the tag library available to code completion and you can use the Packaging Project section to include the tag library in a WAR file.

Debugging web applications

Open the docs/main.jsp file in the Source Editor and set a breakpoint by clicking in the margin at the line 32 (the line that invokes midnight:content). Right-click the project node in the Projects or Files window and choose Debug Project from the contextual menu. The web application will stop at the breakpoint that you set. Press F7 to step into the code. Whenever a dialog appears because of missing source, press OK to select the default of stopping at the first line with source. Continue pressing F7 until you enter the otherDoStartTagOperations() function in the ContentHandler class. Set a breakpoint at line 50 (request.getRequestDispatcher(page).include(request, response)) and press Ctrl-F5 (continue). Place the cursor over "page", "request", and "response" to see the values. You can also see the values in the Local Variables tab. Note that the Call Stack tab shows the relationship between the JSP code and the generated servlet methods. Try setting other breakpoints. Right-click a variable and choose New Watch from the contextual menu. Click the Watches tab to see the values change as you execute the various pages in the web application. Choose Debug > Finish Session to quit the debugging session.

Testing JSP files

To run a public JSP file (one that is not under the WEB-INF folder), you simply right-click the file's node and choose Execute from the contextual menu. If a page is loaded, clicking the Browser's reload button will display any modifications that you have made. Private JSP files, like the ones in this tutorial, are a little harder to execute. One way to test a modified private JSP file without having to restart the web application and navigate to that page is to use the HTTP Monitor's replay action. Modify the docs/cookies/Tray.jsp file by setting the table's border to 10 and save your changes. In the HTTP Monitor, right-click a GET Tray.jsp record and choose Replay from the contextual menu. The Tray.jsp page should appear in the browser with a larger table border.


Glossary

Below are explanations of some of the terms used in this tutorial.

Composite View

A design pattern that is used to present information in JSP pages. This design pattern creates an aggregate view from component views. Component views might include dynamic and modular portions of the page. The Composite View design pattern pertains to web application design when you are creating a view from numerous subviews. Complex web pages frequently consist of content derived from various resources. The layout of the page is managed independently of the content of its subviews. For instance, a view might have subviews such as Navigation, Search, Feature Story, and Headline.

When creating a composite view, you can include static content and dynamic content. Static content might consist of an HTML file. Dynamic content is a fragment of a JSP page. The specific content can be determined at either JSP translation time or at runtime.

Front Controller

Front controllers are responsible for routing incoming requests and enforcing navigation in web applications. For more information on the use of the Front Controller design pattern, see the "Front Controllers" section of the Building Web Components programming series book, which is available on the documentation page of the Sun™ ONE Studio Developer Resources web site.

JSP page

Pages that are used in web applications to present information to end users and to enable data from end users to flow back to the server. JSP pages must be placed within a web application in order for the JSP pages to be executable within the IDE.

Servlet

Servlets are Java classes that execute within a servlet container, which is typically running within a web server. Servlets are used to do the following:

  • Generate dynamic content.
  • Extend the capabilities of web servers and web-enabled application servers.
  • Interact with web clients (typically a browser application such as Netscape or Internet Explorer) using a request-response paradigm

Bookmark this page

del.icio.us furl simpy slashdot technorati digg
Companion
Projects:
MySQL Database Server   Open JDK: an Open SourceJDK   GlassFish Community: an Open Source Application Server    Mobile & Embedded Community    Open Solaris   java.net - The Source for Java Technology Collaboration   Virtual Box - full virtualizer  Open ESB - The Open Enterprise Service Bus Powered by