You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Anjib Mulepati <an...@hotmail.com> on 2012/06/13 15:03:12 UTC

Form handling by direct URL in Struts 1.3.8

Hi All,

I have question regarding handling form submission by direct URL in 
Struts 1.3.8

I have a page to change password which user can access after they login. 
URL for that page is http://localhost:8080/MyApp/changepassword.do

I have action mapping as follow:
<action path="/changepassword" input="changePasswordPage" 
scope="request"  name="ChangePasswordForm" 
type="com.anjib.actions.ChangePasswordAction">
<forward name="success" path="changePasswordPage" />
<forward name="failure" path="changePasswordPage"/>
</action>

I have tile definition for changePasswordPage which have page like 
header which display welcome information after user login
<div id="welcome" class="right">
<bean:message key="label.welcome" />
<logic:notEmpty name="userInfo" property="firstName">
          ${userInfo.firstName}&nbsp;${userInfo.lastName}
</logic:notEmpty>
<logic:empty name="userInfo" property="firstName">
             ${userInfo.userName}
</logic:empty>
</div>

Now everything works fine if we follow normal process: Login and do 
actions. But if someone type URL 
http://localhost:8080/MyApp/changepassword.do directly then I don't get 
page and I have error in Tomcat log
Caused by: javax.servlet.jsp.JspException: Cannot find bean: "userInfo" 
in any scope

Any help will be appreciated.

Thanks,
Anjib






---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Form handling by direct URL in Struts 1.3.8

Posted by Takanori Hayashi <th...@na.rim.or.jp>.
PS
In that case, forward to another JSP on that file userInfo information 
should not be used.

(2012/06/15 9:10), Takanori Hayashi wrote:
> Hello Anjib,
>
> Assumed that you made the distinction on validate method,
> then if forwarded JSP page is using userInfo session like
> <logic:empty name="userInfo" property="firstName">
>             ${userInfo.userName}
> </logic:empty>
> the same error  is shown.
> [Caused by: javax.servlet.jsp.JspException: Cannot find bean: 
> "userInfo" in any scope ]
> Because you are using "not existing userInfo" at the JSP.  The problem 
> is JSP using userInfo being there.
>
> Takanori
>
> (2012/06/14 22:29), Dave Newton wrote:
>> On Thu, Jun 14, 2012 at 9:18 AM, Anjib Mulepati<an...@hotmail.com>  
>> wrote:
>>
>>> I don't think problem is mapping correct page from Action class. If you
>>> look into my initial code posting /changepassword need form 
>>> validation so
>>> it calls the validate() method and since there is no data it fails. 
>>> I have
>>> input="changePasswordPage" which takes to the tile where it look for 
>>> the
>>> session variable.
>>> My problem I don't a mechanism where if some one POST the empty data
>>> validation fail must lead to not login message or invalid access 
>>> message.
>>> How can I make such distinction from normal form submission?
>>>
>> You don't *need* to make that distinction, although you *may*.
>>
>> You still have the same options as before:
>>
>> 1. A userInfo object in session, or
>> 2. Don't read userInfo properties if it's *not* in session.
>>
>> For (1), you *could* just keep a dummy/default "not-logged-in" 
>> userInfo in
>> session, and replace it with a real on on login (and go back to the
>> dummy/default one on logout). This is sort-of a NullObject pattern
>> implementation, except that it represents a dummy/default user.
>>
>> For (2), you can use conditional logic around property access.
>>
>> Or just don't go to any pages that require a userInfo, likely by
>> redirecting to a login page on "protected" pages. That could be 
>> handled by
>> a filter, a custom request processor, etc.
>>
>> It seems like you're over-thinking this instead of just using any of the
>> suggestions already provided or coming up with something better--this 
>> is a
>> straight-forward problem, with relatively straight-forward solution.
>>
>> Dave
>>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
>
>
>
>




---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Form handling by direct URL in Struts 1.3.8

Posted by Takanori Hayashi <th...@na.rim.or.jp>.
Hello Anjib,

Assumed that you made the distinction on validate method,
then if forwarded JSP page is using userInfo session like
<logic:empty name="userInfo" property="firstName">
             ${userInfo.userName}
</logic:empty>
the same error  is shown.
[Caused by: javax.servlet.jsp.JspException: Cannot find bean: "userInfo" 
in any scope ]
Because you are using "not existing userInfo" at the JSP.  The problem 
is JSP using userInfo being there.

Takanori

(2012/06/14 22:29), Dave Newton wrote:
> On Thu, Jun 14, 2012 at 9:18 AM, Anjib Mulepati<an...@hotmail.com>  wrote:
>
>> I don't think problem is mapping correct page from Action class. If you
>> look into my initial code posting /changepassword need form validation so
>> it calls the validate() method and since there is no data it fails. I have
>> input="changePasswordPage" which takes to the tile where it look for the
>> session variable.
>> My problem I don't a mechanism where if some one POST the empty data
>> validation fail must lead to not login message or invalid access message.
>> How can I make such distinction from normal form submission?
>>
> You don't *need* to make that distinction, although you *may*.
>
> You still have the same options as before:
>
> 1. A userInfo object in session, or
> 2. Don't read userInfo properties if it's *not* in session.
>
> For (1), you *could* just keep a dummy/default "not-logged-in" userInfo in
> session, and replace it with a real on on login (and go back to the
> dummy/default one on logout). This is sort-of a NullObject pattern
> implementation, except that it represents a dummy/default user.
>
> For (2), you can use conditional logic around property access.
>
> Or just don't go to any pages that require a userInfo, likely by
> redirecting to a login page on "protected" pages. That could be handled by
> a filter, a custom request processor, etc.
>
> It seems like you're over-thinking this instead of just using any of the
> suggestions already provided or coming up with something better--this is a
> straight-forward problem, with relatively straight-forward solution.
>
> Dave
>




---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Form handling by direct URL in Struts 1.3.8

Posted by Dave Newton <da...@gmail.com>.
On Thu, Jun 14, 2012 at 9:18 AM, Anjib Mulepati <an...@hotmail.com> wrote:

> I don't think problem is mapping correct page from Action class. If you
> look into my initial code posting /changepassword need form validation so
> it calls the validate() method and since there is no data it fails. I have
> input="changePasswordPage" which takes to the tile where it look for the
> session variable.
> My problem I don't a mechanism where if some one POST the empty data
> validation fail must lead to not login message or invalid access message.
> How can I make such distinction from normal form submission?
>

You don't *need* to make that distinction, although you *may*.

You still have the same options as before:

1. A userInfo object in session, or
2. Don't read userInfo properties if it's *not* in session.

For (1), you *could* just keep a dummy/default "not-logged-in" userInfo in
session, and replace it with a real on on login (and go back to the
dummy/default one on logout). This is sort-of a NullObject pattern
implementation, except that it represents a dummy/default user.

For (2), you can use conditional logic around property access.

Or just don't go to any pages that require a userInfo, likely by
redirecting to a login page on "protected" pages. That could be handled by
a filter, a custom request processor, etc.

It seems like you're over-thinking this instead of just using any of the
suggestions already provided or coming up with something better--this is a
straight-forward problem, with relatively straight-forward solution.

Dave

Re: Form handling by direct URL in Struts 1.3.8

Posted by Anjib Mulepati <an...@hotmail.com>.
I don't think problem is mapping correct page from Action class. If you 
look into my initial code posting /changepassword need form validation 
so it calls the validate() method and since there is no data it fails. I 
have input="changePasswordPage" which takes to the tile where it look 
for the session variable.
My problem I don't a mechanism where if some one POST the empty data 
validation fail must lead to not login message or invalid access 
message. How can I make such distinction from normal form submission?

