Using File Templates to Create Java Files, Servlets, JSPs, Filters, and JSP Tag
Overview
Studio allows the user to develop EJB and web components. EJB components include Java files and EJBs, while web components include servlets and JSPs and taglibs. HTML files and images are some static components that can be written in Studio using the templates.
This document describes different file type templates in Studio.
Choosing a file type
To select a file type:
- Select File > New from the main menu.
- In the New File dialog, select from the file templates. The files that can be generated are Java, Servlet, Filter, JSP, HTML, JSP tags, EJB, JAR, WAR, EAR, Taglibs, MIDlets, and blank new file.
- Click a file type and click OK. This opens the specific dialog to create a skeleton for the selected type.
Java
Table 1:
|
Attribute
|
Option
|
Description
|
|
Class Name
|
|
The complete qualified class name followed by the class name of the Java file to be created
|
|
Source Root
|
|
Choose from the active desk EJB module or Web module
|
|
Template
|
|
Choose from the available templates
|
|
|
Default
|
Creates a Java file comprising of a class definition that encloses the entire program and the main method
|
|
|
TestFrame
|
Creates a class that extends JFrame; Imports the required swing and AWT packages; creates a basic window frame
|
|
|
ClientLookup
|
Creates a Java file that looksup a bean. In the demo code, replace the bean name with actual bean name and uncomment lookup code. Steps within the comments should be followed for the bean lookup to work
|
|
|
Interface
|
Generates home, interface templates based on the existing bean structure
|
|
|
StudioTool
|
Generates skeleton to write a tool for Studio
|
Servlet
Servlets extend the functionality of a web server and receive HTTP requests from a client, dynamically generate the response (according to programmed instructions), and send the response in an HTML or XML format to the client.
Table 2:
|
Attribute
|
Option
|
Description
|
|
Class Name
|
|
The package name followed by the class name of the Servlet file
|
|
Source Root
|
|
Choose from the active desk EJB module, or Web module
|
|
Template
|
|
Choose from available templates
|
|
|
Default
|
Creates a Servlet file which implements doGet and doPost methods
|
|
|
LoginServlet
|
Creates a Servlet file comprising of demo code that checks for the username/ password and returns a boolean value - true or false. Replace the demo Servlet URL with actual method
|
|
|
LookupServlet
|
Creates a Servlet file that looksup a bean. In the demo code, replace the bean name with actual bean name and uncomment lookup code
|
JavaServer Pages
JSP technology is an extensible technology that enables generation of dynamic content for a web client. A JSP contains HTML and XML tags to format the content; JSP tags and scriptlets to generate dynamic content in the web document.
Table 3:
|
Attribute
|
Option
|
Description
|
|
File Name
|
|
The name of the JSP file to be created
|
|
Web module
|
|
Choose from the active desk web modules
|
|
Template
|
|
Choose from the available templates
|
|
|
Default
|
Creates an empty JSP file
|
|
|
LoginJsp
|
Creates a JSP file that accepts a username/ password and confirms authenticity. Replace demo JSP URL as required and uncomment the code
|
|
|
LookupJsp
|
Creates a JSP file that looksup a bean. In the demo code, replace bean name with actual bean name and uncomments code
|
Filters
Filters are components that dynamically intercept requests and responses to transform or use the information contained in the requests or responses. Filters typically do not create responses but provide universal functions that can be attached to any type of servlet or JSP page.
Table 4:
|
Attribute
|
Option
|
Description
|
|
Class Name
|
|
Enter the fully qualified class name of the Filter in this field
|
|
Source Root
|
|
Choose from the desk EJB module, or Web module
|
|
Template
|
|
Choose from the available templates
|
|
|
Default
|
Creates a dummy implementation of javax.servlet.Filter interface
|
|
|
HitCounterFilter
|
Creates a file that counts the number of hits to a particular URL to which this filter is mapped
|
To deploy the Filter as a part of the web module:
- Right click on the Filter node in explore panel, and select Compile. This compiles and adds required information into web.xml file of the web module that stores the Filter.
- Right click on the web module and select web.xml.
- Click Filter Mappings and use Add button to add new mappings. Map the Filter to the correct URL Pattern or Servlet.
- Right click and select Deploy to deploy the web module.
HTML
HTML files comprise of tags used to design web pages. HTML files are also used by JSPs.
Table 5:
|
Attribute
|
Description
|
|
File Name
|
The name of HTML file to be created
|
|
Web module
|
Choose from the active desk web modules
|
|
Template
|
Choose from the default templates provided to create a HTML file. Creates an empty HTML file with basic tags
|
JSP Tag
JSP Tag is a piece of text between a left angle bracket and a right angle bracket that has a name, attributes, and is a part of an element in a JSP. A tag handler is a Java class that implements the Tag or BodyTag interfaces; it is the runtime representation of a custom action. The handler is a Java object that implements javax.servlet.jsp.tagext.Tag interface. It is responsible for the interaction between a JSP and server-side objects.
Table 6:
|
Attribute
|
Option
|
Description
|
|
Tag Class
|
|
Add the main class of the tag which defines the tag handler class implementing the javax.serlvet.jsp.tagext. Tag interface. This field is mandatory
|
|
TEI Class
|
|
The Tag Extra Info Class is added here. It is an optional subclass of javax.servlet.jsp.targetx.TagExtraInfo. This field is optional
|
|
Source Root
|
|
Choose from the active desk Source Roots - EJB module, Web module or Java Module
|
|
Body Content
|
|
The Tag writers explicitly specify the nature of the content of its Body here. This is primarily intended for use by page composition tools
|
|
|
tagdependent
|
The body is handled by the tag handler and is most likely in a different language. For example: embedded SQL statements. The body of the action may be empty
|
|
|
JSP
|
Selecting this option makes the body contain elements which use the JSP syntax. The body of the action may be empty
|
|
|
Empty
|
Selecting this makes the body empty
|
|
Tag Types
|
|
Specify a type of the tag to be created. It is important to understand a Tag Handler to select the tag type while creating tags
|
|
|
implements Tag
|
Implements Tag handler of the Tag interface, where Tag defines the basic methods that are needed in all tag handlers. Includes setter methods to initialize a tag handler with context data and with the attribute values of the corresponding action, and the two methods: doStartTag() and doEndTag()
|
|
|
implements Iteration Tag
|
Implements Iteration Tag and creates skeleton for methods that are inherited from Tag interface
|
|
|
implements Body Tag
|
A tag handler implementation of Body Tag interface;BodyTag provides two additional methods for when the tag handler wants to manipulate its body. The two new methods are doInitBody() and doAfterBody()
|
|
|
extends TagSupport
|
A support class that can be used as a base class
|
|
|
extends Body Tagsupport
|
A support class that can be used a base class
|
Click OK to create a folder with the tagName; The tagClassFile is created inside that folder. This file has a predefined template depending on the options chosen for generating the template.
Note: If a TEI ClassName is provided, then a template for TagExtraInfo is also created.
Creating a file template
A template is a basic framework used for writing a program with repetitive code. All templates are stored. Create a template using Studio or any other editor. To create new templates, use the following placeholders provided:
- <_AUTHOR_NAME_>: Username of the system
- <_CLASS_NAME_> : Class name of the Java file. Used in Java and Servlet templates
- <_PACKAGE_NAME_>: Key-word package and package name of the Java file. Used in Java and Servlet templates
- <_FILE_NAME_> : File name provided while creating Java, JSP, or HTML file
- <_DATE_>: The system date is inserted while creating the file
Save all templates with the extension .template and store them under respective folders as <install_dir>/templates/<file type>/<template_type.template>.