Resources

SAS® AppDev Studio 3.0 Developer's Site

Adding and Editing Servlets, JavaServer Pages, and Other Content

Once you have created your Web application project with the project wizard, it is easy to add additional servlets, JSP files and other files to your project. Select File [arrow] New to display the list of available resource types to create:

New window

After selecting the file type and filename, click OK to start a file-creation wizard that is appropriate for the file type.

Basic Versus Build-Frame Servlets

When creating a new Servlet with webAF, you choose whether to create a basic servlet or a build-frame servlet. These are the main distinguishing characteristics between the two:

 Basic ServletBuild-Frame Servlet
Initial file content auto-created? Yes - with basic doGet() and doPost() method boilerplate Yes - with handleMessage() method, plus boilerplate for SAS services support
Drag and Drop Support? No Yes - from webAF component palette
User-editable source? Yes - anywhere Partial - some blocks of code are read-only and managed by webAF

The main difference is that a build-frame servlet enables you to drag and drop components onto the editor from the palette, which triggers additional auto-code generation in the source code. The portions of the source code that are read-only have a yellow background color to distinguish them. In addition, webAF maintains another file with an .fml extension to aid in code generation. This is an XML file that should not be modified by the developer, and does not need to be distributed with the final Web application.

web.xml changes for Servlets

Regardless of whether you add a basic servlet or a build-frame servlet, webAF will automatically add the necessary declaration and servlet-mapping to the deployment descriptor. For example:

    ...
    <!-- Declare MyServlet -->
    <servlet>
        <servlet-name>MyServlet</servlet-name>
        <servlet-class>com.mycompany.mypkg.MyServlet</servlet-class>
    </servlet>
    ...
    <!-- Standard MyServlet mapping -->
    <servlet-mapping>
        <servlet-name>MyServlet</servlet-name>
        <url-pattern>/MyServlet</url-pattern>
    </servlet-mapping>

General information on writing proper servlets is beyond the scope of this document. Please consult the many books and other references available on this subject for information.

Blank Versus Tag Library JavaServer Pages

When you choose to add a new JSP file to your project, the wizard will ask you to choose a Blank JavaServer Page or a Tag Library JavaServer Page. As the name suggests, a blank JSP will initially have no source code at all. If you choose the tag library JSP, it will be initially generated with tag library declarations corresponding to the options you selected for the project. For example, if your Web application project options are JSP Standard Tag Library, SAS Runtime Classes and SAS Taglib and TBeans (Version 2), then your initial JSP file will look like this:

Editor window

If you want to create a new tag library JSP that uses a tag library you did not initially include as an option, you can add the option to the project (before creating the JSP) by selecting File [arrow] Web Application Properties. Note: You can only add the Struts tag libraries to a Web application that was created with the Struts framework template.

Even if you create a new blank JSP, you can still drag and drop tag library elements from the palette onto the editor, and webAF will automatically generate the taglib declaration if needed.

General information on writing JavaServer Pages is beyond the scope of this document. Please consult the many books and other references available on this subject for information.

See also Customizing The New File Wizard to learn how to create templates that add new file types or initial file content choices to the New File Wizard.