Thanks,
Anjib
On 6/13/2012 7:00 PM, Takanori Hayashi wrote:
> Hello Anjib,
>
> [Error message]
> Caused by: javax.servlet.jsp.JspException: Cannot find bean: 
> "userInfo" in any scope
>
> [Cause]
> If someone type direct URL http://localhost:8080/MyApp/changepassword.do,
> no userInfo in the session.
> Then userIsLoggedIn method returns false,
>     return mapping.findForward("sessionEnded");
> On this case, would  the same JSP, changePasswordPage be called or 
> some JSP using userInfo session information?
>
> a JSP, changePasswordPage.
> <logic:empty name="userInfo" property="firstName">
>             ${userInfo.userName}
> </logic:empty>
>
> [Measure idea #1]
> On BaseAction
> Changed from:return mapping.findForward("sessionEnded");
>                 to:     some JSP page without userInfo session 
> information.
>
> [Measure idea #2]
> On BaseAction
> Changed from:
>         if (!this.userIsLoggedIn(request)) {
>             ActionErrors errors = new ActionErrors();
>             errors.add("error", new 
> ActionMessage("error.userNotLoggedIn"));
>             this.saveErrors(request, errors);
>             String url = request.getServletPath() + "?" + 
> request.getQueryString();
>             request.getSession().setAttribute("forwardPath", url);
>             return mapping.findForward("sessionEnded");
>         }
>                 to:
>         if (!this.userIsLoggedIn(request)) {
>             ActionErrors errors = new ActionErrors();
>             errors.add("error", new 
> ActionMessage("error.userNotLoggedIn"));
>             this.saveErrors(request, errors);
>             String url = request.getServletPath() + "?" + 
> request.getQueryString();
>             request.getSession().setAttribute("forwardPath", url);
>
>             // ADD
>             request.getSession().setAttribute("userInfo", SOMETHING 
> TEMPORARY INFORMATION);
>
>             return mapping.findForward("sessionEnded");
>         }
>
> Best regards,
> Takanori Hayashi
>
> (2012/06/14 3:07), Anjib Mulepati wrote:
>> I am looking for such prevention measure. Right now for most action I 
>> have Base action where it check whether user has logged in or not.
>>
>> On 6/13/2012 1:21 PM, Dave Newton wrote:
>>> On Wednesday, June 13, 2012, Anjib Mulepati<an...@hotmail.com>  
>>> wrote:
>>>> Where and how I do that?
>>> In Struts 1.2 you'd use a custom request processor (or just a 
>>> filter). Not
>>> sure about 1.3.
>>>
>>> How are you preventing access to protected pages now?
>>>
>>> Dave
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>>
>>
>>
>>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Form handling by direct URL in Struts 1.3.8

Posted by Takanori Hayashi <th...@na.rim.or.jp>.
Hello Anjib,

[Error message]
Caused by: javax.servlet.jsp.JspException: Cannot find bean: "userInfo" 
in any scope

[Cause]
If someone type direct URL http://localhost:8080/MyApp/changepassword.do,
no userInfo in the session.
Then userIsLoggedIn method returns false,
     return mapping.findForward("sessionEnded");
On this case, would  the same JSP, changePasswordPage be called or some 
JSP using userInfo session information?

a JSP, changePasswordPage.
<logic:empty name="userInfo" property="firstName">
             ${userInfo.userName}
</logic:empty>

[Measure idea #1]
On BaseAction
Changed from:return mapping.findForward("sessionEnded");
                 to:     some JSP page without userInfo session information.

[Measure idea #2]
On BaseAction
Changed from:
         if (!this.userIsLoggedIn(request)) {
             ActionErrors errors = new ActionErrors();
             errors.add("error", new 
ActionMessage("error.userNotLoggedIn"));
             this.saveErrors(request, errors);
             String url = request.getServletPath() + "?" + 
request.getQueryString();
             request.getSession().setAttribute("forwardPath", url);
             return mapping.findForward("sessionEnded");
         }
                 to:
         if (!this.userIsLoggedIn(request)) {
             ActionErrors errors = new ActionErrors();
             errors.add("error", new 
ActionMessage("error.userNotLoggedIn"));
             this.saveErrors(request, errors);
             String url = request.getServletPath() + "?" + 
request.getQueryString();
             request.getSession().setAttribute("forwardPath", url);

             // ADD
             request.getSession().setAttribute("userInfo", SOMETHING 
TEMPORARY INFORMATION);

             return mapping.findForward("sessionEnded");
         }

Best regards,
Takanori Hayashi

(2012/06/14 3:07), Anjib Mulepati wrote:
> I am looking for such prevention measure. Right now for most action I 
> have Base action where it check whether user has logged in or not.
>
> On 6/13/2012 1:21 PM, Dave Newton wrote:
>> On Wednesday, June 13, 2012, Anjib Mulepati<an...@hotmail.com>  wrote:
>>> Where and how I do that?
>> In Struts 1.2 you'd use a custom request processor (or just a 
>> filter). Not
>> sure about 1.3.
>>
>> How are you preventing access to protected pages now?
>>
>> Dave
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
>
>
>
>




---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Form handling by direct URL in Struts 1.3.8

Posted by Anjib Mulepati <an...@hotmail.com>.
I am looking for such prevention measure. Right now for most action I 
have Base action where it check whether user has logged in or not.

On 6/13/2012 1:21 PM, Dave Newton wrote:
> On Wednesday, June 13, 2012, Anjib Mulepati<an...@hotmail.com>  wrote:
>> Where and how I do that?
> In Struts 1.2 you'd use a custom request processor (or just a filter). Not
> sure about 1.3.
>
> How are you preventing access to protected pages now?
>
> Dave
>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Form handling by direct URL in Struts 1.3.8

Posted by Dave Newton <da...@gmail.com>.
On Wednesday, June 13, 2012, Anjib Mulepati <an...@hotmail.com> wrote:
> Where and how I do that?

In Struts 1.2 you'd use a custom request processor (or just a filter). Not
sure about 1.3.

How are you preventing access to protected pages now?

Dave

Re: Form handling by direct URL in Struts 1.3.8

Posted by Anjib Mulepati <an...@hotmail.com>.
Where and how I do that?

On 6/13/2012 12:19 PM, Dave Newton wrote:
> Sure, redirect any request without a user info object to the login page.
>
> Dave
>
> (pardon brevity and typos, on cell)
> On Jun 13, 2012 12:16 PM, "Anjib Mulepati"<an...@hotmail.com>  wrote:
>
>> i know that. My question was how we handle such direct URL. Like in this
>> case. Is there any mechanism to prevent?
>>
>> On 6/13/2012 12:07 PM, Jason Zheng wrote:
>>
>>> That's the problem, when you type the URL directly, the
>>> LoginSubmitAction.execute() method will not be invoked, so the 'userinfo'
>>> is not exits in any scope.
>>>
>>> On Wed, Jun 13, 2012 at 11:58 PM, Anjib Mulepati<an...@hotmail.com>**
>>> wrote:
>>>
>>>   User info is put into session after they log in so its in
>>>> LoginSubmitAction class.
>>>>
>>>> public class LoginSubmitAction extends org.apache.struts.action.****Action
>>>> {
>>>>
>>>>     private static final String ERROR = "errorFront";
>>>>
>>>>
>>>>     private static final String SUCCESS = "success";
>>>>
>>>>     private static Log log = LogFactory.getLog("****LoginSubmitAction");
>>>>
>>>>
>>>>      @Override
>>>>     public ActionForward execute(ActionMapping mapping, ActionForm form,
>>>>             HttpServletRequest request, HttpServletResponse response)
>>>>             throws Exception {
>>>>
>>>>         LoginForm loginForm = (LoginForm) form;
>>>>         String forwardPath = (String) request.getSession().**
>>>> getAttribute("forwardPath");
>>>>         String userName = loginForm.getUserName().****toLowerCase();
>>>>         String passWord = loginForm.getPassword();
>>>>         UserInfo userInfo = new UserInfo();
>>>>
>>>>         ActionForward objAxFrwd = null;
>>>>         try {
>>>>             /* Authenticate user */
>>>>
>>>>             UserDelegate userDelegate = new UserDelegate(userName, null);
>>>>             userDelegate.validateUser(****userName, passWord);
>>>>             log.info("User authenticated: " + userName);
>>>>
>>>>             /* Get user profile and store in beans then to session
>>>> variable
>>>> */
>>>>             UserProfileInfo userProfileInfo =
>>>> userDelegate.getUserProfile(*
>>>> *userName);
>>>>             userInfo.setUserName(****userProfileInfo.getUserName())****;
>>>> //Currently username is same as email address.
>>>>             userInfo.setPassword(passWord)****;
>>>>             userInfo.setFirstName(****userProfileInfo.getFirstName()**
>>>> **);
>>>>             userInfo.setLastName(****userProfileInfo.getLastName())****;
>>>>             userInfo.setEmail(****userProfileInfo.getEmail());
>>>>             userInfo.setPhone(****userProfileInfo.getPhone());
>>>>
>>>>
>>>>
>>>>         } catch (BusinessDelegateException e) {
>>>>             /* User not authenticated */
>>>>             log.error(e.getErrorCode() + ": User not authenticated: " +
>>>> userName);
>>>>
>>>>             ActionErrors errors = new ActionErrors();
>>>>             errors.add("error", new ActionMessage(e.getMessage(), false));
>>>>             this.saveErrors(request, errors);
>>>>             return mapping.findForward(ERROR);
>>>>         } catch (org.apache.cxf.binding.soap.****SoapFault s){
>>>>             log.error(s);
>>>>             return mapping.findForward(ERROR);
>>>>         }
>>>>
>>>>         /* Forward control to the specified success URI */
>>>>         if (forwardPath != null) {
>>>>             objAxFrwd = new ActionForward(forwardPath);
>>>>         } else {
>>>>             objAxFrwd = mapping.findForward(SUCCESS);
>>>>         }
>>>>         request.getSession().****setAttribute("userInfo", userInfo);
>>>>         request.getSession().****setAttribute("userName", userName);
>>>>         return objAxFrwd;
>>>>
>>>>     }
>>>> }
>>>> On 6/13/2012 11:51 AM, Dave Newton wrote:
>>>>
>>>>   I don't see anything that puts a user info into session (or request, I
>>>>> forgot where it was), so it makes sense the JSP would fail.
>>>>>
>>>>> [OT] In the future, consider removing useless, empty comments so people
>>>>> trying to help have less work to do :)
>>>>>
>>>>> Dave
>>>>>
>>>>> On Wed, Jun 13, 2012 at 11:43 AM, Anjib Mulepati<an...@hotmail.com>**
>>>>> **
>>>>> wrote:
>>>>>
>>>>>   1. Base Class
>>>>>
>>>>>> public abstract class BaseAction extends org.apache.struts.action.****
>>>>>> Action
>>>>>> {
>>>>>>
>>>>>>     private static Log log = LogFactory.getLog("BaseAction"******);
>>>>>>
>>>>>>     /**
>>>>>>      *
>>>>>>      * @param mapping
>>>>>>      * @param form
>>>>>>      * @param request
>>>>>>      * @param response
>>>>>>      * @return
>>>>>>      * @throws IOException
>>>>>>      * @throws ServletException
>>>>>>      * @throws BusinessDelegateException
>>>>>>      */
>>>>>>     @Override
>>>>>>     public ActionForward execute(ActionMapping mapping, ActionForm form,
>>>>>>             HttpServletRequest request, HttpServletResponse response)
>>>>>>             throws IOException, ServletException,
>>>>>> BusinessDelegateException
>>>>>> {
>>>>>>
>>>>>>         if (!this.userIsLoggedIn(request)******) {
>>>>>>             ActionErrors errors = new ActionErrors();
>>>>>>             errors.add("error", new ActionMessage("error.**
>>>>>> userNotLoggedIn"));
>>>>>>             this.saveErrors(request, errors);
>>>>>>             String url = request.getServletPath() + "?" +
>>>>>> request.getQueryString();
>>>>>>             request.getSession().******setAttribute("forwardPath",
>>>>>> url);
>>>>>>             return mapping.findForward("******sessionEnded");
>>>>>>         }
>>>>>>         return executeAction(mapping, form, request, response);
>>>>>>     }
>>>>>>
>>>>>>     /**
>>>>>>      *
>>>>>>      * @param mapping
>>>>>>      * @param form
>>>>>>      * @param request
>>>>>>      * @param response
>>>>>>      * @return
>>>>>>      * @throws IOException
>>>>>>      * @throws ServletException
>>>>>>      */
>>>>>>     protected abstract ActionForward executeAction(ActionMapping
>>>>>> mapping,
>>>>>>             ActionForm form, HttpServletRequest request,
>>>>>>             HttpServletResponse response)
>>>>>>             throws IOException, ServletException;
>>>>>>
>>>>>>     private boolean userIsLoggedIn(******HttpServletRequest request) {
>>>>>>         UserInfo userInfo = (UserInfo) request.getSession().**
>>>>>> getAttribute("userInfo");
>>>>>>         String userName = null;
>>>>>>         try{
>>>>>>             userName = userInfo.getUserName();
>>>>>>         } catch (NullPointerException ex) {
>>>>>>             log.error("User hasn't logged in yet.");
>>>>>>             return false;
>>>>>>         }
>>>>>>
>>>>>>         if ( userName == null) {
>>>>>>             return false;
>>>>>>         }
>>>>>>         return true;
>>>>>>     }
>>>>>> }
>>>>>>
>>>>>> 2. Action class
>>>>>> public class ChangePasswordAction extends BaseAction {
>>>>>>
>>>>>>     private static Log log = LogFactory.getLog("****
>>>>>> ChangePasswordAction");
>>>>>>
>>>>>>     private static final String SUCCESS = "success";
>>>>>>
>>>>>>     private static final String FAILURE = "failure";
>>>>>>
>>>>>>     @Override
>>>>>>     public ActionForward executeAction(ActionMapping mapping, ActionForm
>>>>>> form,
>>>>>>             HttpServletRequest request, HttpServletResponse response)
>>>>>>             throws IOException, ServletException {
>>>>>>
>>>>>>         ActionErrors errors = new ActionErrors();
>>>>>>         ActionMessages messages = new ActionMessages();
>>>>>>
>>>>>>         ChangePasswordForm changePwdForm = (ChangePasswordForm) form;
>>>>>>         String userName = changePwdForm.getUserName();
>>>>>>         String oldPassword = changePwdForm.getOldPwd().******trim();
>>>>>>         String newPassword = changePwdForm.getPassword().******trim();
>>>>>>         UserDelegate userDelegate = new UserDelegate(userName, null);
>>>>>>         boolean isPasswordChanged = userDelegate.changePassword(******
>>>>>> userName,
>>>>>> oldPassword, newPassword);
>>>>>>
>>>>>>         if (isPasswordChanged) {
>>>>>>             messages.add("password", new ActionMessage("msg.**
>>>>>> changePasswordSuccess"));
>>>>>>             this.saveMessages(request, messages);
>>>>>>             log.info("Password changed successfully.");
>>>>>>             return mapping.findForward(SUCCESS);
>>>>>>         } else {
>>>>>>             errors.add("errors", new ActionMessage("msg.**
>>>>>> changePasswordError"));
>>>>>>             saveErrors(request, errors);
>>>>>>             log.error("Password can't be changed");
>>>>>>             return mapping.findForward(FAILURE);
>>>>>>         }
>>>>>>    }
>>>>>> }
>>>>>>
>>>>>> 3. Validation class
>>>>>> public class ChangePasswordForm extends ValidatorForm {
>>>>>>
>>>>>>     private String userName;
>>>>>>     private String oldPwd;
>>>>>>     private String password;
>>>>>>     private String confirmPwd;
>>>>>>
>>>>>>     /**
>>>>>>      *
>>>>>>      * @return
>>>>>>      */
>>>>>>     public String getPassword() {
>>>>>>         return password;
>>>>>>     }
>>>>>>
>>>>>>     /**
>>>>>>      *
>>>>>>      * @param password
>>>>>>      */
>>>>>>     public void setPassword(String password) {
>>>>>>         this.password = password;
>>>>>>     }
>>>>>>
>>>>>>     /**
>>>>>>      *
>>>>>>      * @return
>>>>>>      */
>>>>>>     public String getOldPwd() {
>>>>>>         return oldPwd;
>>>>>>     }
>>>>>>
>>>>>>     /**
>>>>>>      *
>>>>>>      * @param oldPwd
>>>>>>      */
>>>>>>     public void setOldPwd(String oldPwd) {
>>>>>>         this.oldPwd = oldPwd;
>>>>>>     }
>>>>>>
>>>>>>     /**
>>>>>>      *
>>>>>>      * @return
>>>>>>      */
>>>>>>     public String getConfirmPwd() {
>>>>>>         return confirmPwd;
>>>>>>     }
>>>>>>
>>>>>>     /**
>>>>>>      *
>>>>>>      * @param confirmPwd
>>>>>>      */
>>>>>>     public void setConfirmPwd(String confirmPwd) {
>>>>>>         this.confirmPwd = confirmPwd;
>>>>>>     }
>>>>>>
>>>>>>     /**
>>>>>>      *
>>>>>>      * @return
>>>>>>      */
>>>>>>     public String getUserName() {
>>>>>>         return userName;
>>>>>>     }
>>>>>>
>>>>>>     /**
>>>>>>      *
>>>>>>      * @param userName
>>>>>>      */
>>>>>>     public void setUserName(String userName) {
>>>>>>         this.userName = userName;
>>>>>>     }
>>>>>>
>>>>>>     /**
>>>>>>      *
>>>>>>      */
>>>>>>     public ChangePasswordForm() {
>>>>>>         super();
>>>>>>
>>>>>>     }
>>>>>>
>>>>>>     /**
>>>>>>      * This is the action called from the Struts framework.
>>>>>>      * @param mapping The ActionMapping used to select this instance.
>>>>>>      * @param request The HTTP Request we are processing.
>>>>>>      * @return set of errors.
>>>>>>      */
>>>>>>     @Override
>>>>>>     public ActionErrors validate(ActionMapping mapping,
>>>>>> HttpServletRequest
>>>>>> request) {
>>>>>>         ActionErrors errors = new ActionErrors();
>>>>>>         if(userName.isEmpty()){
>>>>>>             errors.add("error", new ActionMessage("error.userName"**
>>>>>> ****));
>>>>>>         }
>>>>>>         if(oldPwd.isEmpty()){
>>>>>>             errors.add("error", new ActionMessage("error.****
>>>>>> oldPassword"));
>>>>>>         }
>>>>>>         if(password.isEmpty()){
>>>>>>             errors.add("error", new ActionMessage("error.****
>>>>>> newPassword"));
>>>>>>         }
>>>>>>         if(!confirmPwd.equals(******password)){
>>>>>>             errors.add("error", new ActionMessage("error.**
>>>>>> confirmPassword"));
>>>>>>         }
>>>>>>         if(userName.equalsIgnoreCase(******password)){
>>>>>>             errors.add("error", new ActionMessage("error.**
>>>>>> sameAsUsername"));
>>>>>>         }
>>>>>>         if(oldPwd.equalsIgnoreCase(******password)){
>>>>>>             errors.add("error", new ActionMessage("error.****
>>>>>> samePassword"));
>>>>>>         }
>>>>>>         return errors;
>>>>>>     }
>>>>>>
>>>>>>     /**
>>>>>>      *
>>>>>>      * @param mapping
>>>>>>      * @param request
>>>>>>      */
>>>>>>     @Override
>>>>>>     public void reset(ActionMapping mapping, HttpServletRequest
>>>>>> request) {
>>>>>>         userName = "";
>>>>>>         oldPwd = "";
>>>>>>         password = "";
>>>>>>         confirmPwd = "";
>>>>>>     }
>>>>>> }
>>>>>>
>>>>>> On 6/13/2012 11:10 AM, Jason Zheng wrote:
>>>>>>
>>>>>>   Anjib, would you like to show us the codes in the Action
>>>>>>
>>>>>>> ChangePasswordAction?
>>>>>>>
>>>>>>> On Wed, Jun 13, 2012 at 10:58 PM, Dave Newton<da...@gmail.com>
>>>>>>>   wrote:
>>>>>>>
>>>>>>>   Then it's likely you're doing something wrong if you're forwarding
>>>>>>> to a
>>>>>>>
>>>>>>>   page before creating the info that page needs.
>>>>>>>> Dave
>>>>>>>>
>>>>>>>> On Wed, Jun 13, 2012 at 10:53 AM, Anjib Mulepati<anjibcs@hotmail.com
>>>>>>>>
>>>>>>>>   wrote:
>>>>>>>>
>>>>>>>>> Even though I put validation in ActionForm validate() method failure
>>>>>>>>> will
>>>>>>>>> take to changePasswordPage. I do have validation to check form
>>>>>>>>> field.
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> On 6/13/2012 9:17 AM, Dave Newton wrote:
>>>>>>>>>
>>>>>>>>>   Maybe some sort of validation would be helpful.
>>>>>>>>>
>>>>>>>>>   Dave
>>>>>>>>>> On Wed, Jun 13, 2012 at 9:03 AM, Anjib Mulepati<
>>>>>>>>>> anjibcs@hotmail.com>
>>>>>>>>>>   wrote:
>>>>>>>>>>
>>>>>>>>>>   Hi All,
>>>>>>>>>>
>>>>>>>>>>   I have question regarding handling form submission by direct URL
>>>>>>>>>> in
>>>>>>>>>>
>>>>>>>>>>> Struts
>>>>>>>>>>> 1.3.8
>>>>>>>>>>>
>>>>>>>>>>> I have a page to change password which user can access after they
>>>>>>>>>>>
>>>>>>>>>>>   login.
>>>>>>>>>>>
>>>>>>>>>> URL for that page is http://localhost:8080/MyApp/********<http://localhost:8080/MyApp/******>
>>>>>>>>> <http://localhost:8080/**MyApp/****<http://localhost:8080/MyApp/****>
>>>>>>>>>   **changepassword.do<http://****localhost:8080/MyApp/******
>>>>>>>>>>> changepassword.do<http://**localhost:8080/MyApp/******
>>>>>>>>>>> changepassword.do<http://localhost:8080/MyApp/****changepassword.do>
>>>>>>>>>>>   <http://localhost:8080/MyApp/********changepassword.do<http://localhost:8080/MyApp/******changepassword.do>
>>>>>>>>>>> <http://**localhost:8080/MyApp/******changepassword.do<http://localhost:8080/MyApp/****changepassword.do>
>>>>>>>>>> <http://**localhost:8080/**MyApp/****changepassword.do<ht**
>>>>>>>>>> tp://localhost:8080/MyApp/****changepassword.do<http://localhost:8080/MyApp/**changepassword.do>
>>>>>>>>> <http://**localhost:8080/******MyApp/**changepassword.do<
>>>>>>>>>
>>>>>>>>>   http://localhost:8080/MyApp/******changepassword.do<http://localhost:8080/MyApp/****changepassword.do>
>>>>>>>>>> <http://**localhost:8080/MyApp/****changepassword.do<http://localhost:8080/MyApp/**changepassword.do>
>>>>>>>>>> <http://**localhost:8080/**MyApp/**changepassword.do<http**
>>>>>>>>>> ://localhost:8080/MyApp/**changepassword.do<http://localhost:8080/MyApp/changepassword.do>
>>>>>>>>>>> I have action mapping as follow:
>>>>>>>>>>> <action path="/changepassword" input="changePasswordPage"
>>>>>>>>>>>
>>>>>>>>>>>   scope="request"
>>>>>>>>>>>
>>>>>>>>>>   name="ChangePasswordForm" type="com.anjib.actions.**
>>>>>>>>>   ChangePasswordAction">
>>>>>>>>>>> <forward name="success" path="changePasswordPage" />
>>>>>>>>>>> <forward name="failure" path="changePasswordPage"/>
>>>>>>>>>>> </action>
>>>>>>>>>>>
>>>>>>>>>>> I have tile definition for changePasswordPage which have page like
>>>>>>>>>>>
>>>>>>>>>>>   header
>>>>>>>>>>>
>>>>>>>>>> which display welcome information after user login
>>>>>>>>>   <div id="welcome" class="right">
>>>>>>>>>>> <bean:message key="label.welcome" />
>>>>>>>>>>> <logic:notEmpty name="userInfo" property="firstName">
>>>>>>>>>>>          ${userInfo.firstName}&nbsp;${**********userInfo.lastName}
>>>>>>>>>>>
>>>>>>>>>>> </logic:notEmpty>
>>>>>>>>>>> <logic:empty name="userInfo" property="firstName">
>>>>>>>>>>>             ${userInfo.userName}
>>>>>>>>>>> </logic:empty>
>>>>>>>>>>> </div>
>>>>>>>>>>>
>>>>>>>>>>> Now everything works fine if we follow normal process: Login and
>>>>>>>>>>> do
>>>>>>>>>>> actions. But if someone type URL http://localhost:8080/MyApp/**
>>>>>>>>>>> changepassword.do<http://********localhost:8080/MyApp/****
>>>>>>>>>>> changepassword.do<
>>>>>>>>>>>
>>>>>>>>>>>   http://localhost:8080/MyApp/******changepassword.do<http://localhost:8080/MyApp/****changepassword.do>
>>>>>>>>>>> <http://**localhost:8080/MyApp/****changepassword.do<http://localhost:8080/MyApp/**changepassword.do>
>>>>>>>>>> <http://**localhost:8080/**MyApp/**changepassword.do<http**
>>>>>>>>>> ://localhost:8080/MyApp/**changepassword.do<http://localhost:8080/MyApp/changepassword.do>
>>>>>>>>>> directly
>>>>>>>>>>
>>>>>>>>>>   then I don't get page and I have error in Tomcat log
>>>>>>>>>   Caused by: javax.servlet.jsp.**********JspException: Cannot find
>>>>>>>>>> bean:
>>>>>>>>>>
>>>>>>>>>>> "userInfo"
>>>>>>>>>>>
>>>>>>>>>>> in any scope
>>>>>>>>>>>
>>>>>>>>>>> Any help will be appreciated.
>>>>>>>>>>>
>>>>>>>>>>> Thanks,
>>>>>>>>>>> Anjib
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> ------------------------------**********----------------------**
>>>>>>>>>>> --**
>>>>>>>>>>> --**--**
>>>>>>>>>>> --**---------
>>>>>>>>>>> To unsubscribe, e-mail: user-unsubscribe@struts.********apac**
>>>>>>>>>>> he.org<
>>>>>>>>>>>
>>>>>>>>>>>   http://apache.org>
>>>>>>>>>>>
>>>>>>>>>> <user-unsubscribe@**struts.****a**pache.org<http://apache.org**><
>>>>>>>>> http://struts.**apache.org<htt**p://struts.apache.org<http://struts.apache.org>
>>>>>>>>>>> <
>>>>>>>>>   user-unsubscribe@struts.****apac**he.org<http://apache.org**><
>>>>>>>>>> user-unsubscribe@**struts.**apache.org<http://struts.apache.org><
>>>>>>>>>> user-unsubscribe@**struts.apache.org<us...@struts.apache.org>
>>>>>>>>> For additional commands, e-mail: user-help@struts.apache.org
>>>>>>>>>
>>>>>>>>>    ------------------------------********------------------------**
>>>>>>>>>>> --**
>>>>>>>>>>> --**
>>>>>>>>>>>
>>>>>>>>>>>   --**---------
>>>>>>>>> To unsubscribe, e-mail: user-unsubscribe@struts.******apac**he.org<
>>>>>>>>> http://apache.org**>
>>>>>>>>> <
>>>>>>>>>
>>>>>>>>>   user-unsubscribe@struts.****apac**he.org<http://apache.org**><
>>>>>>>>>
>>>>>>>> user-unsubscribe@**struts.**apache.org<http://struts.apache.org><
>>>>>>>> user-unsubscribe@**struts.apache.org<us...@struts.apache.org>
>>>>>>>>> For additional commands, e-mail: user-help@struts.apache.org
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>    ------------------------------******--------------------------**
>>>>>>> --**
>>>>>>>
>>>>>> --**---------
>>>>>> To unsubscribe, e-mail: user-unsubscribe@struts.****apac**he.org<
>>>>>> http://apache.org**>
>>>>>> <user-unsubscribe@**struts.**apache.org<http://struts.apache.org><
>>>>>> user-unsubscribe@**struts.apache.org<us...@struts.apache.org>
>>>>>> For additional commands, e-mail: user-help@struts.apache.org
>>>>>>
>>>>>>
>>>>>>
>>>>>>   ------------------------------****----------------------------**
>>>> --**---------
>>>> To unsubscribe, e-mail: user-unsubscribe@struts.**apac**he.org<http://apache.org>
>>>> <us...@struts.apache.org>
>>>> For additional commands, e-mail: user-help@struts.apache.org
>>>>
>>>>
>>>>
>> ------------------------------**------------------------------**---------
>> To unsubscribe, e-mail: user-unsubscribe@struts.**apache.org<us...@struts.apache.org>
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Form handling by direct URL in Struts 1.3.8

Posted by Dave Newton <da...@gmail.com>.
Sure, redirect any request without a user info object to the login page.

Dave

(pardon brevity and typos, on cell)
On Jun 13, 2012 12:16 PM, "Anjib Mulepati" <an...@hotmail.com> wrote:

> i know that. My question was how we handle such direct URL. Like in this
> case. Is there any mechanism to prevent?
>
> On 6/13/2012 12:07 PM, Jason Zheng wrote:
>
>> That's the problem, when you type the URL directly, the
>> LoginSubmitAction.execute() method will not be invoked, so the 'userinfo'
>> is not exits in any scope.
>>
>> On Wed, Jun 13, 2012 at 11:58 PM, Anjib Mulepati<an...@hotmail.com>**
>> wrote:
>>
>>  User info is put into session after they log in so its in
>>> LoginSubmitAction class.
>>>
>>> public class LoginSubmitAction extends org.apache.struts.action.****Action
>>> {
>>>
>>>    private static final String ERROR = "errorFront";
>>>
>>>
>>>    private static final String SUCCESS = "success";
>>>
>>>    private static Log log = LogFactory.getLog("****LoginSubmitAction");
>>>
>>>
>>>     @Override
>>>    public ActionForward execute(ActionMapping mapping, ActionForm form,
>>>            HttpServletRequest request, HttpServletResponse response)
>>>            throws Exception {
>>>
>>>        LoginForm loginForm = (LoginForm) form;
>>>        String forwardPath = (String) request.getSession().**
>>> getAttribute("forwardPath");
>>>        String userName = loginForm.getUserName().****toLowerCase();
>>>        String passWord = loginForm.getPassword();
>>>        UserInfo userInfo = new UserInfo();
>>>
>>>        ActionForward objAxFrwd = null;
>>>        try {
>>>            /* Authenticate user */
>>>
>>>            UserDelegate userDelegate = new UserDelegate(userName, null);
>>>            userDelegate.validateUser(****userName, passWord);
>>>            log.info("User authenticated: " + userName);
>>>
>>>            /* Get user profile and store in beans then to session
>>> variable
>>> */
>>>            UserProfileInfo userProfileInfo =
>>> userDelegate.getUserProfile(*
>>> *userName);
>>>            userInfo.setUserName(****userProfileInfo.getUserName())****;
>>> //Currently username is same as email address.
>>>            userInfo.setPassword(passWord)****;
>>>            userInfo.setFirstName(****userProfileInfo.getFirstName()**
>>> **);
>>>            userInfo.setLastName(****userProfileInfo.getLastName())****;
>>>            userInfo.setEmail(****userProfileInfo.getEmail());
>>>            userInfo.setPhone(****userProfileInfo.getPhone());
>>>
>>>
>>>
>>>        } catch (BusinessDelegateException e) {
>>>            /* User not authenticated */
>>>            log.error(e.getErrorCode() + ": User not authenticated: " +
>>> userName);
>>>
>>>            ActionErrors errors = new ActionErrors();
>>>            errors.add("error", new ActionMessage(e.getMessage(), false));
>>>            this.saveErrors(request, errors);
>>>            return mapping.findForward(ERROR);
>>>        } catch (org.apache.cxf.binding.soap.****SoapFault s){
>>>            log.error(s);
>>>            return mapping.findForward(ERROR);
>>>        }
>>>
>>>        /* Forward control to the specified success URI */
>>>        if (forwardPath != null) {
>>>            objAxFrwd = new ActionForward(forwardPath);
>>>        } else {
>>>            objAxFrwd = mapping.findForward(SUCCESS);
>>>        }
>>>        request.getSession().****setAttribute("userInfo", userInfo);
>>>        request.getSession().****setAttribute("userName", userName);
>>>        return objAxFrwd;
>>>
>>>    }
>>> }
>>> On 6/13/2012 11:51 AM, Dave Newton wrote:
>>>
>>>  I don't see anything that puts a user info into session (or request, I
>>>> forgot where it was), so it makes sense the JSP would fail.
>>>>
>>>> [OT] In the future, consider removing useless, empty comments so people
>>>> trying to help have less work to do :)
>>>>
>>>> Dave
>>>>
>>>> On Wed, Jun 13, 2012 at 11:43 AM, Anjib Mulepati<an...@hotmail.com>**
>>>> **
>>>> wrote:
>>>>
>>>>  1. Base Class
>>>>
>>>>> public abstract class BaseAction extends org.apache.struts.action.****
>>>>> Action
>>>>> {
>>>>>
>>>>>    private static Log log = LogFactory.getLog("BaseAction"******);
>>>>>
>>>>>    /**
>>>>>     *
>>>>>     * @param mapping
>>>>>     * @param form
>>>>>     * @param request
>>>>>     * @param response
>>>>>     * @return
>>>>>     * @throws IOException
>>>>>     * @throws ServletException
>>>>>     * @throws BusinessDelegateException
>>>>>     */
>>>>>    @Override
>>>>>    public ActionForward execute(ActionMapping mapping, ActionForm form,
>>>>>            HttpServletRequest request, HttpServletResponse response)
>>>>>            throws IOException, ServletException,
>>>>> BusinessDelegateException
>>>>> {
>>>>>
>>>>>        if (!this.userIsLoggedIn(request)******) {
>>>>>            ActionErrors errors = new ActionErrors();
>>>>>            errors.add("error", new ActionMessage("error.**
>>>>> userNotLoggedIn"));
>>>>>            this.saveErrors(request, errors);
>>>>>            String url = request.getServletPath() + "?" +
>>>>> request.getQueryString();
>>>>>            request.getSession().******setAttribute("forwardPath",
>>>>> url);
>>>>>            return mapping.findForward("******sessionEnded");
>>>>>        }
>>>>>        return executeAction(mapping, form, request, response);
>>>>>    }
>>>>>
>>>>>    /**
>>>>>     *
>>>>>     * @param mapping
>>>>>     * @param form
>>>>>     * @param request
>>>>>     * @param response
>>>>>     * @return
>>>>>     * @throws IOException
>>>>>     * @throws ServletException
>>>>>     */
>>>>>    protected abstract ActionForward executeAction(ActionMapping
>>>>> mapping,
>>>>>            ActionForm form, HttpServletRequest request,
>>>>>            HttpServletResponse response)
>>>>>            throws IOException, ServletException;
>>>>>
>>>>>    private boolean userIsLoggedIn(******HttpServletRequest request) {
>>>>>        UserInfo userInfo = (UserInfo) request.getSession().**
>>>>> getAttribute("userInfo");
>>>>>        String userName = null;
>>>>>        try{
>>>>>            userName = userInfo.getUserName();
>>>>>        } catch (NullPointerException ex) {
>>>>>            log.error("User hasn't logged in yet.");
>>>>>            return false;
>>>>>        }
>>>>>
>>>>>        if ( userName == null) {
>>>>>            return false;
>>>>>        }
>>>>>        return true;
>>>>>    }
>>>>> }
>>>>>
>>>>> 2. Action class
>>>>> public class ChangePasswordAction extends BaseAction {
>>>>>
>>>>>    private static Log log = LogFactory.getLog("****
>>>>> ChangePasswordAction");
>>>>>
>>>>>    private static final String SUCCESS = "success";
>>>>>
>>>>>    private static final String FAILURE = "failure";
>>>>>
>>>>>    @Override
>>>>>    public ActionForward executeAction(ActionMapping mapping, ActionForm
>>>>> form,
>>>>>            HttpServletRequest request, HttpServletResponse response)
>>>>>            throws IOException, ServletException {
>>>>>
>>>>>        ActionErrors errors = new ActionErrors();
>>>>>        ActionMessages messages = new ActionMessages();
>>>>>
>>>>>        ChangePasswordForm changePwdForm = (ChangePasswordForm) form;
>>>>>        String userName = changePwdForm.getUserName();
>>>>>        String oldPassword = changePwdForm.getOldPwd().******trim();
>>>>>        String newPassword = changePwdForm.getPassword().******trim();
>>>>>        UserDelegate userDelegate = new UserDelegate(userName, null);
>>>>>        boolean isPasswordChanged = userDelegate.changePassword(******
>>>>> userName,
>>>>> oldPassword, newPassword);
>>>>>
>>>>>        if (isPasswordChanged) {
>>>>>            messages.add("password", new ActionMessage("msg.**
>>>>> changePasswordSuccess"));
>>>>>            this.saveMessages(request, messages);
>>>>>            log.info("Password changed successfully.");
>>>>>            return mapping.findForward(SUCCESS);
>>>>>        } else {
>>>>>            errors.add("errors", new ActionMessage("msg.**
>>>>> changePasswordError"));
>>>>>            saveErrors(request, errors);
>>>>>            log.error("Password can't be changed");
>>>>>            return mapping.findForward(FAILURE);
>>>>>        }
>>>>>   }
>>>>> }
>>>>>
>>>>> 3. Validation class
>>>>> public class ChangePasswordForm extends ValidatorForm {
>>>>>
>>>>>    private String userName;
>>>>>    private String oldPwd;
>>>>>    private String password;
>>>>>    private String confirmPwd;
>>>>>
>>>>>    /**
>>>>>     *
>>>>>     * @return
>>>>>     */
>>>>>    public String getPassword() {
>>>>>        return password;
>>>>>    }
>>>>>
>>>>>    /**
>>>>>     *
>>>>>     * @param password
>>>>>     */
>>>>>    public void setPassword(String password) {
>>>>>        this.password = password;
>>>>>    }
>>>>>
>>>>>    /**
>>>>>     *
>>>>>     * @return
>>>>>     */
>>>>>    public String getOldPwd() {
>>>>>        return oldPwd;
>>>>>    }
>>>>>
>>>>>    /**
>>>>>     *
>>>>>     * @param oldPwd
>>>>>     */
>>>>>    public void setOldPwd(String oldPwd) {
>>>>>        this.oldPwd = oldPwd;
>>>>>    }
>>>>>
>>>>>    /**
>>>>>     *
>>>>>     * @return
>>>>>     */
>>>>>    public String getConfirmPwd() {
>>>>>        return confirmPwd;
>>>>>    }
>>>>>
>>>>>    /**
>>>>>     *
>>>>>     * @param confirmPwd
>>>>>     */
>>>>>    public void setConfirmPwd(String confirmPwd) {
>>>>>        this.confirmPwd = confirmPwd;
>>>>>    }
>>>>>
>>>>>    /**
>>>>>     *
>>>>>     * @return
>>>>>     */
>>>>>    public String getUserName() {
>>>>>        return userName;
>>>>>    }
>>>>>
>>>>>    /**
>>>>>     *
>>>>>     * @param userName
>>>>>     */
>>>>>    public void setUserName(String userName) {
>>>>>        this.userName = userName;
>>>>>    }
>>>>>
>>>>>    /**
>>>>>     *
>>>>>     */
>>>>>    public ChangePasswordForm() {
>>>>>        super();
>>>>>
>>>>>    }
>>>>>
>>>>>    /**
>>>>>     * This is the action called from the Struts framework.
>>>>>     * @param mapping The ActionMapping used to select this instance.
>>>>>     * @param request The HTTP Request we are processing.
>>>>>     * @return set of errors.
>>>>>     */
>>>>>    @Override
>>>>>    public ActionErrors validate(ActionMapping mapping,
>>>>> HttpServletRequest
>>>>> request) {
>>>>>        ActionErrors errors = new ActionErrors();
>>>>>        if(userName.isEmpty()){
>>>>>            errors.add("error", new ActionMessage("error.userName"**
>>>>> ****));
>>>>>        }
>>>>>        if(oldPwd.isEmpty()){
>>>>>            errors.add("error", new ActionMessage("error.****
>>>>> oldPassword"));
>>>>>        }
>>>>>        if(password.isEmpty()){
>>>>>            errors.add("error", new ActionMessage("error.****
>>>>> newPassword"));
>>>>>        }
>>>>>        if(!confirmPwd.equals(******password)){
>>>>>            errors.add("error", new ActionMessage("error.**
>>>>> confirmPassword"));
>>>>>        }
>>>>>        if(userName.equalsIgnoreCase(******password)){
>>>>>            errors.add("error", new ActionMessage("error.**
>>>>> sameAsUsername"));
>>>>>        }
>>>>>        if(oldPwd.equalsIgnoreCase(******password)){
>>>>>            errors.add("error", new ActionMessage("error.****
>>>>> samePassword"));
>>>>>        }
>>>>>        return errors;
>>>>>    }
>>>>>
>>>>>    /**
>>>>>     *
>>>>>     * @param mapping
>>>>>     * @param request
>>>>>     */
>>>>>    @Override
>>>>>    public void reset(ActionMapping mapping, HttpServletRequest
>>>>> request) {
>>>>>        userName = "";
>>>>>        oldPwd = "";
>>>>>        password = "";
>>>>>        confirmPwd = "";
>>>>>    }
>>>>> }
>>>>>
>>>>> On 6/13/2012 11:10 AM, Jason Zheng wrote:
>>>>>
>>>>>  Anjib, would you like to show us the codes in the Action
>>>>>
>>>>>> ChangePasswordAction?
>>>>>>
>>>>>> On Wed, Jun 13, 2012 at 10:58 PM, Dave Newton<da...@gmail.com>
>>>>>>  wrote:
>>>>>>
>>>>>>  Then it's likely you're doing something wrong if you're forwarding
>>>>>> to a
>>>>>>
>>>>>>  page before creating the info that page needs.
>>>>>>>
>>>>>>> Dave
>>>>>>>
>>>>>>> On Wed, Jun 13, 2012 at 10:53 AM, Anjib Mulepati<anjibcs@hotmail.com
>>>>>>>
>>>>>>>  wrote:
>>>>>>>
>>>>>>>> Even though I put validation in ActionForm validate() method failure
>>>>>>>> will
>>>>>>>> take to changePasswordPage. I do have validation to check form
>>>>>>>> field.
>>>>>>>>
>>>>>>>>
>>>>>>>> On 6/13/2012 9:17 AM, Dave Newton wrote:
>>>>>>>>
>>>>>>>>  Maybe some sort of validation would be helpful.
>>>>>>>>
>>>>>>>>  Dave
>>>>>>>>>
>>>>>>>>> On Wed, Jun 13, 2012 at 9:03 AM, Anjib Mulepati<
>>>>>>>>> anjibcs@hotmail.com>
>>>>>>>>>  wrote:
>>>>>>>>>
>>>>>>>>>  Hi All,
>>>>>>>>>
>>>>>>>>>  I have question regarding handling form submission by direct URL
>>>>>>>>> in
>>>>>>>>>
>>>>>>>>>> Struts
>>>>>>>>>> 1.3.8
>>>>>>>>>>
>>>>>>>>>> I have a page to change password which user can access after they
>>>>>>>>>>
>>>>>>>>>>  login.
>>>>>>>>>>
>>>>>>>>> URL for that page is http://localhost:8080/MyApp/********<http://localhost:8080/MyApp/******>
>>>>>>>> <http://localhost:8080/**MyApp/****<http://localhost:8080/MyApp/****>
>>>>>>>> >
>>>>>>>>
>>>>>>>>  **changepassword.do<http://****localhost:8080/MyApp/******
>>>>>>>>>
>>>>>>>>>> changepassword.do<http://**localhost:8080/MyApp/******
>>>>>>>>>> changepassword.do<http://localhost:8080/MyApp/****changepassword.do>
>>>>>>>>>> >
>>>>>>>>>>  <http://localhost:8080/MyApp/********changepassword.do<http://localhost:8080/MyApp/******changepassword.do>
>>>>>>>>>> <http://**localhost:8080/MyApp/******changepassword.do<http://localhost:8080/MyApp/****changepassword.do>
>>>>>>>>>> >
>>>>>>>>>>
>>>>>>>>> <http://**localhost:8080/**MyApp/****changepassword.do<ht**
>>>>>>>>> tp://localhost:8080/MyApp/****changepassword.do<http://localhost:8080/MyApp/**changepassword.do>
>>>>>>>>> >
>>>>>>>>>
>>>>>>>> <http://**localhost:8080/******MyApp/**changepassword.do<
>>>>>>>>
>>>>>>>>  http://localhost:8080/MyApp/******changepassword.do<http://localhost:8080/MyApp/****changepassword.do>
>>>>>>>>> <http://**localhost:8080/MyApp/****changepassword.do<http://localhost:8080/MyApp/**changepassword.do>
>>>>>>>>> >
>>>>>>>>> <http://**localhost:8080/**MyApp/**changepassword.do<http**
>>>>>>>>> ://localhost:8080/MyApp/**changepassword.do<http://localhost:8080/MyApp/changepassword.do>
>>>>>>>>> >
>>>>>>>>>
>>>>>>>>>> I have action mapping as follow:
>>>>>>>>>> <action path="/changepassword" input="changePasswordPage"
>>>>>>>>>>
>>>>>>>>>>  scope="request"
>>>>>>>>>>
>>>>>>>>>  name="ChangePasswordForm" type="com.anjib.actions.**
>>>>>>>>
>>>>>>>>  ChangePasswordAction">
>>>>>>>>>
>>>>>>>>>> <forward name="success" path="changePasswordPage" />
>>>>>>>>>> <forward name="failure" path="changePasswordPage"/>
>>>>>>>>>> </action>
>>>>>>>>>>
>>>>>>>>>> I have tile definition for changePasswordPage which have page like
>>>>>>>>>>
>>>>>>>>>>  header
>>>>>>>>>>
>>>>>>>>> which display welcome information after user login
>>>>>>>>
>>>>>>>>  <div id="welcome" class="right">
>>>>>>>>>
>>>>>>>>>> <bean:message key="label.welcome" />
>>>>>>>>>> <logic:notEmpty name="userInfo" property="firstName">
>>>>>>>>>>         ${userInfo.firstName}&nbsp;${**********userInfo.lastName}
>>>>>>>>>>
>>>>>>>>>> </logic:notEmpty>
>>>>>>>>>> <logic:empty name="userInfo" property="firstName">
>>>>>>>>>>            ${userInfo.userName}
>>>>>>>>>> </logic:empty>
>>>>>>>>>> </div>
>>>>>>>>>>
>>>>>>>>>> Now everything works fine if we follow normal process: Login and
>>>>>>>>>> do
>>>>>>>>>> actions. But if someone type URL http://localhost:8080/MyApp/**
>>>>>>>>>> changepassword.do<http://********localhost:8080/MyApp/****
>>>>>>>>>> changepassword.do<
>>>>>>>>>>
>>>>>>>>>>  http://localhost:8080/MyApp/******changepassword.do<http://localhost:8080/MyApp/****changepassword.do>
>>>>>>>>>> <http://**localhost:8080/MyApp/****changepassword.do<http://localhost:8080/MyApp/**changepassword.do>
>>>>>>>>>> >
>>>>>>>>>>
>>>>>>>>> <http://**localhost:8080/**MyApp/**changepassword.do<http**
>>>>>>>>> ://localhost:8080/MyApp/**changepassword.do<http://localhost:8080/MyApp/changepassword.do>
>>>>>>>>> >
>>>>>>>>> directly
>>>>>>>>>
>>>>>>>>>  then I don't get page and I have error in Tomcat log
>>>>>>>>
>>>>>>>>  Caused by: javax.servlet.jsp.**********JspException: Cannot find
>>>>>>>>> bean:
>>>>>>>>>
>>>>>>>>>> "userInfo"
>>>>>>>>>>
>>>>>>>>>> in any scope
>>>>>>>>>>
>>>>>>>>>> Any help will be appreciated.
>>>>>>>>>>
>>>>>>>>>> Thanks,
>>>>>>>>>> Anjib
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> ------------------------------**********----------------------**
>>>>>>>>>> --**
>>>>>>>>>> --**--**
>>>>>>>>>> --**---------
>>>>>>>>>> To unsubscribe, e-mail: user-unsubscribe@struts.********apac**
>>>>>>>>>> he.org<
>>>>>>>>>>
>>>>>>>>>>  http://apache.org>
>>>>>>>>>>
>>>>>>>>> <user-unsubscribe@**struts.****a**pache.org<http://apache.org**><
>>>>>>>> http://struts.**apache.org<htt**p://struts.apache.org<http://struts.apache.org>
>>>>>>>> >><
>>>>>>>>
>>>>>>>>  user-unsubscribe@struts.****apac**he.org<http://apache.org**><
>>>>>>>>> user-unsubscribe@**struts.**apache.org <http://struts.apache.org><
>>>>>>>>> user-unsubscribe@**struts.apache.org<us...@struts.apache.org>
>>>>>>>>> >
>>>>>>>>>
>>>>>>>> For additional commands, e-mail: user-help@struts.apache.org
>>>>>>>>
>>>>>>>>   ------------------------------********------------------------**
>>>>>>>>>> --**
>>>>>>>>>> --**
>>>>>>>>>>
>>>>>>>>>>  --**---------
>>>>>>>>>
>>>>>>>> To unsubscribe, e-mail: user-unsubscribe@struts.******apac**he.org<
>>>>>>>> http://apache.org**>
>>>>>>>> <
>>>>>>>>
>>>>>>>>  user-unsubscribe@struts.****apac**he.org<http://apache.org**><
>>>>>>>>
>>>>>>> user-unsubscribe@**struts.**apache.org <http://struts.apache.org><
>>>>>>> user-unsubscribe@**struts.apache.org<us...@struts.apache.org>
>>>>>>> >
>>>>>>>
>>>>>>>> For additional commands, e-mail: user-help@struts.apache.org
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>   ------------------------------******--------------------------**
>>>>>> --**
>>>>>>
>>>>> --**---------
>>>>> To unsubscribe, e-mail: user-unsubscribe@struts.****apac**he.org<
>>>>> http://apache.org**>
>>>>> <user-unsubscribe@**struts.**apache.org <http://struts.apache.org><
>>>>> user-unsubscribe@**struts.apache.org<us...@struts.apache.org>
>>>>> >
>>>>> For additional commands, e-mail: user-help@struts.apache.org
>>>>>
>>>>>
>>>>>
>>>>>  ------------------------------****----------------------------**
>>> --**---------
>>> To unsubscribe, e-mail: user-unsubscribe@struts.**apac**he.org<http://apache.org>
>>> <us...@struts.apache.org>
>>> >
>>>
>>> For additional commands, e-mail: user-help@struts.apache.org
>>>
>>>
>>>
>>
>
> ------------------------------**------------------------------**---------
> To unsubscribe, e-mail: user-unsubscribe@struts.**apache.org<us...@struts.apache.org>
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: Form handling by direct URL in Struts 1.3.8

Posted by Anjib Mulepati <an...@hotmail.com>.
i know that. My question was how we handle such direct URL. Like in this 
case. Is there any mechanism to prevent?

On 6/13/2012 12:07 PM, Jason Zheng wrote:
> That's the problem, when you type the URL directly, the
> LoginSubmitAction.execute() method will not be invoked, so the 'userinfo'
> is not exits in any scope.
>
> On Wed, Jun 13, 2012 at 11:58 PM, Anjib Mulepati<an...@hotmail.com>wrote:
>
>> User info is put into session after they log in so its in
>> LoginSubmitAction class.
>>
>> public class LoginSubmitAction extends org.apache.struts.action.**Action {
>>
>>     private static final String ERROR = "errorFront";
>>
>>
>>     private static final String SUCCESS = "success";
>>
>>     private static Log log = LogFactory.getLog("**LoginSubmitAction");
>>
>>
>>      @Override
>>     public ActionForward execute(ActionMapping mapping, ActionForm form,
>>             HttpServletRequest request, HttpServletResponse response)
>>             throws Exception {
>>
>>         LoginForm loginForm = (LoginForm) form;
>>         String forwardPath = (String) request.getSession().**
>> getAttribute("forwardPath");
>>         String userName = loginForm.getUserName().**toLowerCase();
>>         String passWord = loginForm.getPassword();
>>         UserInfo userInfo = new UserInfo();
>>
>>         ActionForward objAxFrwd = null;
>>         try {
>>             /* Authenticate user */
>>
>>             UserDelegate userDelegate = new UserDelegate(userName, null);
>>             userDelegate.validateUser(**userName, passWord);
>>             log.info("User authenticated: " + userName);
>>
>>             /* Get user profile and store in beans then to session variable
>> */
>>             UserProfileInfo userProfileInfo = userDelegate.getUserProfile(*
>> *userName);
>>             userInfo.setUserName(**userProfileInfo.getUserName())**;
>> //Currently username is same as email address.
>>             userInfo.setPassword(passWord)**;
>>             userInfo.setFirstName(**userProfileInfo.getFirstName()**);
>>             userInfo.setLastName(**userProfileInfo.getLastName())**;
>>             userInfo.setEmail(**userProfileInfo.getEmail());
>>             userInfo.setPhone(**userProfileInfo.getPhone());
>>
>>
>>
>>         } catch (BusinessDelegateException e) {
>>             /* User not authenticated */
>>             log.error(e.getErrorCode() + ": User not authenticated: " +
>> userName);
>>
>>             ActionErrors errors = new ActionErrors();
>>             errors.add("error", new ActionMessage(e.getMessage(), false));
>>             this.saveErrors(request, errors);
>>             return mapping.findForward(ERROR);
>>         } catch (org.apache.cxf.binding.soap.**SoapFault s){
>>             log.error(s);
>>             return mapping.findForward(ERROR);
>>         }
>>
>>         /* Forward control to the specified success URI */
>>         if (forwardPath != null) {
>>             objAxFrwd = new ActionForward(forwardPath);
>>         } else {
>>             objAxFrwd = mapping.findForward(SUCCESS);
>>         }
>>         request.getSession().**setAttribute("userInfo", userInfo);
>>         request.getSession().**setAttribute("userName", userName);
>>         return objAxFrwd;
>>
>>     }
>> }
>> On 6/13/2012 11:51 AM, Dave Newton wrote:
>>
>>> I don't see anything that puts a user info into session (or request, I
>>> forgot where it was), so it makes sense the JSP would fail.
>>>
>>> [OT] In the future, consider removing useless, empty comments so people
>>> trying to help have less work to do :)
>>>
>>> Dave
>>>
>>> On Wed, Jun 13, 2012 at 11:43 AM, Anjib Mulepati<an...@hotmail.com>**
>>> wrote:
>>>
>>>   1. Base Class
>>>> public abstract class BaseAction extends org.apache.struts.action.****
>>>> Action
>>>> {
>>>>
>>>>     private static Log log = LogFactory.getLog("BaseAction"****);
>>>>
>>>>     /**
>>>>      *
>>>>      * @param mapping
>>>>      * @param form
>>>>      * @param request
>>>>      * @param response
>>>>      * @return
>>>>      * @throws IOException
>>>>      * @throws ServletException
>>>>      * @throws BusinessDelegateException
>>>>      */
>>>>     @Override
>>>>     public ActionForward execute(ActionMapping mapping, ActionForm form,
>>>>             HttpServletRequest request, HttpServletResponse response)
>>>>             throws IOException, ServletException,
>>>> BusinessDelegateException
>>>> {
>>>>
>>>>         if (!this.userIsLoggedIn(request)****) {
>>>>             ActionErrors errors = new ActionErrors();
>>>>             errors.add("error", new ActionMessage("error.**
>>>> userNotLoggedIn"));
>>>>             this.saveErrors(request, errors);
>>>>             String url = request.getServletPath() + "?" +
>>>> request.getQueryString();
>>>>             request.getSession().****setAttribute("forwardPath", url);
>>>>             return mapping.findForward("****sessionEnded");
>>>>         }
>>>>         return executeAction(mapping, form, request, response);
>>>>     }
>>>>
>>>>     /**
>>>>      *
>>>>      * @param mapping
>>>>      * @param form
>>>>      * @param request
>>>>      * @param response
>>>>      * @return
>>>>      * @throws IOException
>>>>      * @throws ServletException
>>>>      */
>>>>     protected abstract ActionForward executeAction(ActionMapping mapping,
>>>>             ActionForm form, HttpServletRequest request,
>>>>             HttpServletResponse response)
>>>>             throws IOException, ServletException;
>>>>
>>>>     private boolean userIsLoggedIn(****HttpServletRequest request) {
>>>>         UserInfo userInfo = (UserInfo) request.getSession().**
>>>> getAttribute("userInfo");
>>>>         String userName = null;
>>>>         try{
>>>>             userName = userInfo.getUserName();
>>>>         } catch (NullPointerException ex) {
>>>>             log.error("User hasn't logged in yet.");
>>>>             return false;
>>>>         }
>>>>
>>>>         if ( userName == null) {
>>>>             return false;
>>>>         }
>>>>         return true;
>>>>     }
>>>> }
>>>>
>>>> 2. Action class
>>>> public class ChangePasswordAction extends BaseAction {
>>>>
>>>>     private static Log log = LogFactory.getLog("****
>>>> ChangePasswordAction");
>>>>
>>>>     private static final String SUCCESS = "success";
>>>>
>>>>     private static final String FAILURE = "failure";
>>>>
>>>>     @Override
>>>>     public ActionForward executeAction(ActionMapping mapping, ActionForm
>>>> form,
>>>>             HttpServletRequest request, HttpServletResponse response)
>>>>             throws IOException, ServletException {
>>>>
>>>>         ActionErrors errors = new ActionErrors();
>>>>         ActionMessages messages = new ActionMessages();
>>>>
>>>>         ChangePasswordForm changePwdForm = (ChangePasswordForm) form;
>>>>         String userName = changePwdForm.getUserName();
>>>>         String oldPassword = changePwdForm.getOldPwd().****trim();
>>>>         String newPassword = changePwdForm.getPassword().****trim();
>>>>         UserDelegate userDelegate = new UserDelegate(userName, null);
>>>>         boolean isPasswordChanged = userDelegate.changePassword(****
>>>> userName,
>>>> oldPassword, newPassword);
>>>>
>>>>         if (isPasswordChanged) {
>>>>             messages.add("password", new ActionMessage("msg.**
>>>> changePasswordSuccess"));
>>>>             this.saveMessages(request, messages);
>>>>             log.info("Password changed successfully.");
>>>>             return mapping.findForward(SUCCESS);
>>>>         } else {
>>>>             errors.add("errors", new ActionMessage("msg.**
>>>> changePasswordError"));
>>>>             saveErrors(request, errors);
>>>>             log.error("Password can't be changed");
>>>>             return mapping.findForward(FAILURE);
>>>>         }
>>>>    }
>>>> }
>>>>
>>>> 3. Validation class
>>>> public class ChangePasswordForm extends ValidatorForm {
>>>>
>>>>     private String userName;
>>>>     private String oldPwd;
>>>>     private String password;
>>>>     private String confirmPwd;
>>>>
>>>>     /**
>>>>      *
>>>>      * @return
>>>>      */
>>>>     public String getPassword() {
>>>>         return password;
>>>>     }
>>>>
>>>>     /**
>>>>      *
>>>>      * @param password
>>>>      */
>>>>     public void setPassword(String password) {
>>>>         this.password = password;
>>>>     }
>>>>
>>>>     /**
>>>>      *
>>>>      * @return
>>>>      */
>>>>     public String getOldPwd() {
>>>>         return oldPwd;
>>>>     }
>>>>
>>>>     /**
>>>>      *
>>>>      * @param oldPwd
>>>>      */
>>>>     public void setOldPwd(String oldPwd) {
>>>>         this.oldPwd = oldPwd;
>>>>     }
>>>>
>>>>     /**
>>>>      *
>>>>      * @return
>>>>      */
>>>>     public String getConfirmPwd() {
>>>>         return confirmPwd;
>>>>     }
>>>>
>>>>     /**
>>>>      *
>>>>      * @param confirmPwd
>>>>      */
>>>>     public void setConfirmPwd(String confirmPwd) {
>>>>         this.confirmPwd = confirmPwd;
>>>>     }
>>>>
>>>>     /**
>>>>      *
>>>>      * @return
>>>>      */
>>>>     public String getUserName() {
>>>>         return userName;
>>>>     }
>>>>
>>>>     /**
>>>>      *
>>>>      * @param userName
>>>>      */
>>>>     public void setUserName(String userName) {
>>>>         this.userName = userName;
>>>>     }
>>>>
>>>>     /**
>>>>      *
>>>>      */
>>>>     public ChangePasswordForm() {
>>>>         super();
>>>>
>>>>     }
>>>>
>>>>     /**
>>>>      * This is the action called from the Struts framework.
>>>>      * @param mapping The ActionMapping used to select this instance.
>>>>      * @param request The HTTP Request we are processing.
>>>>      * @return set of errors.
>>>>      */
>>>>     @Override
>>>>     public ActionErrors validate(ActionMapping mapping, HttpServletRequest
>>>> request) {
>>>>         ActionErrors errors = new ActionErrors();
>>>>         if(userName.isEmpty()){
>>>>             errors.add("error", new ActionMessage("error.userName"****));
>>>>         }
>>>>         if(oldPwd.isEmpty()){
>>>>             errors.add("error", new ActionMessage("error.****
>>>> oldPassword"));
>>>>         }
>>>>         if(password.isEmpty()){
>>>>             errors.add("error", new ActionMessage("error.****
>>>> newPassword"));
>>>>         }
>>>>         if(!confirmPwd.equals(****password)){
>>>>             errors.add("error", new ActionMessage("error.**
>>>> confirmPassword"));
>>>>         }
>>>>         if(userName.equalsIgnoreCase(****password)){
>>>>             errors.add("error", new ActionMessage("error.**
>>>> sameAsUsername"));
>>>>         }
>>>>         if(oldPwd.equalsIgnoreCase(****password)){
>>>>             errors.add("error", new ActionMessage("error.****
>>>> samePassword"));
>>>>         }
>>>>         return errors;
>>>>     }
>>>>
>>>>     /**
>>>>      *
>>>>      * @param mapping
>>>>      * @param request
>>>>      */
>>>>     @Override
>>>>     public void reset(ActionMapping mapping, HttpServletRequest request) {
>>>>         userName = "";
>>>>         oldPwd = "";
>>>>         password = "";
>>>>         confirmPwd = "";
>>>>     }
>>>> }
>>>>
>>>> On 6/13/2012 11:10 AM, Jason Zheng wrote:
>>>>
>>>>   Anjib, would you like to show us the codes in the Action
>>>>> ChangePasswordAction?
>>>>>
>>>>> On Wed, Jun 13, 2012 at 10:58 PM, Dave Newton<da...@gmail.com>
>>>>>   wrote:
>>>>>
>>>>>   Then it's likely you're doing something wrong if you're forwarding to a
>>>>>
>>>>>> page before creating the info that page needs.
>>>>>>
>>>>>> Dave
>>>>>>
>>>>>> On Wed, Jun 13, 2012 at 10:53 AM, Anjib Mulepati<anjibcs@hotmail.com
>>>>>>
>>>>>>   wrote:
>>>>>>> Even though I put validation in ActionForm validate() method failure
>>>>>>> will
>>>>>>> take to changePasswordPage. I do have validation to check form field.
>>>>>>>
>>>>>>>
>>>>>>> On 6/13/2012 9:17 AM, Dave Newton wrote:
>>>>>>>
>>>>>>>   Maybe some sort of validation would be helpful.
>>>>>>>
>>>>>>>> Dave
>>>>>>>>
>>>>>>>> On Wed, Jun 13, 2012 at 9:03 AM, Anjib Mulepati<an...@hotmail.com>
>>>>>>>>   wrote:
>>>>>>>>
>>>>>>>>   Hi All,
>>>>>>>>
>>>>>>>>   I have question regarding handling form submission by direct URL in
>>>>>>>>> Struts
>>>>>>>>> 1.3.8
>>>>>>>>>
>>>>>>>>> I have a page to change password which user can access after they
>>>>>>>>>
>>>>>>>>>   login.
>>>>>>> URL for that page is http://localhost:8080/MyApp/******<http://localhost:8080/MyApp/****>
>>>>>>>
>>>>>>>> **changepassword.do<http://**localhost:8080/MyApp/******
>>>>>>>>> changepassword.do<http://localhost:8080/MyApp/****changepassword.do>
>>>>>>>>>   <http://localhost:8080/MyApp/******changepassword.do<http://localhost:8080/MyApp/****changepassword.do>
>>>>>>>> <http://**localhost:8080/MyApp/****changepassword.do<http://localhost:8080/MyApp/**changepassword.do>
>>>>>>> <http://**localhost:8080/****MyApp/**changepassword.do<
>>>>>>>
>>>>>>>> http://localhost:8080/MyApp/****changepassword.do<http://localhost:8080/MyApp/**changepassword.do>
>>>>>>>> <http://**localhost:8080/MyApp/**changepassword.do<http://localhost:8080/MyApp/changepassword.do>
>>>>>>>>> I have action mapping as follow:
>>>>>>>>> <action path="/changepassword" input="changePasswordPage"
>>>>>>>>>
>>>>>>>>>   scope="request"
>>>>>>>   name="ChangePasswordForm" type="com.anjib.actions.**
>>>>>>>
>>>>>>>> ChangePasswordAction">
>>>>>>>>> <forward name="success" path="changePasswordPage" />
>>>>>>>>> <forward name="failure" path="changePasswordPage"/>
>>>>>>>>> </action>
>>>>>>>>>
>>>>>>>>> I have tile definition for changePasswordPage which have page like
>>>>>>>>>
>>>>>>>>>   header
>>>>>>> which display welcome information after user login
>>>>>>>
>>>>>>>> <div id="welcome" class="right">
>>>>>>>>> <bean:message key="label.welcome" />
>>>>>>>>> <logic:notEmpty name="userInfo" property="firstName">
>>>>>>>>>          ${userInfo.firstName}&nbsp;${********userInfo.lastName}
>>>>>>>>>
>>>>>>>>> </logic:notEmpty>
>>>>>>>>> <logic:empty name="userInfo" property="firstName">
>>>>>>>>>             ${userInfo.userName}
>>>>>>>>> </logic:empty>
>>>>>>>>> </div>
>>>>>>>>>
>>>>>>>>> Now everything works fine if we follow normal process: Login and do
>>>>>>>>> actions. But if someone type URL http://localhost:8080/MyApp/**
>>>>>>>>> changepassword.do<http://******localhost:8080/MyApp/****
>>>>>>>>> changepassword.do<
>>>>>>>>>
>>>>>>>>>   http://localhost:8080/MyApp/****changepassword.do<http://localhost:8080/MyApp/**changepassword.do>
>>>>>>>> <http://**localhost:8080/MyApp/**changepassword.do<http://localhost:8080/MyApp/changepassword.do>
>>>>>>>> directly
>>>>>>>>
>>>>>>> then I don't get page and I have error in Tomcat log
>>>>>>>
>>>>>>>> Caused by: javax.servlet.jsp.********JspException: Cannot find bean:
>>>>>>>>> "userInfo"
>>>>>>>>>
>>>>>>>>> in any scope
>>>>>>>>>
>>>>>>>>> Any help will be appreciated.
>>>>>>>>>
>>>>>>>>> Thanks,
>>>>>>>>> Anjib
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> ------------------------------********------------------------**
>>>>>>>>> --**--**
>>>>>>>>> --**---------
>>>>>>>>> To unsubscribe, e-mail: user-unsubscribe@struts.******apac**he.org<
>>>>>>>>>
>>>>>>>>>   http://apache.org>
>>>>>>> <user-unsubscribe@**struts.**a**pache.org<http://apache.org><
>>>>>>> http://struts.**apache.org<http://struts.apache.org>><
>>>>>>>
>>>>>>>> user-unsubscribe@struts.**apac**he.org<http://apache.org><
>>>>>>>> user-unsubscribe@**struts.apache.org<us...@struts.apache.org>
>>>>>>> For additional commands, e-mail: user-help@struts.apache.org
>>>>>>>
>>>>>>>>>   ------------------------------******--------------------------**
>>>>>>>>> --**
>>>>>>>>>
>>>>>>>> --**---------
>>>>>>> To unsubscribe, e-mail: user-unsubscribe@struts.****apac**he.org<
>>>>>>> http://apache.org**>
>>>>>>> <
>>>>>>>
>>>>>>>   user-unsubscribe@struts.**apac**he.org<http://apache.org><
>>>>>> user-unsubscribe@**struts.apache.org<us...@struts.apache.org>
>>>>>>> For additional commands, e-mail: user-help@struts.apache.org
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>   ------------------------------****----------------------------**
>>>> --**---------
>>>> To unsubscribe, e-mail: user-unsubscribe@struts.**apac**he.org<http://apache.org>
>>>> <us...@struts.apache.org>
>>>> For additional commands, e-mail: user-help@struts.apache.org
>>>>
>>>>
>>>>
>> ------------------------------**------------------------------**---------
>> To unsubscribe, e-mail: user-unsubscribe@struts.**apache.org<us...@struts.apache.org>
>>
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Form handling by direct URL in Struts 1.3.8

Posted by Jason Zheng <mr...@gmail.com>.
That's the problem, when you type the URL directly, the
LoginSubmitAction.execute() method will not be invoked, so the 'userinfo'
is not exits in any scope.

On Wed, Jun 13, 2012 at 11:58 PM, Anjib Mulepati <an...@hotmail.com>wrote:

> User info is put into session after they log in so its in
> LoginSubmitAction class.
>
> public class LoginSubmitAction extends org.apache.struts.action.**Action {
>
>    private static final String ERROR = "errorFront";
>
>
>    private static final String SUCCESS = "success";
>
>    private static Log log = LogFactory.getLog("**LoginSubmitAction");
>
>
>     @Override
>    public ActionForward execute(ActionMapping mapping, ActionForm form,
>            HttpServletRequest request, HttpServletResponse response)
>            throws Exception {
>
>        LoginForm loginForm = (LoginForm) form;
>        String forwardPath = (String) request.getSession().**
> getAttribute("forwardPath");
>        String userName = loginForm.getUserName().**toLowerCase();
>        String passWord = loginForm.getPassword();
>        UserInfo userInfo = new UserInfo();
>
>        ActionForward objAxFrwd = null;
>        try {
>            /* Authenticate user */
>
>            UserDelegate userDelegate = new UserDelegate(userName, null);
>            userDelegate.validateUser(**userName, passWord);
>            log.info("User authenticated: " + userName);
>
>            /* Get user profile and store in beans then to session variable
> */
>            UserProfileInfo userProfileInfo = userDelegate.getUserProfile(*
> *userName);
>            userInfo.setUserName(**userProfileInfo.getUserName())**;
> //Currently username is same as email address.
>            userInfo.setPassword(passWord)**;
>            userInfo.setFirstName(**userProfileInfo.getFirstName()**);
>            userInfo.setLastName(**userProfileInfo.getLastName())**;
>            userInfo.setEmail(**userProfileInfo.getEmail());
>            userInfo.setPhone(**userProfileInfo.getPhone());
>
>
>
>        } catch (BusinessDelegateException e) {
>            /* User not authenticated */
>            log.error(e.getErrorCode() + ": User not authenticated: " +
> userName);
>
>            ActionErrors errors = new ActionErrors();
>            errors.add("error", new ActionMessage(e.getMessage(), false));
>            this.saveErrors(request, errors);
>            return mapping.findForward(ERROR);
>        } catch (org.apache.cxf.binding.soap.**SoapFault s){
>            log.error(s);
>            return mapping.findForward(ERROR);
>        }
>
>        /* Forward control to the specified success URI */
>        if (forwardPath != null) {
>            objAxFrwd = new ActionForward(forwardPath);
>        } else {
>            objAxFrwd = mapping.findForward(SUCCESS);
>        }
>        request.getSession().**setAttribute("userInfo", userInfo);
>        request.getSession().**setAttribute("userName", userName);
>        return objAxFrwd;
>
>    }
> }
> On 6/13/2012 11:51 AM, Dave Newton wrote:
>
>> I don't see anything that puts a user info into session (or request, I
>> forgot where it was), so it makes sense the JSP would fail.
>>
>> [OT] In the future, consider removing useless, empty comments so people
>> trying to help have less work to do :)
>>
>> Dave
>>
>> On Wed, Jun 13, 2012 at 11:43 AM, Anjib Mulepati<an...@hotmail.com>**
>> wrote:
>>
>>  1. Base Class
>>> public abstract class BaseAction extends org.apache.struts.action.****
>>> Action
>>> {
>>>
>>>    private static Log log = LogFactory.getLog("BaseAction"****);
>>>
>>>    /**
>>>     *
>>>     * @param mapping
>>>     * @param form
>>>     * @param request
>>>     * @param response
>>>     * @return
>>>     * @throws IOException
>>>     * @throws ServletException
>>>     * @throws BusinessDelegateException
>>>     */
>>>    @Override
>>>    public ActionForward execute(ActionMapping mapping, ActionForm form,
>>>            HttpServletRequest request, HttpServletResponse response)
>>>            throws IOException, ServletException,
>>> BusinessDelegateException
>>> {
>>>
>>>        if (!this.userIsLoggedIn(request)****) {
>>>            ActionErrors errors = new ActionErrors();
>>>            errors.add("error", new ActionMessage("error.**
>>> userNotLoggedIn"));
>>>            this.saveErrors(request, errors);
>>>            String url = request.getServletPath() + "?" +
>>> request.getQueryString();
>>>            request.getSession().****setAttribute("forwardPath", url);
>>>            return mapping.findForward("****sessionEnded");
>>>        }
>>>        return executeAction(mapping, form, request, response);
>>>    }
>>>
>>>    /**
>>>     *
>>>     * @param mapping
>>>     * @param form
>>>     * @param request
>>>     * @param response
>>>     * @return
>>>     * @throws IOException
>>>     * @throws ServletException
>>>     */
>>>    protected abstract ActionForward executeAction(ActionMapping mapping,
>>>            ActionForm form, HttpServletRequest request,
>>>            HttpServletResponse response)
>>>            throws IOException, ServletException;
>>>
>>>    private boolean userIsLoggedIn(****HttpServletRequest request) {
>>>        UserInfo userInfo = (UserInfo) request.getSession().**
>>> getAttribute("userInfo");
>>>        String userName = null;
>>>        try{
>>>            userName = userInfo.getUserName();
>>>        } catch (NullPointerException ex) {
>>>            log.error("User hasn't logged in yet.");
>>>            return false;
>>>        }
>>>
>>>        if ( userName == null) {
>>>            return false;
>>>        }
>>>        return true;
>>>    }
>>> }
>>>
>>> 2. Action class
>>> public class ChangePasswordAction extends BaseAction {
>>>
>>>    private static Log log = LogFactory.getLog("****
>>> ChangePasswordAction");
>>>
>>>    private static final String SUCCESS = "success";
>>>
>>>    private static final String FAILURE = "failure";
>>>
>>>    @Override
>>>    public ActionForward executeAction(ActionMapping mapping, ActionForm
>>> form,
>>>            HttpServletRequest request, HttpServletResponse response)
>>>            throws IOException, ServletException {
>>>
>>>        ActionErrors errors = new ActionErrors();
>>>        ActionMessages messages = new ActionMessages();
>>>
>>>        ChangePasswordForm changePwdForm = (ChangePasswordForm) form;
>>>        String userName = changePwdForm.getUserName();
>>>        String oldPassword = changePwdForm.getOldPwd().****trim();
>>>        String newPassword = changePwdForm.getPassword().****trim();
>>>        UserDelegate userDelegate = new UserDelegate(userName, null);
>>>        boolean isPasswordChanged = userDelegate.changePassword(****
>>> userName,
>>> oldPassword, newPassword);
>>>
>>>        if (isPasswordChanged) {
>>>            messages.add("password", new ActionMessage("msg.**
>>> changePasswordSuccess"));
>>>            this.saveMessages(request, messages);
>>>            log.info("Password changed successfully.");
>>>            return mapping.findForward(SUCCESS);
>>>        } else {
>>>            errors.add("errors", new ActionMessage("msg.**
>>> changePasswordError"));
>>>            saveErrors(request, errors);
>>>            log.error("Password can't be changed");
>>>            return mapping.findForward(FAILURE);
>>>        }
>>>   }
>>> }
>>>
>>> 3. Validation class
>>> public class ChangePasswordForm extends ValidatorForm {
>>>
>>>    private String userName;
>>>    private String oldPwd;
>>>    private String password;
>>>    private String confirmPwd;
>>>
>>>    /**
>>>     *
>>>     * @return
>>>     */
>>>    public String getPassword() {
>>>        return password;
>>>    }
>>>
>>>    /**
>>>     *
>>>     * @param password
>>>     */
>>>    public void setPassword(String password) {
>>>        this.password = password;
>>>    }
>>>
>>>    /**
>>>     *
>>>     * @return
>>>     */
>>>    public String getOldPwd() {
>>>        return oldPwd;
>>>    }
>>>
>>>    /**
>>>     *
>>>     * @param oldPwd
>>>     */
>>>    public void setOldPwd(String oldPwd) {
>>>        this.oldPwd = oldPwd;
>>>    }
>>>
>>>    /**
>>>     *
>>>     * @return
>>>     */
>>>    public String getConfirmPwd() {
>>>        return confirmPwd;
>>>    }
>>>
>>>    /**
>>>     *
>>>     * @param confirmPwd
>>>     */
>>>    public void setConfirmPwd(String confirmPwd) {
>>>        this.confirmPwd = confirmPwd;
>>>    }
>>>
>>>    /**
>>>     *
>>>     * @return
>>>     */
>>>    public String getUserName() {
>>>        return userName;
>>>    }
>>>
>>>    /**
>>>     *
>>>     * @param userName
>>>     */
>>>    public void setUserName(String userName) {
>>>        this.userName = userName;
>>>    }
>>>
>>>    /**
>>>     *
>>>     */
>>>    public ChangePasswordForm() {
>>>        super();
>>>
>>>    }
>>>
>>>    /**
>>>     * This is the action called from the Struts framework.
>>>     * @param mapping The ActionMapping used to select this instance.
>>>     * @param request The HTTP Request we are processing.
>>>     * @return set of errors.
>>>     */
>>>    @Override
>>>    public ActionErrors validate(ActionMapping mapping, HttpServletRequest
>>> request) {
>>>        ActionErrors errors = new ActionErrors();
>>>        if(userName.isEmpty()){
>>>            errors.add("error", new ActionMessage("error.userName"****));
>>>        }
>>>        if(oldPwd.isEmpty()){
>>>            errors.add("error", new ActionMessage("error.****
>>> oldPassword"));
>>>        }
>>>        if(password.isEmpty()){
>>>            errors.add("error", new ActionMessage("error.****
>>> newPassword"));
>>>        }
>>>        if(!confirmPwd.equals(****password)){
>>>            errors.add("error", new ActionMessage("error.**
>>> confirmPassword"));
>>>        }
>>>        if(userName.equalsIgnoreCase(****password)){
>>>            errors.add("error", new ActionMessage("error.**
>>> sameAsUsername"));
>>>        }
>>>        if(oldPwd.equalsIgnoreCase(****password)){
>>>            errors.add("error", new ActionMessage("error.****
>>> samePassword"));
>>>        }
>>>        return errors;
>>>    }
>>>
>>>    /**
>>>     *
>>>     * @param mapping
>>>     * @param request
>>>     */
>>>    @Override
>>>    public void reset(ActionMapping mapping, HttpServletRequest request) {
>>>        userName = "";
>>>        oldPwd = "";
>>>        password = "";
>>>        confirmPwd = "";
>>>    }
>>> }
>>>
>>> On 6/13/2012 11:10 AM, Jason Zheng wrote:
>>>
>>>  Anjib, would you like to show us the codes in the Action
>>>> ChangePasswordAction?
>>>>
>>>> On Wed, Jun 13, 2012 at 10:58 PM, Dave Newton<da...@gmail.com>
>>>>  wrote:
>>>>
>>>>  Then it's likely you're doing something wrong if you're forwarding to a
>>>>
>>>>> page before creating the info that page needs.
>>>>>
>>>>> Dave
>>>>>
>>>>> On Wed, Jun 13, 2012 at 10:53 AM, Anjib Mulepati<anjibcs@hotmail.com
>>>>>
>>>>>  wrote:
>>>>>> Even though I put validation in ActionForm validate() method failure
>>>>>> will
>>>>>> take to changePasswordPage. I do have validation to check form field.
>>>>>>
>>>>>>
>>>>>> On 6/13/2012 9:17 AM, Dave Newton wrote:
>>>>>>
>>>>>>  Maybe some sort of validation would be helpful.
>>>>>>
>>>>>>> Dave
>>>>>>>
>>>>>>> On Wed, Jun 13, 2012 at 9:03 AM, Anjib Mulepati<an...@hotmail.com>
>>>>>>>  wrote:
>>>>>>>
>>>>>>>  Hi All,
>>>>>>>
>>>>>>>  I have question regarding handling form submission by direct URL in
>>>>>>>> Struts
>>>>>>>> 1.3.8
>>>>>>>>
>>>>>>>> I have a page to change password which user can access after they
>>>>>>>>
>>>>>>>>  login.
>>>>>>>
>>>>>> URL for that page is http://localhost:8080/MyApp/******<http://localhost:8080/MyApp/****>
>>>>>>
>>>>>>> **changepassword.do<http://**localhost:8080/MyApp/******
>>>>>>>> changepassword.do<http://localhost:8080/MyApp/****changepassword.do>
>>>>>>>> >
>>>>>>>>
>>>>>>>>  <http://localhost:8080/MyApp/******changepassword.do<http://localhost:8080/MyApp/****changepassword.do>
>>>>>>> <http://**localhost:8080/MyApp/****changepassword.do<http://localhost:8080/MyApp/**changepassword.do>
>>>>>>> >
>>>>>>>
>>>>>> <http://**localhost:8080/****MyApp/**changepassword.do<
>>>>>>
>>>>>>> http://localhost:8080/MyApp/****changepassword.do<http://localhost:8080/MyApp/**changepassword.do>
>>>>>>> <http://**localhost:8080/MyApp/**changepassword.do<http://localhost:8080/MyApp/changepassword.do>
>>>>>>> >
>>>>>>>
>>>>>>>> I have action mapping as follow:
>>>>>>>> <action path="/changepassword" input="changePasswordPage"
>>>>>>>>
>>>>>>>>  scope="request"
>>>>>>>
>>>>>>  name="ChangePasswordForm" type="com.anjib.actions.**
>>>>>>
>>>>>>> ChangePasswordAction">
>>>>>>>> <forward name="success" path="changePasswordPage" />
>>>>>>>> <forward name="failure" path="changePasswordPage"/>
>>>>>>>> </action>
>>>>>>>>
>>>>>>>> I have tile definition for changePasswordPage which have page like
>>>>>>>>
>>>>>>>>  header
>>>>>>>
>>>>>> which display welcome information after user login
>>>>>>
>>>>>>> <div id="welcome" class="right">
>>>>>>>> <bean:message key="label.welcome" />
>>>>>>>> <logic:notEmpty name="userInfo" property="firstName">
>>>>>>>>         ${userInfo.firstName}&nbsp;${********userInfo.lastName}
>>>>>>>>
>>>>>>>> </logic:notEmpty>
>>>>>>>> <logic:empty name="userInfo" property="firstName">
>>>>>>>>            ${userInfo.userName}
>>>>>>>> </logic:empty>
>>>>>>>> </div>
>>>>>>>>
>>>>>>>> Now everything works fine if we follow normal process: Login and do
>>>>>>>> actions. But if someone type URL http://localhost:8080/MyApp/**
>>>>>>>> changepassword.do<http://******localhost:8080/MyApp/****
>>>>>>>> changepassword.do<
>>>>>>>>
>>>>>>>>  http://localhost:8080/MyApp/****changepassword.do<http://localhost:8080/MyApp/**changepassword.do>
>>>>>>> <http://**localhost:8080/MyApp/**changepassword.do<http://localhost:8080/MyApp/changepassword.do>
>>>>>>> >
>>>>>>> directly
>>>>>>>
>>>>>> then I don't get page and I have error in Tomcat log
>>>>>>
>>>>>>> Caused by: javax.servlet.jsp.********JspException: Cannot find bean:
>>>>>>>> "userInfo"
>>>>>>>>
>>>>>>>> in any scope
>>>>>>>>
>>>>>>>> Any help will be appreciated.
>>>>>>>>
>>>>>>>> Thanks,
>>>>>>>> Anjib
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> ------------------------------********------------------------**
>>>>>>>> --**--**
>>>>>>>> --**---------
>>>>>>>> To unsubscribe, e-mail: user-unsubscribe@struts.******apac**he.org<
>>>>>>>>
>>>>>>>>  http://apache.org>
>>>>>>>
>>>>>> <user-unsubscribe@**struts.**a**pache.org <http://apache.org><
>>>>>> http://struts.**apache.org <http://struts.apache.org>><
>>>>>>
>>>>>>> user-unsubscribe@struts.**apac**he.org <http://apache.org><
>>>>>>> user-unsubscribe@**struts.apache.org<us...@struts.apache.org>
>>>>>>> >
>>>>>>>
>>>>>> For additional commands, e-mail: user-help@struts.apache.org
>>>>>>
>>>>>>>
>>>>>>>>
>>>>>>>>  ------------------------------******--------------------------**
>>>>>>>> --**
>>>>>>>>
>>>>>>> --**---------
>>>>>> To unsubscribe, e-mail: user-unsubscribe@struts.****apac**he.org<
>>>>>> http://apache.org**>
>>>>>> <
>>>>>>
>>>>>>  user-unsubscribe@struts.**apac**he.org <http://apache.org><
>>>>> user-unsubscribe@**struts.apache.org<us...@struts.apache.org>
>>>>> >
>>>>>
>>>>>> For additional commands, e-mail: user-help@struts.apache.org
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>  ------------------------------****----------------------------**
>>> --**---------
>>> To unsubscribe, e-mail: user-unsubscribe@struts.**apac**he.org<http://apache.org>
>>> <us...@struts.apache.org>
>>> >
>>> For additional commands, e-mail: user-help@struts.apache.org
>>>
>>>
>>>
>
> ------------------------------**------------------------------**---------
> To unsubscribe, e-mail: user-unsubscribe@struts.**apache.org<us...@struts.apache.org>
>
> For additional commands, e-mail: user-help@struts.apache.org
>
>


-- 
Thanks
Jason

Re: Form handling by direct URL in Struts 1.3.8

Posted by Anjib Mulepati <an...@hotmail.com>.
User info is put into session after they log in so its in 
LoginSubmitAction class.

public class LoginSubmitAction extends org.apache.struts.action.Action {

     private static final String ERROR = "errorFront";

     private static final String SUCCESS = "success";

     private static Log log = LogFactory.getLog("LoginSubmitAction");

      @Override
     public ActionForward execute(ActionMapping mapping, ActionForm form,
             HttpServletRequest request, HttpServletResponse response)
             throws Exception {

         LoginForm loginForm = (LoginForm) form;
         String forwardPath = (String) 
request.getSession().getAttribute("forwardPath");
         String userName = loginForm.getUserName().toLowerCase();
         String passWord = loginForm.getPassword();
         UserInfo userInfo = new UserInfo();

         ActionForward objAxFrwd = null;
         try {
             /* Authenticate user */
             UserDelegate userDelegate = new UserDelegate(userName, null);
             userDelegate.validateUser(userName, passWord);
             log.info("User authenticated: " + userName);

             /* Get user profile and store in beans then to session 
variable */
             UserProfileInfo userProfileInfo = 
userDelegate.getUserProfile(userName);
             userInfo.setUserName(userProfileInfo.getUserName()); 
//Currently username is same as email address.
             userInfo.setPassword(passWord);
             userInfo.setFirstName(userProfileInfo.getFirstName());
             userInfo.setLastName(userProfileInfo.getLastName());
             userInfo.setEmail(userProfileInfo.getEmail());
             userInfo.setPhone(userProfileInfo.getPhone());



         } catch (BusinessDelegateException e) {
             /* User not authenticated */
             log.error(e.getErrorCode() + ": User not authenticated: " + 
userName);
             ActionErrors errors = new ActionErrors();
             errors.add("error", new ActionMessage(e.getMessage(), false));
             this.saveErrors(request, errors);
             return mapping.findForward(ERROR);
         } catch (org.apache.cxf.binding.soap.SoapFault s){
             log.error(s);
             return mapping.findForward(ERROR);
         }

         /* Forward control to the specified success URI */
         if (forwardPath != null) {
             objAxFrwd = new ActionForward(forwardPath);
         } else {
             objAxFrwd = mapping.findForward(SUCCESS);
         }
         request.getSession().setAttribute("userInfo", userInfo);
         request.getSession().setAttribute("userName", userName);
         return objAxFrwd;
     }
}
On 6/13/2012 11:51 AM, Dave Newton wrote:
> I don't see anything that puts a user info into session (or request, I
> forgot where it was), so it makes sense the JSP would fail.
>
> [OT] In the future, consider removing useless, empty comments so people
> trying to help have less work to do :)
>
> Dave
>
> On Wed, Jun 13, 2012 at 11:43 AM, Anjib Mulepati<an...@hotmail.com>wrote:
>
>> 1. Base Class
>> public abstract class BaseAction extends org.apache.struts.action.**Action
>> {
>>
>>     private static Log log = LogFactory.getLog("BaseAction"**);
>>
>>     /**
>>      *
>>      * @param mapping
>>      * @param form
>>      * @param request
>>      * @param response
>>      * @return
>>      * @throws IOException
>>      * @throws ServletException
>>      * @throws BusinessDelegateException
>>      */
>>     @Override
>>     public ActionForward execute(ActionMapping mapping, ActionForm form,
>>             HttpServletRequest request, HttpServletResponse response)
>>             throws IOException, ServletException, BusinessDelegateException
>> {
>>
>>         if (!this.userIsLoggedIn(request)**) {
>>             ActionErrors errors = new ActionErrors();
>>             errors.add("error", new ActionMessage("error.**
>> userNotLoggedIn"));
>>             this.saveErrors(request, errors);
>>             String url = request.getServletPath() + "?" +
>> request.getQueryString();
>>             request.getSession().**setAttribute("forwardPath", url);
>>             return mapping.findForward("**sessionEnded");
>>         }
>>         return executeAction(mapping, form, request, response);
>>     }
>>
>>     /**
>>      *
>>      * @param mapping
>>      * @param form
>>      * @param request
>>      * @param response
>>      * @return
>>      * @throws IOException
>>      * @throws ServletException
>>      */
>>     protected abstract ActionForward executeAction(ActionMapping mapping,
>>             ActionForm form, HttpServletRequest request,
>>             HttpServletResponse response)
>>             throws IOException, ServletException;
>>
>>     private boolean userIsLoggedIn(**HttpServletRequest request) {
>>         UserInfo userInfo = (UserInfo) request.getSession().**
>> getAttribute("userInfo");
>>         String userName = null;
>>         try{
>>             userName = userInfo.getUserName();
>>         } catch (NullPointerException ex) {
>>             log.error("User hasn't logged in yet.");
>>             return false;
>>         }
>>
>>         if ( userName == null) {
>>             return false;
>>         }
>>         return true;
>>     }
>> }
>>
>> 2. Action class
>> public class ChangePasswordAction extends BaseAction {
>>
>>     private static Log log = LogFactory.getLog("**ChangePasswordAction");
>>
>>     private static final String SUCCESS = "success";
>>
>>     private static final String FAILURE = "failure";
>>
>>     @Override
>>     public ActionForward executeAction(ActionMapping mapping, ActionForm
>> form,
>>             HttpServletRequest request, HttpServletResponse response)
>>             throws IOException, ServletException {
>>
>>         ActionErrors errors = new ActionErrors();
>>         ActionMessages messages = new ActionMessages();
>>
>>         ChangePasswordForm changePwdForm = (ChangePasswordForm) form;
>>         String userName = changePwdForm.getUserName();
>>         String oldPassword = changePwdForm.getOldPwd().**trim();
>>         String newPassword = changePwdForm.getPassword().**trim();
>>         UserDelegate userDelegate = new UserDelegate(userName, null);
>>         boolean isPasswordChanged = userDelegate.changePassword(**userName,
>> oldPassword, newPassword);
>>
>>         if (isPasswordChanged) {
>>             messages.add("password", new ActionMessage("msg.**
>> changePasswordSuccess"));
>>             this.saveMessages(request, messages);
>>             log.info("Password changed successfully.");
>>             return mapping.findForward(SUCCESS);
>>         } else {
>>             errors.add("errors", new ActionMessage("msg.**
>> changePasswordError"));
>>             saveErrors(request, errors);
>>             log.error("Password can't be changed");
>>             return mapping.findForward(FAILURE);
>>         }
>>    }
>> }
>>
>> 3. Validation class
>> public class ChangePasswordForm extends ValidatorForm {
>>
>>     private String userName;
>>     private String oldPwd;
>>     private String password;
>>     private String confirmPwd;
>>
>>     /**
>>      *
>>      * @return
>>      */
>>     public String getPassword() {
>>         return password;
>>     }
>>
>>     /**
>>      *
>>      * @param password
>>      */
>>     public void setPassword(String password) {
>>         this.password = password;
>>     }
>>
>>     /**
>>      *
>>      * @return
>>      */
>>     public String getOldPwd() {
>>         return oldPwd;
>>     }
>>
>>     /**
>>      *
>>      * @param oldPwd
>>      */
>>     public void setOldPwd(String oldPwd) {
>>         this.oldPwd = oldPwd;
>>     }
>>
>>     /**
>>      *
>>      * @return
>>      */
>>     public String getConfirmPwd() {
>>         return confirmPwd;
>>     }
>>
>>     /**
>>      *
>>      * @param confirmPwd
>>      */
>>     public void setConfirmPwd(String confirmPwd) {
>>         this.confirmPwd = confirmPwd;
>>     }
>>
>>     /**
>>      *
>>      * @return
>>      */
>>     public String getUserName() {
>>         return userName;
>>     }
>>
>>     /**
>>      *
>>      * @param userName
>>      */
>>     public void setUserName(String userName) {
>>         this.userName = userName;
>>     }
>>
>>     /**
>>      *
>>      */
>>     public ChangePasswordForm() {
>>         super();
>>
>>     }
>>
>>     /**
>>      * This is the action called from the Struts framework.
>>      * @param mapping The ActionMapping used to select this instance.
>>      * @param request The HTTP Request we are processing.
>>      * @return set of errors.
>>      */
>>     @Override
>>     public ActionErrors validate(ActionMapping mapping, HttpServletRequest
>> request) {
>>         ActionErrors errors = new ActionErrors();
>>         if(userName.isEmpty()){
>>             errors.add("error", new ActionMessage("error.userName"**));
>>         }
>>         if(oldPwd.isEmpty()){
>>             errors.add("error", new ActionMessage("error.**oldPassword"));
>>         }
>>         if(password.isEmpty()){
>>             errors.add("error", new ActionMessage("error.**newPassword"));
>>         }
>>         if(!confirmPwd.equals(**password)){
>>             errors.add("error", new ActionMessage("error.**
>> confirmPassword"));
>>         }
>>         if(userName.equalsIgnoreCase(**password)){
>>             errors.add("error", new ActionMessage("error.**
>> sameAsUsername"));
>>         }
>>         if(oldPwd.equalsIgnoreCase(**password)){
>>             errors.add("error", new ActionMessage("error.**samePassword"));
>>         }
>>         return errors;
>>     }
>>
>>     /**
>>      *
>>      * @param mapping
>>      * @param request
>>      */
>>     @Override
>>     public void reset(ActionMapping mapping, HttpServletRequest request) {
>>         userName = "";
>>         oldPwd = "";
>>         password = "";
>>         confirmPwd = "";
>>     }
>> }
>>
>> On 6/13/2012 11:10 AM, Jason Zheng wrote:
>>
>>> Anjib, would you like to show us the codes in the Action
>>> ChangePasswordAction?
>>>
>>> On Wed, Jun 13, 2012 at 10:58 PM, Dave Newton<da...@gmail.com>
>>>   wrote:
>>>
>>>   Then it's likely you're doing something wrong if you're forwarding to a
>>>> page before creating the info that page needs.
>>>>
>>>> Dave
>>>>
>>>> On Wed, Jun 13, 2012 at 10:53 AM, Anjib Mulepati<anjibcs@hotmail.com
>>>>
>>>>> wrote:
>>>>> Even though I put validation in ActionForm validate() method failure
>>>>> will
>>>>> take to changePasswordPage. I do have validation to check form field.
>>>>>
>>>>>
>>>>> On 6/13/2012 9:17 AM, Dave Newton wrote:
>>>>>
>>>>>   Maybe some sort of validation would be helpful.
>>>>>> Dave
>>>>>>
>>>>>> On Wed, Jun 13, 2012 at 9:03 AM, Anjib Mulepati<an...@hotmail.com>
>>>>>>   wrote:
>>>>>>
>>>>>>   Hi All,
>>>>>>
>>>>>>> I have question regarding handling form submission by direct URL in
>>>>>>> Struts
>>>>>>> 1.3.8
>>>>>>>
>>>>>>> I have a page to change password which user can access after they
>>>>>>>
>>>>>> login.
>>>>> URL for that page is http://localhost:8080/MyApp/****
>>>>>>> **changepassword.do<http://localhost:8080/MyApp/****changepassword.do>
>>>>>>>
>>>>>> <http://localhost:8080/MyApp/****changepassword.do<http://localhost:8080/MyApp/**changepassword.do>
>>>>> <http://**localhost:8080/**MyApp/**changepassword.do<
>>>>>> http://localhost:8080/MyApp/**changepassword.do<http://localhost:8080/MyApp/changepassword.do>
>>>>>>> I have action mapping as follow:
>>>>>>> <action path="/changepassword" input="changePasswordPage"
>>>>>>>
>>>>>> scope="request"
>>>>>   name="ChangePasswordForm" type="com.anjib.actions.**
>>>>>>> ChangePasswordAction">
>>>>>>> <forward name="success" path="changePasswordPage" />
>>>>>>> <forward name="failure" path="changePasswordPage"/>
>>>>>>> </action>
>>>>>>>
>>>>>>> I have tile definition for changePasswordPage which have page like
>>>>>>>
>>>>>> header
>>>>> which display welcome information after user login
>>>>>>> <div id="welcome" class="right">
>>>>>>> <bean:message key="label.welcome" />
>>>>>>> <logic:notEmpty name="userInfo" property="firstName">
>>>>>>>          ${userInfo.firstName}&nbsp;${******userInfo.lastName}
>>>>>>>
>>>>>>> </logic:notEmpty>
>>>>>>> <logic:empty name="userInfo" property="firstName">
>>>>>>>             ${userInfo.userName}
>>>>>>> </logic:empty>
>>>>>>> </div>
>>>>>>>
>>>>>>> Now everything works fine if we follow normal process: Login and do
>>>>>>> actions. But if someone type URL http://localhost:8080/MyApp/**
>>>>>>> changepassword.do<http://****localhost:8080/MyApp/****
>>>>>>> changepassword.do<
>>>>>>>
>>>>>> http://localhost:8080/MyApp/**changepassword.do<http://localhost:8080/MyApp/changepassword.do>
>>>>>> directly
>>>>> then I don't get page and I have error in Tomcat log
>>>>>>> Caused by: javax.servlet.jsp.******JspException: Cannot find bean:
>>>>>>> "userInfo"
>>>>>>>
>>>>>>> in any scope
>>>>>>>
>>>>>>> Any help will be appreciated.
>>>>>>>
>>>>>>> Thanks,
>>>>>>> Anjib
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> ------------------------------******--------------------------**--**
>>>>>>> --**---------
>>>>>>> To unsubscribe, e-mail: user-unsubscribe@struts.****apac**he.org<
>>>>>>>
>>>>>> http://apache.org>
>>>>> <user-unsubscribe@**struts.**apache.org<http://struts.apache.org><
>>>>>> user-unsubscribe@struts.**apache.org<us...@struts.apache.org>
>>>>> For additional commands, e-mail: user-help@struts.apache.org
>>>>>>>
>>>>>>>
>>>>>>>   ------------------------------****----------------------------**
>>>>> --**---------
>>>>> To unsubscribe, e-mail: user-unsubscribe@struts.**apac**he.org<http://apache.org>
>>>>> <
>>>>>
>>>> user-unsubscribe@struts.**apache.org<us...@struts.apache.org>
>>>>> For additional commands, e-mail: user-help@struts.apache.org
>>>>>
>>>>>
>>>>>
>>>
>> ------------------------------**------------------------------**---------
>> To unsubscribe, e-mail: user-unsubscribe@struts.**apache.org<us...@struts.apache.org>
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Form handling by direct URL in Struts 1.3.8

Posted by Dave Newton <da...@gmail.com>.
I don't see anything that puts a user info into session (or request, I
forgot where it was), so it makes sense the JSP would fail.

[OT] In the future, consider removing useless, empty comments so people
trying to help have less work to do :)

Dave

On Wed, Jun 13, 2012 at 11:43 AM, Anjib Mulepati <an...@hotmail.com>wrote:

> 1. Base Class
> public abstract class BaseAction extends org.apache.struts.action.**Action
> {
>
>    private static Log log = LogFactory.getLog("BaseAction"**);
>
>    /**
>     *
>     * @param mapping
>     * @param form
>     * @param request
>     * @param response
>     * @return
>     * @throws IOException
>     * @throws ServletException
>     * @throws BusinessDelegateException
>     */
>    @Override
>    public ActionForward execute(ActionMapping mapping, ActionForm form,
>            HttpServletRequest request, HttpServletResponse response)
>            throws IOException, ServletException, BusinessDelegateException
> {
>
>        if (!this.userIsLoggedIn(request)**) {
>            ActionErrors errors = new ActionErrors();
>            errors.add("error", new ActionMessage("error.**
> userNotLoggedIn"));
>            this.saveErrors(request, errors);
>            String url = request.getServletPath() + "?" +
> request.getQueryString();
>            request.getSession().**setAttribute("forwardPath", url);
>            return mapping.findForward("**sessionEnded");
>        }
>        return executeAction(mapping, form, request, response);
>    }
>
>    /**
>     *
>     * @param mapping
>     * @param form
>     * @param request
>     * @param response
>     * @return
>     * @throws IOException
>     * @throws ServletException
>     */
>    protected abstract ActionForward executeAction(ActionMapping mapping,
>            ActionForm form, HttpServletRequest request,
>            HttpServletResponse response)
>            throws IOException, ServletException;
>
>    private boolean userIsLoggedIn(**HttpServletRequest request) {
>        UserInfo userInfo = (UserInfo) request.getSession().**
> getAttribute("userInfo");
>        String userName = null;
>        try{
>            userName = userInfo.getUserName();
>        } catch (NullPointerException ex) {
>            log.error("User hasn't logged in yet.");
>            return false;
>        }
>
>        if ( userName == null) {
>            return false;
>        }
>        return true;
>    }
> }
>
> 2. Action class
> public class ChangePasswordAction extends BaseAction {
>
>    private static Log log = LogFactory.getLog("**ChangePasswordAction");
>
>    private static final String SUCCESS = "success";
>
>    private static final String FAILURE = "failure";
>
>    @Override
>    public ActionForward executeAction(ActionMapping mapping, ActionForm
> form,
>            HttpServletRequest request, HttpServletResponse response)
>            throws IOException, ServletException {
>
>        ActionErrors errors = new ActionErrors();
>        ActionMessages messages = new ActionMessages();
>
>        ChangePasswordForm changePwdForm = (ChangePasswordForm) form;
>        String userName = changePwdForm.getUserName();
>        String oldPassword = changePwdForm.getOldPwd().**trim();
>        String newPassword = changePwdForm.getPassword().**trim();
>        UserDelegate userDelegate = new UserDelegate(userName, null);
>        boolean isPasswordChanged = userDelegate.changePassword(**userName,
> oldPassword, newPassword);
>
>        if (isPasswordChanged) {
>            messages.add("password", new ActionMessage("msg.**
> changePasswordSuccess"));
>            this.saveMessages(request, messages);
>            log.info("Password changed successfully.");
>            return mapping.findForward(SUCCESS);
>        } else {
>            errors.add("errors", new ActionMessage("msg.**
> changePasswordError"));
>            saveErrors(request, errors);
>            log.error("Password can't be changed");
>            return mapping.findForward(FAILURE);
>        }
>   }
> }
>
> 3. Validation class
> public class ChangePasswordForm extends ValidatorForm {
>
>    private String userName;
>    private String oldPwd;
>    private String password;
>    private String confirmPwd;
>
>    /**
>     *
>     * @return
>     */
>    public String getPassword() {
>        return password;
>    }
>
>    /**
>     *
>     * @param password
>     */
>    public void setPassword(String password) {
>        this.password = password;
>    }
>
>    /**
>     *
>     * @return
>     */
>    public String getOldPwd() {
>        return oldPwd;
>    }
>
>    /**
>     *
>     * @param oldPwd
>     */
>    public void setOldPwd(String oldPwd) {
>        this.oldPwd = oldPwd;
>    }
>
>    /**
>     *
>     * @return
>     */
>    public String getConfirmPwd() {
>        return confirmPwd;
>    }
>
>    /**
>     *
>     * @param confirmPwd
>     */
>    public void setConfirmPwd(String confirmPwd) {
>        this.confirmPwd = confirmPwd;
>    }
>
>    /**
>     *
>     * @return
>     */
>    public String getUserName() {
>        return userName;
>    }
>
>    /**
>     *
>     * @param userName
>     */
>    public void setUserName(String userName) {
>        this.userName = userName;
>    }
>
>    /**
>     *
>     */
>    public ChangePasswordForm() {
>        super();
>
>    }
>
>    /**
>     * This is the action called from the Struts framework.
>     * @param mapping The ActionMapping used to select this instance.
>     * @param request The HTTP Request we are processing.
>     * @return set of errors.
>     */
>    @Override
>    public ActionErrors validate(ActionMapping mapping, HttpServletRequest
> request) {
>        ActionErrors errors = new ActionErrors();
>        if(userName.isEmpty()){
>            errors.add("error", new ActionMessage("error.userName"**));
>        }
>        if(oldPwd.isEmpty()){
>            errors.add("error", new ActionMessage("error.**oldPassword"));
>        }
>        if(password.isEmpty()){
>            errors.add("error", new ActionMessage("error.**newPassword"));
>        }
>        if(!confirmPwd.equals(**password)){
>            errors.add("error", new ActionMessage("error.**
> confirmPassword"));
>        }
>        if(userName.equalsIgnoreCase(**password)){
>            errors.add("error", new ActionMessage("error.**
> sameAsUsername"));
>        }
>        if(oldPwd.equalsIgnoreCase(**password)){
>            errors.add("error", new ActionMessage("error.**samePassword"));
>        }
>        return errors;
>    }
>
>    /**
>     *
>     * @param mapping
>     * @param request
>     */
>    @Override
>    public void reset(ActionMapping mapping, HttpServletRequest request) {
>        userName = "";
>        oldPwd = "";
>        password = "";
>        confirmPwd = "";
>    }
> }
>
> On 6/13/2012 11:10 AM, Jason Zheng wrote:
>
>> Anjib, would you like to show us the codes in the Action
>> ChangePasswordAction?
>>
>> On Wed, Jun 13, 2012 at 10:58 PM, Dave Newton<da...@gmail.com>
>>  wrote:
>>
>>  Then it's likely you're doing something wrong if you're forwarding to a
>>> page before creating the info that page needs.
>>>
>>> Dave
>>>
>>> On Wed, Jun 13, 2012 at 10:53 AM, Anjib Mulepati<anjibcs@hotmail.com
>>>
>>>> wrote:
>>>> Even though I put validation in ActionForm validate() method failure
>>>> will
>>>> take to changePasswordPage. I do have validation to check form field.
>>>>
>>>>
>>>> On 6/13/2012 9:17 AM, Dave Newton wrote:
>>>>
>>>>  Maybe some sort of validation would be helpful.
>>>>>
>>>>> Dave
>>>>>
>>>>> On Wed, Jun 13, 2012 at 9:03 AM, Anjib Mulepati<an...@hotmail.com>
>>>>>  wrote:
>>>>>
>>>>>  Hi All,
>>>>>
>>>>>> I have question regarding handling form submission by direct URL in
>>>>>> Struts
>>>>>> 1.3.8
>>>>>>
>>>>>> I have a page to change password which user can access after they
>>>>>>
>>>>> login.
>>>
>>>> URL for that page is http://localhost:8080/MyApp/****
>>>>>> **changepassword.do<http://localhost:8080/MyApp/****changepassword.do>
>>>>>>
>>>>> <http://localhost:8080/MyApp/****changepassword.do<http://localhost:8080/MyApp/**changepassword.do>
>>> >
>>>
>>>> <http://**localhost:8080/**MyApp/**changepassword.do<
>>>>>>
>>>>> http://localhost:8080/MyApp/**changepassword.do<http://localhost:8080/MyApp/changepassword.do>
>>> >
>>>
>>>>
>>>>>> I have action mapping as follow:
>>>>>> <action path="/changepassword" input="changePasswordPage"
>>>>>>
>>>>> scope="request"
>>>
>>>>  name="ChangePasswordForm" type="com.anjib.actions.**
>>>>>>
>>>>>> ChangePasswordAction">
>>>>>> <forward name="success" path="changePasswordPage" />
>>>>>> <forward name="failure" path="changePasswordPage"/>
>>>>>> </action>
>>>>>>
>>>>>> I have tile definition for changePasswordPage which have page like
>>>>>>
>>>>> header
>>>
>>>> which display welcome information after user login
>>>>>> <div id="welcome" class="right">
>>>>>> <bean:message key="label.welcome" />
>>>>>> <logic:notEmpty name="userInfo" property="firstName">
>>>>>>         ${userInfo.firstName}&nbsp;${******userInfo.lastName}
>>>>>>
>>>>>> </logic:notEmpty>
>>>>>> <logic:empty name="userInfo" property="firstName">
>>>>>>            ${userInfo.userName}
>>>>>> </logic:empty>
>>>>>> </div>
>>>>>>
>>>>>> Now everything works fine if we follow normal process: Login and do
>>>>>> actions. But if someone type URL http://localhost:8080/MyApp/**
>>>>>> changepassword.do<http://****localhost:8080/MyApp/****
>>>>>> changepassword.do<
>>>>>>
>>>>> http://localhost:8080/MyApp/**changepassword.do<http://localhost:8080/MyApp/changepassword.do>
>>> >>directly
>>>
>>>> then I don't get page and I have error in Tomcat log
>>>>>> Caused by: javax.servlet.jsp.******JspException: Cannot find bean:
>>>>>> "userInfo"
>>>>>>
>>>>>> in any scope
>>>>>>
>>>>>> Any help will be appreciated.
>>>>>>
>>>>>> Thanks,
>>>>>> Anjib
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> ------------------------------******--------------------------**--**
>>>>>> --**---------
>>>>>> To unsubscribe, e-mail: user-unsubscribe@struts.****apac**he.org<
>>>>>>
>>>>> http://apache.org>
>>>
>>>> <user-unsubscribe@**struts.**apache.org <http://struts.apache.org><
>>>>>>
>>>>> user-unsubscribe@struts.**apache.org<us...@struts.apache.org>
>>> >
>>>
>>>> For additional commands, e-mail: user-help@struts.apache.org
>>>>>>
>>>>>>
>>>>>>
>>>>>>  ------------------------------****----------------------------**
>>>> --**---------
>>>> To unsubscribe, e-mail: user-unsubscribe@struts.**apac**he.org<http://apache.org>
>>>> <
>>>>
>>> user-unsubscribe@struts.**apache.org<us...@struts.apache.org>
>>> >
>>>
>>>> For additional commands, e-mail: user-help@struts.apache.org
>>>>
>>>>
>>>>
>>
>>
>
> ------------------------------**------------------------------**---------
> To unsubscribe, e-mail: user-unsubscribe@struts.**apache.org<us...@struts.apache.org>
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: Form handling by direct URL in Struts 1.3.8

Posted by Anjib Mulepati <an...@hotmail.com>.
1. Base Class
public abstract class BaseAction extends org.apache.struts.action.Action {

     private static Log log = LogFactory.getLog("BaseAction");

     /**
      *
      * @param mapping
      * @param form
      * @param request
      * @param response
      * @return
      * @throws IOException
      * @throws ServletException
      * @throws BusinessDelegateException
      */
     @Override
     public ActionForward execute(ActionMapping mapping, ActionForm form,
             HttpServletRequest request, HttpServletResponse response)
             throws IOException, ServletException, 
BusinessDelegateException {

         if (!this.userIsLoggedIn(request)) {
             ActionErrors errors = new ActionErrors();
             errors.add("error", new 
ActionMessage("error.userNotLoggedIn"));
             this.saveErrors(request, errors);
             String url = request.getServletPath() + "?" + 
request.getQueryString();
             request.getSession().setAttribute("forwardPath", url);
             return mapping.findForward("sessionEnded");
         }
         return executeAction(mapping, form, request, response);
     }

     /**
      *
      * @param mapping
      * @param form
      * @param request
      * @param response
      * @return
      * @throws IOException
      * @throws ServletException
      */
     protected abstract ActionForward executeAction(ActionMapping mapping,
             ActionForm form, HttpServletRequest request,
             HttpServletResponse response)
             throws IOException, ServletException;

     private boolean userIsLoggedIn(HttpServletRequest request) {
         UserInfo userInfo = (UserInfo) 
request.getSession().getAttribute("userInfo");
         String userName = null;
         try{
             userName = userInfo.getUserName();
         } catch (NullPointerException ex) {
             log.error("User hasn't logged in yet.");
             return false;
         }

         if ( userName == null) {
             return false;
         }
         return true;
     }
}

2. Action class
public class ChangePasswordAction extends BaseAction {

     private static Log log = LogFactory.getLog("ChangePasswordAction");

     private static final String SUCCESS = "success";

     private static final String FAILURE = "failure";

     @Override
     public ActionForward executeAction(ActionMapping mapping, 
ActionForm form,
             HttpServletRequest request, HttpServletResponse response)
             throws IOException, ServletException {

         ActionErrors errors = new ActionErrors();
         ActionMessages messages = new ActionMessages();

         ChangePasswordForm changePwdForm = (ChangePasswordForm) form;
         String userName = changePwdForm.getUserName();
         String oldPassword = changePwdForm.getOldPwd().trim();
         String newPassword = changePwdForm.getPassword().trim();
         UserDelegate userDelegate = new UserDelegate(userName, null);
         boolean isPasswordChanged = 
userDelegate.changePassword(userName, oldPassword, newPassword);

         if (isPasswordChanged) {
             messages.add("password", new 
ActionMessage("msg.changePasswordSuccess"));
             this.saveMessages(request, messages);
             log.info("Password changed successfully.");
             return mapping.findForward(SUCCESS);
         } else {
             errors.add("errors", new 
ActionMessage("msg.changePasswordError"));
             saveErrors(request, errors);
             log.error("Password can't be changed");
             return mapping.findForward(FAILURE);
         }
    }
}

3. Validation class
public class ChangePasswordForm extends ValidatorForm {

     private String userName;
     private String oldPwd;
     private String password;
     private String confirmPwd;

     /**
      *
      * @return
      */
     public String getPassword() {
         return password;
     }

     /**
      *
      * @param password
      */
     public void setPassword(String password) {
         this.password = password;
     }

     /**
      *
      * @return
      */
     public String getOldPwd() {
         return oldPwd;
     }

     /**
      *
      * @param oldPwd
      */
     public void setOldPwd(String oldPwd) {
         this.oldPwd = oldPwd;
     }

     /**
      *
      * @return
      */
     public String getConfirmPwd() {
         return confirmPwd;
     }

     /**
      *
      * @param confirmPwd
      */
     public void setConfirmPwd(String confirmPwd) {
         this.confirmPwd = confirmPwd;
     }

     /**
      *
      * @return
      */
     public String getUserName() {
         return userName;
     }

     /**
      *
      * @param userName
      */
     public void setUserName(String userName) {
         this.userName = userName;
     }

     /**
      *
      */
     public ChangePasswordForm() {
         super();

     }

     /**
      * This is the action called from the Struts framework.
      * @param mapping The ActionMapping used to select this instance.
      * @param request The HTTP Request we are processing.
      * @return set of errors.
      */
     @Override
     public ActionErrors validate(ActionMapping mapping, 
HttpServletRequest request) {
         ActionErrors errors = new ActionErrors();
         if(userName.isEmpty()){
             errors.add("error", new ActionMessage("error.userName"));
         }
         if(oldPwd.isEmpty()){
             errors.add("error", new ActionMessage("error.oldPassword"));
         }
         if(password.isEmpty()){
             errors.add("error", new ActionMessage("error.newPassword"));
         }
         if(!confirmPwd.equals(password)){
             errors.add("error", new 
ActionMessage("error.confirmPassword"));
         }
         if(userName.equalsIgnoreCase(password)){
             errors.add("error", new ActionMessage("error.sameAsUsername"));
         }
         if(oldPwd.equalsIgnoreCase(password)){
             errors.add("error", new ActionMessage("error.samePassword"));
         }
         return errors;
     }

     /**
      *
      * @param mapping
      * @param request
      */
     @Override
     public void reset(ActionMapping mapping, HttpServletRequest request) {
         userName = "";
         oldPwd = "";
         password = "";
         confirmPwd = "";
     }
}

On 6/13/2012 11:10 AM, Jason Zheng wrote:
> Anjib, would you like to show us the codes in the Action
> ChangePasswordAction?
>
> On Wed, Jun 13, 2012 at 10:58 PM, Dave Newton<da...@gmail.com>  wrote:
>
>> Then it's likely you're doing something wrong if you're forwarding to a
>> page before creating the info that page needs.
>>
>> Dave
>>
>> On Wed, Jun 13, 2012 at 10:53 AM, Anjib Mulepati<anjibcs@hotmail.com
>>> wrote:
>>> Even though I put validation in ActionForm validate() method failure will
>>> take to changePasswordPage. I do have validation to check form field.
>>>
>>>
>>> On 6/13/2012 9:17 AM, Dave Newton wrote:
>>>
>>>> Maybe some sort of validation would be helpful.
>>>>
>>>> Dave
>>>>
>>>> On Wed, Jun 13, 2012 at 9:03 AM, Anjib Mulepati<an...@hotmail.com>
>>>>   wrote:
>>>>
>>>>   Hi All,
>>>>> I have question regarding handling form submission by direct URL in
>>>>> Struts
>>>>> 1.3.8
>>>>>
>>>>> I have a page to change password which user can access after they
>> login.
>>>>> URL for that page is http://localhost:8080/MyApp/****changepassword.do
>> <http://localhost:8080/MyApp/**changepassword.do>
>>>>> <http://**localhost:8080/MyApp/**changepassword.do<
>> http://localhost:8080/MyApp/changepassword.do>
>>>>>
>>>>> I have action mapping as follow:
>>>>> <action path="/changepassword" input="changePasswordPage"
>> scope="request"
>>>>>   name="ChangePasswordForm" type="com.anjib.actions.**
>>>>>
>>>>> ChangePasswordAction">
>>>>> <forward name="success" path="changePasswordPage" />
>>>>> <forward name="failure" path="changePasswordPage"/>
>>>>> </action>
>>>>>
>>>>> I have tile definition for changePasswordPage which have page like
>> header
>>>>> which display welcome information after user login
>>>>> <div id="welcome" class="right">
>>>>> <bean:message key="label.welcome" />
>>>>> <logic:notEmpty name="userInfo" property="firstName">
>>>>>          ${userInfo.firstName}&nbsp;${****userInfo.lastName}
>>>>>
>>>>> </logic:notEmpty>
>>>>> <logic:empty name="userInfo" property="firstName">
>>>>>             ${userInfo.userName}
>>>>> </logic:empty>
>>>>> </div>
>>>>>
>>>>> Now everything works fine if we follow normal process: Login and do
>>>>> actions. But if someone type URL http://localhost:8080/MyApp/**
>>>>> changepassword.do<http://**localhost:8080/MyApp/**changepassword.do<
>> http://localhost:8080/MyApp/changepassword.do>>directly
>>>>> then I don't get page and I have error in Tomcat log
>>>>> Caused by: javax.servlet.jsp.****JspException: Cannot find bean:
>>>>> "userInfo"
>>>>>
>>>>> in any scope
>>>>>
>>>>> Any help will be appreciated.
>>>>>
>>>>> Thanks,
>>>>> Anjib
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> ------------------------------****----------------------------**
>>>>> --**---------
>>>>> To unsubscribe, e-mail: user-unsubscribe@struts.**apac**he.org<
>> http://apache.org>
>>>>> <user-unsubscribe@**struts.apache.org<
>> user-unsubscribe@struts.apache.org>
>>>>> For additional commands, e-mail: user-help@struts.apache.org
>>>>>
>>>>>
>>>>>
>>> ------------------------------**------------------------------**---------
>>> To unsubscribe, e-mail: user-unsubscribe@struts.**apache.org<
>> user-unsubscribe@struts.apache.org>
>>> For additional commands, e-mail: user-help@struts.apache.org
>>>
>>>
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Form handling by direct URL in Struts 1.3.8

Posted by Jason Zheng <mr...@gmail.com>.
Anjib, would you like to show us the codes in the Action
ChangePasswordAction?

On Wed, Jun 13, 2012 at 10:58 PM, Dave Newton <da...@gmail.com> wrote:

> Then it's likely you're doing something wrong if you're forwarding to a
> page before creating the info that page needs.
>
> Dave
>
> On Wed, Jun 13, 2012 at 10:53 AM, Anjib Mulepati <anjibcs@hotmail.com
> >wrote:
>
> > Even though I put validation in ActionForm validate() method failure will
> > take to changePasswordPage. I do have validation to check form field.
> >
> >
> > On 6/13/2012 9:17 AM, Dave Newton wrote:
> >
> >> Maybe some sort of validation would be helpful.
> >>
> >> Dave
> >>
> >> On Wed, Jun 13, 2012 at 9:03 AM, Anjib Mulepati<an...@hotmail.com>
> >>  wrote:
> >>
> >>  Hi All,
> >>>
> >>> I have question regarding handling form submission by direct URL in
> >>> Struts
> >>> 1.3.8
> >>>
> >>> I have a page to change password which user can access after they
> login.
> >>> URL for that page is http://localhost:8080/MyApp/****changepassword.do
> <http://localhost:8080/MyApp/**changepassword.do>
> >>> <http://**localhost:8080/MyApp/**changepassword.do<
> http://localhost:8080/MyApp/changepassword.do>
> >>> >
> >>>
> >>>
> >>> I have action mapping as follow:
> >>> <action path="/changepassword" input="changePasswordPage"
> scope="request"
> >>>  name="ChangePasswordForm" type="com.anjib.actions.**
> >>>
> >>> ChangePasswordAction">
> >>> <forward name="success" path="changePasswordPage" />
> >>> <forward name="failure" path="changePasswordPage"/>
> >>> </action>
> >>>
> >>> I have tile definition for changePasswordPage which have page like
> header
> >>> which display welcome information after user login
> >>> <div id="welcome" class="right">
> >>> <bean:message key="label.welcome" />
> >>> <logic:notEmpty name="userInfo" property="firstName">
> >>>         ${userInfo.firstName}&nbsp;${****userInfo.lastName}
> >>>
> >>> </logic:notEmpty>
> >>> <logic:empty name="userInfo" property="firstName">
> >>>            ${userInfo.userName}
> >>> </logic:empty>
> >>> </div>
> >>>
> >>> Now everything works fine if we follow normal process: Login and do
> >>> actions. But if someone type URL http://localhost:8080/MyApp/**
> >>> changepassword.do<http://**localhost:8080/MyApp/**changepassword.do<
> http://localhost:8080/MyApp/changepassword.do>>directly
> >>> then I don't get page and I have error in Tomcat log
> >>> Caused by: javax.servlet.jsp.****JspException: Cannot find bean:
> >>> "userInfo"
> >>>
> >>> in any scope
> >>>
> >>> Any help will be appreciated.
> >>>
> >>> Thanks,
> >>> Anjib
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>> ------------------------------****----------------------------**
> >>> --**---------
> >>> To unsubscribe, e-mail: user-unsubscribe@struts.**apac**he.org<
> http://apache.org>
> >>> <user-unsubscribe@**struts.apache.org<
> user-unsubscribe@struts.apache.org>
> >>> >
> >>>
> >>> For additional commands, e-mail: user-help@struts.apache.org
> >>>
> >>>
> >>>
> >
> > ------------------------------**------------------------------**---------
> > To unsubscribe, e-mail: user-unsubscribe@struts.**apache.org<
> user-unsubscribe@struts.apache.org>
> > For additional commands, e-mail: user-help@struts.apache.org
> >
> >
>



-- 
Thanks
Jason

Re: Form handling by direct URL in Struts 1.3.8

Posted by Dave Newton <da...@gmail.com>.
Then it's likely you're doing something wrong if you're forwarding to a
page before creating the info that page needs.

Dave

On Wed, Jun 13, 2012 at 10:53 AM, Anjib Mulepati <an...@hotmail.com>wrote:

> Even though I put validation in ActionForm validate() method failure will
> take to changePasswordPage. I do have validation to check form field.
>
>
> On 6/13/2012 9:17 AM, Dave Newton wrote:
>
>> Maybe some sort of validation would be helpful.
>>
>> Dave
>>
>> On Wed, Jun 13, 2012 at 9:03 AM, Anjib Mulepati<an...@hotmail.com>
>>  wrote:
>>
>>  Hi All,
>>>
>>> I have question regarding handling form submission by direct URL in
>>> Struts
>>> 1.3.8
>>>
>>> I have a page to change password which user can access after they login.
>>> URL for that page is http://localhost:8080/MyApp/****changepassword.do<http://localhost:8080/MyApp/**changepassword.do>
>>> <http://**localhost:8080/MyApp/**changepassword.do<http://localhost:8080/MyApp/changepassword.do>
>>> >
>>>
>>>
>>> I have action mapping as follow:
>>> <action path="/changepassword" input="changePasswordPage" scope="request"
>>>  name="ChangePasswordForm" type="com.anjib.actions.**
>>>
>>> ChangePasswordAction">
>>> <forward name="success" path="changePasswordPage" />
>>> <forward name="failure" path="changePasswordPage"/>
>>> </action>
>>>
>>> I have tile definition for changePasswordPage which have page like header
>>> which display welcome information after user login
>>> <div id="welcome" class="right">
>>> <bean:message key="label.welcome" />
>>> <logic:notEmpty name="userInfo" property="firstName">
>>>         ${userInfo.firstName}&nbsp;${****userInfo.lastName}
>>>
>>> </logic:notEmpty>
>>> <logic:empty name="userInfo" property="firstName">
>>>            ${userInfo.userName}
>>> </logic:empty>
>>> </div>
>>>
>>> Now everything works fine if we follow normal process: Login and do
>>> actions. But if someone type URL http://localhost:8080/MyApp/**
>>> changepassword.do<http://**localhost:8080/MyApp/**changepassword.do<http://localhost:8080/MyApp/changepassword.do>>directly
>>> then I don't get page and I have error in Tomcat log
>>> Caused by: javax.servlet.jsp.****JspException: Cannot find bean:
>>> "userInfo"
>>>
>>> in any scope
>>>
>>> Any help will be appreciated.
>>>
>>> Thanks,
>>> Anjib
>>>
>>>
>>>
>>>
>>>
>>>
>>> ------------------------------****----------------------------**
>>> --**---------
>>> To unsubscribe, e-mail: user-unsubscribe@struts.**apac**he.org<http://apache.org>
>>> <us...@struts.apache.org>
>>> >
>>>
>>> For additional commands, e-mail: user-help@struts.apache.org
>>>
>>>
>>>
>
> ------------------------------**------------------------------**---------
> To unsubscribe, e-mail: user-unsubscribe@struts.**apache.org<us...@struts.apache.org>
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: Form handling by direct URL in Struts 1.3.8

Posted by Anjib Mulepati <an...@hotmail.com>.
Even though I put validation in ActionForm validate() method failure 
will take to changePasswordPage. I do have validation to check form field.

On 6/13/2012 9:17 AM, Dave Newton wrote:
> Maybe some sort of validation would be helpful.
>
> Dave
>
> On Wed, Jun 13, 2012 at 9:03 AM, Anjib Mulepati<an...@hotmail.com>  wrote:
>
>> Hi All,
>>
>> I have question regarding handling form submission by direct URL in Struts
>> 1.3.8
>>
>> I have a page to change password which user can access after they login.
>> URL for that page is http://localhost:8080/MyApp/**changepassword.do<http://localhost:8080/MyApp/changepassword.do>
>>
>> I have action mapping as follow:
>> <action path="/changepassword" input="changePasswordPage" scope="request"
>>   name="ChangePasswordForm" type="com.anjib.actions.**
>> ChangePasswordAction">
>> <forward name="success" path="changePasswordPage" />
>> <forward name="failure" path="changePasswordPage"/>
>> </action>
>>
>> I have tile definition for changePasswordPage which have page like header
>> which display welcome information after user login
>> <div id="welcome" class="right">
>> <bean:message key="label.welcome" />
>> <logic:notEmpty name="userInfo" property="firstName">
>>          ${userInfo.firstName}&nbsp;${**userInfo.lastName}
>> </logic:notEmpty>
>> <logic:empty name="userInfo" property="firstName">
>>             ${userInfo.userName}
>> </logic:empty>
>> </div>
>>
>> Now everything works fine if we follow normal process: Login and do
>> actions. But if someone type URL http://localhost:8080/MyApp/**
>> changepassword.do<http://localhost:8080/MyApp/changepassword.do>directly then I don't get page and I have error in Tomcat log
>> Caused by: javax.servlet.jsp.**JspException: Cannot find bean: "userInfo"
>> in any scope
>>
>> Any help will be appreciated.
>>
>> Thanks,
>> Anjib
>>
>>
>>
>>
>>
>>
>> ------------------------------**------------------------------**---------
>> To unsubscribe, e-mail: user-unsubscribe@struts.**apache.org<us...@struts.apache.org>
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Form handling by direct URL in Struts 1.3.8

Posted by Dave Newton <da...@gmail.com>.
Maybe some sort of validation would be helpful.

Dave

On Wed, Jun 13, 2012 at 9:03 AM, Anjib Mulepati <an...@hotmail.com> wrote:

> Hi All,
>
> I have question regarding handling form submission by direct URL in Struts
> 1.3.8
>
> I have a page to change password which user can access after they login.
> URL for that page is http://localhost:8080/MyApp/**changepassword.do<http://localhost:8080/MyApp/changepassword.do>
>
> I have action mapping as follow:
> <action path="/changepassword" input="changePasswordPage" scope="request"
>  name="ChangePasswordForm" type="com.anjib.actions.**
> ChangePasswordAction">
> <forward name="success" path="changePasswordPage" />
> <forward name="failure" path="changePasswordPage"/>
> </action>
>
> I have tile definition for changePasswordPage which have page like header
> which display welcome information after user login
> <div id="welcome" class="right">
> <bean:message key="label.welcome" />
> <logic:notEmpty name="userInfo" property="firstName">
>         ${userInfo.firstName}&nbsp;${**userInfo.lastName}
> </logic:notEmpty>
> <logic:empty name="userInfo" property="firstName">
>            ${userInfo.userName}
> </logic:empty>
> </div>
>
> Now everything works fine if we follow normal process: Login and do
> actions. But if someone type URL http://localhost:8080/MyApp/**
> changepassword.do <http://localhost:8080/MyApp/changepassword.do>directly then I don't get page and I have error in Tomcat log
> Caused by: javax.servlet.jsp.**JspException: Cannot find bean: "userInfo"
> in any scope
>
> Any help will be appreciated.
>
> Thanks,
> Anjib
>
>
>
>
>
>
> ------------------------------**------------------------------**---------
> To unsubscribe, e-mail: user-unsubscribe@struts.**apache.org<us...@struts.apache.org>
> For additional commands, e-mail: user-help@struts.apache.org
>
>