Home Struts new Hot Jobs new
Disclaimer: This is a bare-bones sample specification to illustrate building a Struts application. The format and detail provided by a specification varies from project to project. The specification for your project may look very different, but may still have these basic elements in common. For more about writing project specifications and constructing software, see one of the many comprehensive texts on this topics, including Structured Analysis and Systems Specifications by Tom DeMarco (ISBN 0138543801) and Code Complete by Steve McConnell (ISBN 1556154844).
Example Application - Sample Specification
- Problem Definition
- Proposed Solution
- Requirements
- Core tasks
- Other requirements
- Sample Screen Flow
- Welcome
- Register
- Login
- Menu
- Account
- Subscription
- Logout
- Product Selection
- Application Program Interface
1.0 Problem Definition
Many people have email accounts on various servers. Some email clients do not handle multiple accounts well. Private and public email portals and gateways usually allow accounts only on their own servers.
2.0 Proposed Solution
These problems could be solved by a "portal" Web application that would allow users to register a set of email subscriptions for any Internet mail server, and then retrieve mail for these subscriptions.
3. 0 Requirements
3.1 Core tasks
- Create an account with a username and password
- Log into that account from any Web browser
- Add email subscriptions to that account
- Retrieve mail for that account
- Logout
3.2 Other requirements
- Authorization must not require an account on the application's server.
- Pages that require account information must not be displayed to unauthorized users.
- To reach the widest audience, the application should be able in multiple languages.
- We should be able to modify the browser pages without recompiling the application.
4.0 Sample Screen Flow
4.1 Welcome
4.2 Register
Display form with registration properties; options to Save, Reset, and Cancel.
- Form: Username, Password, Password (confirm), Full Name, From Address, Reply To Address.
- Save: Validate registration properties; either return to user with advice, or store and display Menu
- Reset: Undo edits
- Cancel: Proceed to { Login. }
4.3 Login
Display form to login user account, with options to Save or Reset.
- Form: Username, Password.
- Save: Validate login, both fields required, and must match stored registration (case-sensitive).
- Reset: Undo edits.
4.4 Menu
4.5 Account
- Display form to edit registration properties (see Register screen).
- List subscriptions in table; options to Edit or Delete { Subscription }.
- Columns must include Hostname, with other properties listed as space permits
- Option to Add (another) subscription { Subscription }.
4.6 Subscription - Add, Edit, Delete.
Display form with subscription properties; options appropriate to task (Add, Edit, Delete).
- Options for Add, Edit Tasks: Save, Reset, Cancel.
- Options for Delete Task: Confirm, Cancel.
- Form: Mail Server, Mail Username, Mail Password, Mail Server Type.
- Save: Validate subscription properties; either return to user with advice, or store and display updated Account.
- Validations: Auto Connect may be blank (false), all other properties must be non-blank.
- If succeeds: { Account }.
- If fails: { Subscription }.
- Reset: Undo edits.
- Cancel: Return to { Account } screen.
- Confirm (deletion): Confirm: Delete record; display updated { Account. }.
4.7 Logout
Invalidate user's login; return to Welcome screen.
5. 0 Product Selection
Java using the Struts Framework is selected for the project since
- It is specifically designed for writing flexible, portable, and scalable Web applications;
- It follows the Model-View-Controller pattern, which can make the application easier to maintain;
- It uses JavaServer Pages for displays, which can be modified without recompiling application;
- It supports authorizing users from within the Web application; and
- It supports internationalizing applications.
6.0 Application Program Interface
6.1 Properties
Label Bean Property Type Restrictions Domain Username User username String !null unique Password User password String !null Full Name User fullname String !null From Address
User fromAddress String !null *@* Reply To Address
User replyToAddress String - User subscriptions Hashtable Mail Server
Subscription host String !null unique Mail Username
Subscription username String !null Mail Password Subscription password String !null Mail Server Type Subscription type String "imap","pop3" Password (repeat) registrationForm password2 String !null
6. 3 Form Beans
<form-beans>
<!-- Logon form bean -->
<form-bean name="logonForm"
type="org.apache.struts.example.LogonForm"/>
<!-- Registration form bean -->
<form-bean name="registrationForm"
type="org.apache.struts.example.RegistrationForm"/>
<!-- Subscription form bean -->
<form-bean name="subscriptionForm"
type="org.apache.struts.example.SubscriptionForm"/>
</form-beans>
6.4 Action Mappings
6.4.1 Example Mappings for Core Tasks
Create an account with a username and password
- Link to editRegistration.do?action=Create
- Submit form to "actoin=saveRegistration.do"
Log into account
- Open "login.jsp" -- the input file for login.do
- Submit input form to "action="logon.do"
Add email subscriptions
- Link to "/editSubscription.do?action=Create&user={user}"
- username = Username
- Submit input form to "action="saveSubscription.do"
- See also linkUser custom tag.
Edit subscription
- Link to "editSubscription.do?action=Edit&username={user}&host={host}"
- username = Username
- host = Mail Server
- Make changes on input form and submit to "saveSubscription.do"
- with hidden field: "action=Edit"
- See also linkSubscription custom tag.
Delete subscription
- Link to "editSubscription.do?action=Delete&username={user}&host={host}"
- username = Username
- host = Mail Server
- Confirm deletion, which submits to action="saveSubscription.do"
- with hidden field: "action=Delete"
- See also linkSubscription custom tag.
Logout
Pages that require account information must not be displayed to unauthorized users.
- Link to "/logoff.do"
- See checkLogin custom tag.
6.4.1 Actual Configuration
<action-mappings>
<!-- Process a user logon -->
<action path="/logon"
type="org.apache.struts.example.LogonAction"
name="logonForm"
scope="request"
input="/logon.jsp">
</action>
<!-- Edit user registration -->
<action path="/editRegistration"
type="org.apache.struts.example.EditRegistrationAction"
name="registrationForm"
scope="request"
validate="false">
<forward name="success" path="/registration.jsp"/>
</action>
<!-- Save user registration -->
<action path="/saveRegistration"
type="org.apache.struts.example.SaveRegistrationAction"
name="registrationForm"
scope="request"
input="/registration.jsp"/>
<!-- Edit mail subscription -->
<action path="/editSubscription"
type="org.apache.struts.example.EditSubscriptionAction"
name="subscriptionForm"
scope="request"
validate="false">
<forward name="failure" path="/mainMenu.jsp"/>
<forward name="success" path="/subscription.jsp"/>
</action>
<!-- Save mail subscription -->
<action path="/saveSubscription"
type="org.apache.struts.example.SaveSubscriptionAction"
name="subscriptionForm"
scope="request"
input="/subscription.jsp">
<forward name="success" path="/editRegistration.do?action=Edit"/>
</action>
<!-- Process a user logoff -->
<action path="/logoff"
type="org.apache.struts.example.LogoffAction">
<forward name="success" path="/index.jsp"/>
</action>
</action-mappings>
6.3 Custom Tags
6.3.1 Example Application Tags
This application uses the following custom tags with an app prefix:
App tags - <%@ taglib uri="/WEB-INF/app.tld" prefix="app" %>
Tag Name Description CheckLogin Check for a valid User logged on in the current session. If there is no such user, forward control to the logon page. LinkUser Generate a URL-encoded hyperlink to the specified URI, with associated query parameters selecting a specified User. LinkSubscription Generate a URL-encoded hyperlink to the specified URI, with associated query parameters selecting a specified Subscription.
CheckLogin Attribute Name Description No Attributes
LinkUser Attribute Name Description page Action to use with User key, for example "/editSubscription.do?action=Create".
This tag will then generate a hyperlink target that appends the key to the user's account.
For example given a username of "user":
<a href="/struts-example/editSubscription.do?action=Create&username=user">
LinkSubscription Attribute Name Description page Action to use with User and Subscription keys, for example "/editSubscription.do?action=Edit".
This tag will then generate a hyperlink target that appends the keys to the user and the subscription.
For example given a user with the name "user" and subscription with a host of "mail.yahoo.com"":
<a href="/struts-example/editSubscription.do?action=Edit&username=user&host=mail.yahoo.com">
6.3.2 Struts Custom Tags
With this application, the following Struts tags libraries and prefixes are used:
Bean tags - <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
HTML tags - <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
Logic tags - <%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
6.4 Page Action Index
Page Beans Actions index.jsp None page="/editRegistration.do?action=Create"
page="/logon.jsp"logon.jsp logonForm action="logon.do" mainMenu.jsp user (session) page=/editRegistration.do?action=Edit"
page="/logoff.do"registration.jsp user (session)
registrationFormaction="saveRegistration.do"
page="/editSubscription.do?action=Delete"
page="/editSubscription.do?action=Edit"
page="/editSubscription.do?action=Create"subscription.jsp user (session)
subscriptionFormaction="saveSubscription.do"
6.5 Internationalization
See < classes/org/apache/struts/example/ApplicationResource.properties >.
This file includes all error messages and text used through the application.
Additional languages can be supported by translating this file.
The application will automatically choose the language appropriate to a visitor's locale.