Creating a Struts-enabled web application in JBuilder is a multi-step process. It’s best to first design your application on paper. Determine the logical flow of the application. What view will be displayed to the user first? What action will follow that view? How will errors be handled? There are several comprehensive Struts tutorials on the web that can help you with application design and flow. Look at the links on the Jakarta Struts Resources Tutorials page at http://jakarta.apache.org/struts/ resources/tutorials.html.
Once your application design is in place, you can start using JBuilder’s tools and wizards to create it. The following steps provide a brief overview of creating a Struts-enabled web application in JBuilder.
1 Create a new project.
2 Use the WebApp wizard (File|New|Web tab|Web Application) to
create your Struts-enabled web application. Choose the Struts framework.
3 Use the JSP wizard (File|New|Web|JavaServer Page) to create the JSP page for the application’s introductory view. This is the view layer of the Struts web application.
a On the Declare JSP And Components page of the wizard, enter the JSP name. Do not select either of the options.
b On the Edit JSP File Details page, choose the background color you want for the JSP. Do not generate a Submit form. Scroll down the list of Tag Libraries until the Struts tag libraries are displayed. Choose the Struts tag libraries you will use in this JSP:
• struts-beans: Tags to display data from JavaBeans, such as data returned from a database query.
• struts-html: Tags that replace many of the common HTML elements.
• struts-logic: Tags that perform iterations and conditional processing of view data, such as presenting database data in a tabular format.
• struts-template: Tags that import snippets to JSP pages, for example, a company logo and header that are common across all pages of a website.
c You can click Finish on this page, you do not need to set options on other pages.
U s i n g t h e S t r u t s f r a m e w o r k i n J B u i l d e r 8-17
C r e a t i n g a S t r u t s - e n a b l e d w e b a p p l i c a t i o n i n J B u i l d e r
4 Add Struts-enabled tags to the JSP to design the view. For more information on building the view layer of the Struts web application, see “Building View Components” in the Struts User’s Guide at http:// jakarta.apache.org/struts/userGuide. The document also includes information about building forms with Struts and internationalizing your Struts web application. It additionally discusses other
presentation techniques, such as includes, tiles (a feature of Struts 1.1), image rendering components, and text rendering.
Note If you don’t use Struts tags in your JSP, you can use the Struts Conversion wizard to convert the HTML tags in your JSP to Struts.
5 Use the ActionForm wizard (File|New|Web tab|ActionForm) to
design the ActionForm for the view layer.
a On the Web Application And Class Info For ActionForm page of the wizard, choose the web application and package for the ActionForm. Usually, this will be the default value. Enter the name of the class. Use a name that is similar to the JSP name.
b On the Field Definition For ActionForm page, choose Add From JSP if you have already added fields to the JSP. Choose the JSP from the Add JSP dialog box. The fields and their types are automatically filled in.
c Leave the defaults set on the Select Additional Options page. The default option automatically creates the <form-bean> mapping in struts-config.xml.
d Click Finish.
6 JBuilder automatically creates getters and setters in the ActionForm, based on the field names. You do not need to edit this file. For more information on the ActionForm class, see “ActionForm classes” in the Struts User’s Guide at http://jakarta.apache.org/struts/userGuide.
7 Use the Action wizard (File|New|Web tab|Action) to create the Action for the view layer.
a On the WebApp and Name For Action page, accept the default web application, package, and base class. Change the Action name to the name you want. It should be a name that is similar to the JSP file name.
C r e a t i n g a S t r u t s - e n a b l e d w e b a p p l i c a t i o n i n J B u i l d e r
b On the Configuration Information page, leave the Action Path set to the default. Choose the form bean from the drop-down list (this is the name assigned to the ActionForm you created with the ActionForm wizard). Set the Input JSP the the JSP where control is returned to in the case of validation errors. You do not need to set either the Scope or Validate FormBean options.
c Click Finish to create the Action class.
8 Open the Action class in the editor. Add business logic to the perform() method. Once you add code to the method, you can delete the last line of the method, the error handling line. (This line will become
unreachable, as you’ve implemented the method.) For more
information on the Action class, see “Action classes” in the Struts User’s Guide at http://jakarta.apache.org/struts/userGuide.
9 Add the action mapping to the JSP, in the action element of the <html:form /> tag.
10Choose File|Save All, then choose Run|Run Project to run your project.
C o n f i g u r i n g y o u r w e b s e r v e r 9-1
C h a p t e r
9
Chapter9
Configuring your web server
Web Development is a feature of JBuilder Enterprise
Both Java servlets and JavaServer Pages (JSP) run inside web servers. Tomcat, the JavaServer Pages/Java Servlets reference implementation, is included with JBuilder. Although it might differ from your production web server, Tomcat allows you to develop and test your servlets and JSPs within the JBuilder development environment.
JBuilder Enterprise supports the Borland Enterprise Server, Sun iPlanet, IBM WebSphere and BEA WebLogic application servers. These
application servers contain web servers. However, in order to use the contained web server, you must have the corresponding application server installed and configured. You cannot use the web server outside of its application server container. Once you’ve configured your web application and web server, you can compile, run and debug your servlet and JSP. For more information, see Chapter 10, “Working with web applications in JBuilder.”
Note In JBuilder Enterprise, you can however, use the Tomcat web server as a stand-alone web server.