From 3464d4d16dc6a0040e3373e2c6799dcfc99acac4 Mon Sep 17 00:00:00 2001
From: Ted Nathan Husted Validate a user logon. Validate a user login. Log user out of the current session. Double check that there is not a valid User logon. Double check that there is not a valid User login.
<global-results>
<result name="error">/pages/Error.jsp</result>
<result name="invalid.token">/pages/Error.jsp</result>
- <result name="login" type="redirect-action">Logon!input</result>
+ <result name="login" type="redirect-action">Login!input</result>
</global-results>
index.heading=MailReader Application Options
-index.logon=Log on to the MailReader Application
+index.login=Log on to the MailReader Application
index.registration=Register with the MailReader Application
index.title=MailReader Demonstration Application
index.tour=A Walking Tour of the MailReader Demonstration Application
@@ -574,8 +574,8 @@ public class Welcome extends MailreaderSupport {
<ul>
<li><a href="<s:url action="Registration!input"/>"><s:text
name="index.registration"/></a></li>
- <li><a href="<s:url action="Logon!input"/>"><s:text
- name="index.logon"/></a></li>
+ <li><a href="<s:url action="Login!input"/>"><s:text
+ name="index.login"/></a></li>
</ul>
<h3>Language Options</h3>
@@ -693,21 +693,21 @@ public class Welcome extends MailreaderSupport {
When rendered, the Welcome page lists two menu options:
one to register with the application and one to log on (if you have
already registered).
- Let's follow the Logon link first.
+ Let's follow the Login link first.
-- If you choose the Logon link, and all goes well, the Logon action forwards - control to the Logon page. + If you choose the Login link, and all goes well, the Login action forwards + control to the Login page.
-- The Logon page displays a form that accepts a username and password. - You can use the default username and password to logon + The Login page displays a form that accepts a username and password. + You can use the default username and password to login (user and pass), if you like. Try omitting or misspelling the username and password in various combinations to see how the application reacts. @@ -722,18 +722,18 @@ public class Welcome extends MailreaderSupport { "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> - <title><s:text name="logon.title"/></title> + <title><s:text name="login.title"/></title> <link href="<s:url value="/css/mailreader.css"/>" rel="stylesheet" type="text/css"/> </head> - <body onLoad="self.focus();document.Logon.username.focus()"> + <body onLoad="self.focus();document.Login.username.focus()"> <s:actionerror/> - <s:form action="Logon" validate="true"> + <s:form action="Login" validate="true"> <s:textfield label="%{getText('username')}" name="username"/> <s:password label="%{getText('password')}" name="password"/> <s:submit value="%{getText('button.save')}"/> <s:reset value="%{getText('button.reset')}"/> - <s:submit action="Logon!cancel" onclick="form.onsubmit=null" + <s:submit action="Login!cancel" onclick="form.onsubmit=null" value="%{getText('button.cancel')}"/> </s:form> <jsp:include page="Footer.jsp"/> @@ -742,12 +742,12 @@ public class Welcome extends MailreaderSupport {
- We already saw some of the tags used by the Logon page on the Welcome page. + We already saw some of the tags used by the Login page on the Welcome page. Let's focus on the new tags.
- The first new tag on the Logon page is actionerrors. + The first new tag on the Login page is actionerrors. Most of the possible validation errors are related to a single field. If you don't enter a username, the framework can place an error message near the tag prompting you to @@ -803,10 +803,10 @@ public class Welcome extends MailreaderSupport {
<tr>
<td class="tdLabel">
- <label for="Logon_username" class="label">Username:</label>
+ <label for="Login_username" class="label">Username:</label>
</td>
<td>
- <input type="text" name="username" value="" id="Logon_username"/>
+ <input type="text" name="username" value="" id="Login_username"/>
</td>
</tr>
<s:submit action="Logon!cancel" onclick="form.onsubmit=null"
+ <s:submit action="Login!cancel" onclick="form.onsubmit=null"
value="%{getText('button.cancel')}"/>
Here we are creating the Cancel button for the form.
- The button's attribute action="Logon!cancel"
- tells the framework to submit to the Logon's "cancel" method
+ The button's attribute action="Login!cancel"
+ tells the framework to submit to the Login's "cancel" method
instead of the usual "execute" method.
The onclick="form.onsubmit=null" script defeats client-side validation.
On the server side, "cancel" is on a special list of methods that bypass validation,
@@ -911,7 +911,7 @@ public class Welcome extends MailreaderSupport {
the "validation" file.
-Logon-validation.xml
+Login-validation.xml
@@ -921,11 +921,11 @@ public class Welcome extends MailreaderSupport {
The validation framework is configured through another XML document, the
- Logon-validation.xml.
+ Login-validation.xml.
-Validation file for Logon Action
+Validation file for Login Action
<!DOCTYPE validators PUBLIC "-//OpenSymphony Group//XWork Validator 1.0.2//EN"
"http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd">
<validators>
@@ -976,19 +976,19 @@ public class Welcome extends MailreaderSupport {
-->
-Logon Action
+Login Action
- If validation passes, the framework invokes the "execute" method of the Logon Action.
- The actual Logon Action is brief, since most of the functionality derives
+ If validation passes, the framework invokes the "execute" method of the Login Action.
+ The actual Login Action is brief, since most of the functionality derives
from the base class, MailreaderSupport.
-Logon.java
+Login.java
package mailreader2;
import org.apache.struts.apps.mailreader.dao.User;
-public final class Logon extends MailreaderSupport {
+public final class Login extends MailreaderSupport {
public String execute() throws ExpiredPasswordException {
User user = findUser(getUsername(), getPassword());
if (user != null) {
@@ -1003,7 +1003,7 @@ public String execute() throws ExpiredPasswordException {
- Logon lays out what we do to authenticate a user.
+ Login lays out what we do to authenticate a user.
We try to find the user using the credentials provided.
If the user is found, we cache a reference.
If the user is not found, we return "input" so the client can try again.
@@ -1099,7 +1099,7 @@ public void setPassword(String password) {
When "findUser" returns,
- the Logon Action looks to see if a valid (non-null) User object is returned.
+ the Login Action looks to see if a valid (non-null) User object is returned.
A valid User is passed to the User property.
Although it is still a JavaBean property,
the User property is not implemented in quite the same way as Username and Password.
@@ -1213,7 +1213,7 @@ public void setSession(Map value) {
If a valid User is not found, or the password doesn't match,
the "findUser" method invokes the addFieldError method to note the
problem.
- When "findUser" returns, the Logon Action checks for errors,
+ When "findUser" returns, the Login Action checks for errors,
and then it returns either INPUT or SUCCESS.
@@ -1241,29 +1241,29 @@ public void setSession(Map value) {
- But, what happens if Logon returns INPUT instead of SUCCESS.
+ But, what happens if Login returns INPUT instead of SUCCESS.
How does the framework know what to do next?
To answer that question,
we need to turn back to the Struts configuration
- and look at how Logon is declared.
+ and look at how Login is declared.
-Logon Configuration
+Login Configuration
- The Logon action element outlines how the Logon workflow operates,
+ The Login action element outlines how the Login workflow operates,
including what to do when the Action returns "input",
or the default result name "success".
-mailreader-support.xml Logon
-<action name="Logon!*" class="mailreader2.Logon" method="{1}">
- <result name="input">/pages/Logon.jsp</result>
+mailreader-support.xml Login
+<action name="Login!*" class="mailreader2.Login" method="{1}">
+ <result name="input">/pages/Login.jsp</result>
<result name="cancel" type="redirect-action">Welcome</result>
<result type="redirect-action">MainMenu</result>
<result name="expired" type="chain">ChangePassword</result>
@@ -1275,14 +1275,14 @@ public void setSession(Map value) {
- You might notice that the name of the Logon action element is not "Logon"
- but "Logon!*".
+ You might notice that the name of the Login action element is not "Login"
+ but "Login!*".
The asterisk is a special "wildcard" notation that tells the framework to match any series
of character at this point.
In the method attribute,
the "{1}" notation indicates that framework should substitute whatever characters match
the asterisk at runtime.
- When we cite actions like "Logon!cancel" or "Logon!input",
+ When we cite actions like "Login!cancel" or "Login!input",
the framework matches "cancel" or "input" with the wildcard and fills in the blanks.
@@ -1304,19 +1304,19 @@ public void setSession(Map value) {
Using wildcards with a exclamation point (or "bang") is not the only way we can use
wilcards to invoke methods.
If we wanted to use actions like "inputLogin",
- we could move the asterisk and use an action name like "*Logon".
+ we could move the asterisk and use an action name like "*Login".
- Within the Logon action element, the first result element is named "input".
+ Within the Login action element, the first result element is named "input".
If validation or authentification fail,
the Action class will return "input" and the framework will transfer control to the
- "Logon.jsp" page.
+ "Login.jsp" page.
The second result element is named cancel.
- If someone presses the cancel button on the Logon page,
+ If someone presses the cancel button on the Login page,
the Action class will return "cancel", this result will be selected,
and the framework will issue a redirect to the Welcome action.
@@ -1324,7 +1324,7 @@ public void setSession(Map value) {
The third result has no name,
so it will be called if the default success token is returned.
- So, if the Logon succeeds,
+ So, if the Login succeeds,
control will transfer to the MainMenu action.
@@ -1397,7 +1397,7 @@ public void setSession(Map value) {
- Finally, the Logon action specifies an InterceptorStack
+ Finally, the Login action specifies an InterceptorStack
named defaultStack.
If you've worked with Struts 2 or WebWork 2 before, that might seem strange,
since "defaultStack" is the factory default.
@@ -1406,7 +1406,7 @@ public void setSession(Map value) {
In the MailReader application, most of the actions are only available
to authenticated users.
- The exceptions are the Welcome, Logon, and Register actions
+ The exceptions are the Welcome, Login, and Register actions
which are available to everyone.
To authenticate clients,
the MailReader uses a custom Interceptor and a custom Interceptor stack.
@@ -1444,7 +1444,7 @@ public class AuthenticationInterceptor implements Interceptor {
If so, it returns normally, and the next Interceptor in the set would be invoked.
If the User object is missing, the Interceptors returns "login".
The framework would match "login" to the global result,
- and transfer control to the Logon action.
+ and transfer control to the Login action.
@@ -1519,7 +1519,7 @@ public class AuthenticationInterceptor implements Interceptor {
Because the default interceptor stack will now authenticate the client,
we need to specify the standard "defaultStack" for the three
- "guest actions", Welcome, Logon, and Register.
+ "guest actions", Welcome, Login, and Register.
Requiring authentification by default is the better practice, since it
means that we won't forget to enable it when creating new actions.
Meanwhile, those pesky users will ensure that we don't forget to disable
@@ -1529,7 +1529,7 @@ public class AuthenticationInterceptor implements Interceptor {
MainMenu
- On a successful logon, the Main Menu page displays.
+ On a successful login, the Main Menu page displays.
If you logged in using the demo account,
the page title should be "Main Menu Options for John Q. User".
Below this legend should be two links:
@@ -1575,8 +1575,8 @@ public class AuthenticationInterceptor implements Interceptor {
<s:text name="mainMenu.registration"/>
</a>
</li>
- <li><a href="<s:url action="Logoff" />">
- <s:text name="mainMenu.logoff"/>
+ <li><a href="<s:url action="Logout" />">
+ <s:text name="mainMenu.logout"/>
</a>
</ul>
</body>
@@ -1602,7 +1602,7 @@ public class AuthenticationInterceptor implements Interceptor {
The customized MainMenu page offers two standard links.
One is to "Edit your user registration profile".
- The other is to "Logoff the MailReader Demonstration Application".
+ The other is to "Logout the MailReader Demonstration Application".
Registration page
@@ -2054,7 +2054,7 @@ public Subscription findSubscription(String host) {
Likewise, the AuthentificationInterceptor will ensure that only clients
with a valid User object can try to edit a Subscription.
If the session expired, or someone bookmarked the page,
- the client will be redirected to the Logon page automatically.
+ the client will be redirected to the Login page automatically.