Previous Next |
Struts and EclipseWe'll start by taking a look at the Struts example we're going to create using Eclipse, using the latest version of Tomcat available (Version 4.1.29 as of this writing), and the latest version of Struts (Version 1.1). When you navigate to the opening JSP, http://localhost:8080/Ch10_01/Ch10_01.jsp, you'll see a menu with a number of HTML controls, as appears in Screenshot-1. Screenshot-1. The opening view of the Struts app![]() The user can order a pizza or sandwich using the controls here and can also include his email address. Clicking the "Place your order" button sends the data in the form to an underlying bean and to the app's controller servlet, which displays a summary of the order, as you see in Screenshot-2. Although these results look pretty simple, that's not to say that the implementation of this app is easy. Struts is not a lightweight framework; to create this example, you use these files, arranged in the Tomcat webapps/Ch10_01 directory: webapps | |_ _Ch10_01 | Ch10_01.jsp [View: Starting form] | Ch10_05.jsp [View: Summary form] | |_ _WEB-INF | struts-config.xml [Struts Configuration File] | Ch10.tld [Custom Tag Definitions] | Struts TLD files [Struts Tag Definitions] | web.xml [app Descriptor File] | |_ _lib | struts.jar [Java Archive of Struts Classes] | |_ _classes | appResources.properties [Contains property data] | |_ _org | |_ _eclipsebook | |_ _ch10 |_ _Ch10_02.class [Custom Tag 1 Implementation] Ch10_03.class [Custom Tag 2 Implementation] Ch10_04.class [Controller: Action servlet] Ch10_06.class [Model: Form bean] Screenshot-2. The Struts app's summary![]() The next step is to create this app using Eclipse. To follow along, create a simple Java project named Ch10_01, and create a new folder in the Tomcat webapps directory, Ch10_01. To get access to this folder in Eclipse, create a new folder by right-clicking the project and selecting New deployment | |_ _WEB-INF | |_ _lib | |_ _classes To handle the compiled output of this project, select the Project
You'll also need these Struts .tld (Tag Library Definition files) from the download in the app's WEB-INF directory; these files support the custom tags that Struts uses:
To get started with the code for this example, right-click the new folder and select New |
Previous Next |