# Creating JavaServer Pages (JSP) files

You can create and edit a JSP file, HTML file, or JSP tagging. This includes placing Java™ source code inside of scriptlet tags.

Most types of JSP files can be created using the New JSP File wizard.
To create a basic JSP file using the JSP file wizard, complete the following steps:

1. Create a dynamic Web project if you have not already done so.
2. Open the Web perspective.
3. Select the Web project, and then select File > New > JSP File. The New JSP File window appears.
4. Select the Browse button and select an appropriate container for the file from the list of project folders (and subfolders).

   The folder that you choose should be under the Web content folder of a dynamic Web project. If a JSP file is not under this folder, then it will not be included in the WAR file that is deployed to the server. In addition, link validation will not encompass files that are not under the Web content folder.

5. Type a file name into the appropriate field.
6. Ensure that the appropriate option is displayed in the Markup language drop-down list. Note that the option you choose will determine the model of JSP that appears in the Model pull-down list.

   In addition, if you select the Create as JSP fragment check box, this file will be created as a fragment that can be added to another JSP file. Other JSP files can include JSP fragments using a JSP include directive. Creating a fragment causes the resulting file to end in a .jspf or .jsf extension. You will not be prompted for DOCTYPE information, because a fragment cannot stand alone as a Web page, and it would invalidate any JSP file that included it.

   Also, depending on the markup language you select, you can select the Use XML style syntax option to create a JSP file that adheres to XML style tagging.

7. You have several options for proceeding: (Note that the windows that appear in this wizard are determined by the options that you select)
   - To accept the defaults associated with a new JSP file, select None in the Model drop-down list, and then select Finish.
   - To use one of the sample templates provided, select Create from page template, and then select Next. (Note that this is only available for HTML and XHTML markup languages.) If you choose this option, a window appears in which you can choose a sample template or a user-defined template.
   - If you want to specify or customize the file options, select the Configure advanced options check box and click Next.
8. Click the Add button to locate a Tag Library Descriptor (TLD) file or a JAR file that contains a TLD file to add tag libraries from a variety of sources.

   Tag library Universal Resource Identifier (URIs) can be located in one of the following places:

   - Defined in the web.xml file
   - Within a JAR file located in the project lib directory that contains /META-INF/taglib.tld
   - Within a JAR file external to the project
   - In a "loose" TLD anywhere in the project
   1. In the Select a tag library dialog, either select one of the available tag libraries, or click the Import button to locate and add a tag library to the list, and then select it. The dialog will automatically populate the informational fields that describe the tag library and its contents. You must specify a Prefix value.
   2. Click OK to add the tag library. Note that if the selected TLD files hasn't been registered in the web.xml file, it will be added automatically.
9. Click Next.
10. If you want to select an encoding type, deselect the Use workbench encoding check box to select a new encoding attribute. Select the appropriate encoding value to add to the file's HTML declaration from the Encoding drop-down list. The default is the value set in the HTML Files preferences page, which is accessed by selecting Window > Preferences, and then expanding the Web and XML Files preferences.
11. Ensure that the proper content type is selected in the Content Type drop-down list. The default depends on the markup language.
12. Select the Document Type that you wish to associate with the JSP file. The default depends on the markup language.
13. Specify a cascading style sheet (CSS) file to be referenced by the new JSP file. Typically, CSS files are located in the theme folder under the Web content folder. You can use Add to choose a style sheet from the file system. Use Remove to delete a style sheet from the list, or use the arrow buttons to rearrange the order in which the file references the style sheets. If a style sheet is already associated with the project in which you are creating the new file, that style sheet is the default.
14. Click Next to select specific method stubs and add deployment information to the Web project's web.xml file.

    Select any appropriate method stubs to be created in the servlet that is deployed for this JSP file.

    If you select the Add to web.xml check box, the JSP file, along with its display name, and any URL mappings and initialization parameters associated with the JSP file will be automatically included in the Web project deployment descriptor file. Note that the File Name value provided in the first page of the wizard is automatically mapped to the Servlet Name value on this page, as well the URL Pattern mappings. These mappings are not updated if you change the original value in the File Name field.

15. Click Finish to create the file in the project that you have selected.

Related concepts
JavaServer Pages (JSP) technology

Related tasks
Creating a dynamic Web project

(C) Copyright IBM Corporation 2000, 2005. All Rights Reserved.