Declaration: This is a demonstration of how to create a struts ApplicationProgram. The implementation of such specifications and details comes from one project. It may be very different from the project framework you work on, but it may have something in common. In order to write more projects and software, let's look at an example to understand this title, including the structure analysis and System Description (ISBN 0138543801) by Tom DeMarco and the implementation by Steve McConnell.Code"(ISBN 1556154844 ).
Example application-sample description
Problem definition
Solution
Requirement Analysis
Core tasks
Other requirements
Screen stream example
Welcome Page
Registration page
Login Page
Menu item
Account
Account description
Exit page
Product selection
Application Interface
--------------------------------------------------------------------------------
1.0 problem definition
Many people have many email accounts on the mail server, but some cannot manage these accounts well. Login portals for private and public mail servers generally only allow users to log on.
--------------------------------------------------------------------------------
2.0 solutions
These problems can be solved through the website login program. This program allows users to register a series of email account and account descriptions of any network mail server over the network, and can also re-view them.
--------------------------------------------------------------------------------
3. 0 Requirement Analysis
3.1 core tasks
Register a new account with your username and password
Log in to the registered account through a browser
Add an email account description
View the description of an email account
Log out
3.2 Other requirements
The authorized email server can create multiple accounts.
The account information page cannot be displayed to unauthorized users.
In order to have a broad user base, this program should be able to meet the needs of users in different languages.
We should be able to modify the browsing page without re-compiling the application.
--------------------------------------------------------------------------------
4.0 view Process
4.1 welcome page
Register a new account {register}
Log on to the registered account {login}
4.2 Registration
The registration attribute form is displayed. Options: Save, reset, and cancel.
Form field: username, password, password (confirm), full name, from address, reply to address.
Save: Verify the form attributes; return the suggestions for the user or store the menu displayed after successful login
Verification: The password must be consistent with the repeated password; the email source and reply address must comply with the email address writing rules (must contain the @ symbol). The reply address is optional, none of them can be blank and must comply with other authentication rules. The user name must be unique.
If the registration is successful: {menu}
If the registration fails: {register}
Reset: resumes the edited content.
Cancel: Jump to {login .}
4.3 Login
Display the form information for the login user, and select "save" or "reset.
Form: username and password ).
Save: Verify the login information. Both are required and must be the same as the registration information (case sensitive ).
Cancel: Cancel editing
4.4 Main Menu
Add/Edit Account description {account }.
Exit {welcome }.
4.5 account
Display the form to edit user registration information (see the register view ).
The description of the account is displayed in the list. You can select "edit" or "delete" to view the description of the account {subdomains }.
The list must contain host names and other attributes (if there is extra space)
Select "add" for the new account description {subscribe }.
4.6 account description-add, edit, and delete)
Lists the account description attributes. You can select "add", "edit", and "delete" (add, edit, delete ).
Optional "add" and "edit" execution tasks: Save, reset, and cancel (save, reset, and cancel ).
Optional "delete" execution task: "OK", "cancel" (confirm, cancel ).
Form field: Mail Server, user name, password, and mail server type ).
Save: Verify the account description attribute; return suggestions for users or display updated accounts.
Verification form field: automatic connection may return NULL (false), and all other attributes must be non-empty.
If it is successfully saved: {account }.
Failed to save: {subparts }.
Reset: Cancel editing.
Cancel: Return to the {account} view.
Confirm (delete): confirm the deletion record; display the updated information {account .}.
4.7 exit
Invalidate user login information; return to the welcome page.
--------------------------------------------------------------------------------
5. 0 product selection
We chose the Java Struts framework to implement this project.
Its design is described as an easy-to-write and scalable Web application;
The MVC mode makes the application easy to maintain;
JSP is used to display the part. You do not need to re-compile the program for all modification operations;
Allows you to customize operations through web programs;
Supports international applications.
--------------------------------------------------------------------------------
6.0 Application Interface
6.1 attributes
Tag component property type rule 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
Sub‑host string! Null unique
Mail Username
Subscribe username string! Null
Mail Password sub‑password string! Null
Mail Server Type subpartition type string "IMAP", "POP3"
Password (Repeat) registrationform password2 string! Null
--------------------------------------------------------------------------------
6. 3 form beans)
<Form-beans>
<! -- Logon form bean login form component -->
<Form-bean name = "logonform"
Type = "org. Apache. Struts. example. logonform"/>
<! -- Registration Form bean registry single component -->
<Form-bean name = "registrationform"
Type = "org. Apache. Struts. example. registrationform"/>
<! -- Subterraform bean account description component -->
<Form-bean name = "subscriptionform"
Type = "org. Apache. Struts. example. subscriptionform"/>
</Form-beans>
--------------------------------------------------------------------------------
6. 4 Action ings)
6. 4.1 examples of core execution task ing
Create an account based on the user name and password
Link to "editregistration. do? Action = create"
Submit the form to "actoin = saveregistration. Do"
Log information to account
Open "login. jsp" -- the input file is "login. Do"
Submit the input form from "Action =" Logon. do ""
Add email account description
Link to "/editsubtasks. do? Action = create & User = {user }"
Username = Username
Submit the input form to "Action =" savesubject. Do"
Refer to the linkuser User custom tag.
Edit Account description
Link to "editsubtasks. do? Action = edit & username = {user} & host = {Host }"
Username = Username
Host = Mail Server
Let the changes and commits to "savesubtasks. Do"
Hide form fields: "Action = edit"
See linksubscribe custom tags.
Delete account description
Link to "editsubtasks. do? Action = Delete & username = {user} & host = {Host }"
Username = Username
Host = Mail Server
Ask the user to confirm whether the deletion is deleted. If the deletion is submitted to action = "savesub.pdf. Do"
Hide form fields: "Action = Delete"
See linksubscribe custom tags.
Exit
Link to "/logoff. Do"
The page cannot be displayed to unauthorized users.
See checklogin custom tags.
--------------------------------------------------------------------------------
6. 4.1 action configuration)
<Action-mappings>
<! -- Process a User Logon Processes user login -->
<Action Path = "/logon"
Type = "org. Apache. Struts. example. logonaction"
Name = "logonform"
Scope = "request"
Input = "/logon. jsp">
</Action>
<! -- Edit user registration information -->
<Action Path = "/editregistration"
Type = "org. Apache. Struts. example. editregistrationaction"
Name = "registrationform"
Scope = "request"
Validate = "false">
<Forward name = "success" Path = "/registration. jsp"/>
</Action>
<! -- Save User registry to Save User Registration Information -->
<Action Path = "/saveregistration"
Type = "org. Apache. Struts. example. saveregistrationaction"
Name = "registrationform"
Scope = "request"
Input = "/registration. jsp"/>
<! -- Edit mail subaccount edit mail account description -->
<Action Path = "/editsubtasks"
Type = "org. Apache. Struts. example. editsubscriptionaction"
Name = "subscriptionform"
Scope = "request"
Validate = "false">
<Forward name = "failure" Path = "/mainmenu. jsp"/>
<Forward name = "success" Path = "/subscribe. jsp"/>
</Action>
<! -- Save mail subscribe to save the email account description -->
<Forward name = "success" Path = "/editregistration. do? Action = edit "/>
</Action>
<! -- Process a user logoff process user exit -->
<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 application tag
This application uses the following custom tag with "app" as the Tag Name:
APP tag-<% @ taglib uri = "/WEB-INF/APP. TLD" prefix = "app" %>
Label Name Description
Checklogin checks whether a valid user logs on to the current session. If no user's session information is displayed, the logon page is displayed.
Linkuser generates the URL encoding pair path, including the query parameters selected by the user.
Linksubhandler generates the URL encoding pair path, including the query parameters selected by the user.
--------------------------------------------------------------------------------
Checklogin
Attribute Name Description
No attribute
--------------------------------------------------------------------------------
Linkuser
Attribute Name Description
Page wraps user information to the Request Path, for example: "/editsubtasks. do? Action = create ".
Package user account information to the Request Path. For example, the user name is "user ":
<A href = "/Struts-example/editsubtasks. do? Action = create & username = user ">
--------------------------------------------------------------------------------
Linksubtasks
Attribute Name Description
The Action Description value of the page user, for example: "/editsubscribe. do? Action = edit ".
Package the user's Action Description value and user account information to the Request Path. For example, the user name is "user" and the description account is "mail.yahoo.com "":
<A href = "/Struts-example/editsubtasks. do? Action = edit & username = user & host = mail.yahoo.com ">
--------------------------------------------------------------------------------
6.3.2 struts custom tag
This application uses the tag library and description name defined by struts as follows:
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" %>
--------------------------------------------------------------------------------
Vi. 4. Default Page Actions
Page component action
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)
Registrationform action = "saveregistration. Do"
Page = "/editsubtasks. do? Action = Delete"
Page = "/editsubtasks. do? Action = edit"
Page = "/editsubtasks. do? Action = create"
Subusers. jsp user (Session)
Subscriptionform action = "savesubject. Do"
--------------------------------------------------------------------------------
6.5 Internationalization
See <classes/org/Apache/struts/example/applicationresource. Properties>.
The application uses this file to contain all Error Descriptions and text information.
Other languages can support this by translating this file.
The application automatically selects this property file to locate the language used by the user.
--------------------------------------------------------------------------------
Ted husted is a free software consultant who provides developer training, code refactoring, and secret support. For more information, visit the website husted dot com.