JSP in Dreamweaver MX

Team-Fly    

Macromedia® DreamWeaver® MX Unleashed
By Matthew Pizzi, Zak Ruvalcaba
Table of Contents
Chapter 23.  JSP


Dreamweaver MX supports hand coding of JSP in your files, but it also has some handy tools that can make you more productive.

  • The Tag Chooser helps you insert well-formed JSP tags into your documents. The Tag Chooser displays different parameters required by the JSP tag, so you can be sure to enter them properly.

  • Includes allow you to place repeatable HTML snippets into separate pages that you can then include from other pages in an application.

  • You can save JSP code into Code Snippets that you can use in your application. Code Snippets are saved in a kind of library to use a snippet, just select it and insert it into your code.

Tag Chooser

You can access the Tag Chooser by clicking the Tag Chooser button on the toolbar or by right-clicking inside your Dreamweaver document and choosing Insert Tag from the pop-up menu (see Figure 23.1).

Figure 23.1. The Tag Chooser can help you insert well-formed JSP tags into your HTML documents.

graphics/23fig01.jpg

To use the JSP tags, click the JSP Tags folder. This folder is organized in the following manner:

  • Directives, which lists the three in-page directives (page, include, and taglib) available in JSP.

  • Scripting elements include declarations (for defining methods and variables), expressions (for generating output), and scriptlets (free-form JSP).

  • Standard actions, which include everything you need to work with JavaBeans and perform page forwarding and other tasks.

To insert one of these elements into your HTML code, double-click it, fill in the required parameters as provided by the Tag Chooser, click OK, and then click Insert (see Figure 23.2).

Figure 23.2. Creating a <jsp:forward> action with the Tag Chooser.

graphics/23fig02.jpg

For more information on each of these items, refer to the "Hand Coding JSP Tags" section later in this chapter.

Includes

Server-side includes enable you to place repeated chunks of HTML and JSP into their own files. You can then reference those files using a server-side include from another file. Although you will notice a small hit on performance, it's usually negligible compared to the time and effort spent making the same updates to dozens and dozens of pages.

To insert an include in Dreamweaver MX, follow these steps:

  1. Choose Insert, Script Objects, Server-Side Include.

  2. Browse the file folder structure and select the file you want to include.

NOTE

If you are using Apache, make sure that the resulting code looks like this:

 <!--#include virtual="file.inc" -->  

And not like this:

 <!--#include file="file.inc" -->  

Do just the opposite on IIS.


TIP

Some Web servers are configured to scan for server-side includes automatically, and others check only for files with a special extension, such as .shtml or .inc. If Tomcat is configured properly on your system, you shouldn't have any problems.


Refer to the "Hand Coding JSP Tags" section to learn about the <jsp:include> tag and the <%@ include %> directive.

Saving Code Snippets

Dreamweaver MX enables you to save any content, HTML markup, or JSP code as Code Snippets that you store in the Snippets library.

To save a piece of JSP code as a snippet, follow these steps:

  1. Highlight the JSP code you want to save as a Snippet.

  2. Click the Snippets tab under Code in the right pane.

  3. Click the Create New Folder icon.

  4. Name the new folder JSP Snippets.

  5. Double-click the folder to open it.

  6. Click the Create New Snippet icon.

  7. In the Snippet dialog box, give your snippet a name that's descriptive of the code.

  8. Optionally, provide a description of the code.

  9. Choose Insert Block (this works for most JSP code blocks) instead of Wrap Selection.

    NOTE

    Wrap Selection is used to wrap code before and after any selection you've highlighted with the mouse. It's a handy way to wrap <b> and </b> tags around a word you've highlighted, but it isn't very useful when you're inserting JSP code.

  10. Choose Code as the Preview Type.

  11. Click OK to close the dialog box.

To use a Code Snippet, click where you want the snippet to go and then double-click it from the list of snippets. Dreamweaver MX inserts the snippet into your document.


    Team-Fly    
    Top


    Macromedia Dreamweaver MX Unleashed
    Macromedia Dreamweaver MX 2004 Unleashed
    ISBN: 0672326310
    EAN: 2147483647
    Year: 2002
    Pages: 321

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net