0

I'm currently having a problem with my setup. I have this action tag in my JSP

<s:action name="doLogin" executeResult="true"></s:action>

and below is the corresponding struts.xml entry

<action name="doLogin" class="siteLoginAction">
    <result name="input">login</result>
    <result name="success">home</result>
</action>

The jsp is just a login div (form, textfield, label).

Now the problem is that when I'm testing the validate function

@Override
public void validate() {
    String username = siteUser.getSiteUserUsername();
    String password = siteUser.getSiteUserPassword();

    if (StringUtils.isEmpty(username) || StringUtils.isEmpty(password)) {
        addFieldError("siteUser.siteUserUsername", "Invalid login");
    } else if (!siteUserService.checkLoginExists(username, password, getBlogSiteUrl())) {
        addFieldError("siteUser.siteUserPassword", "Invalid login");
    }
}

As you can see it works,

enter image description here

but it will not go away. The error message will stay there everytime I visit that page.

Is this because of the singleton default model of the Struts2 action? I have tried @Scope("prototype") but if I use it it doesn't display the error at all

Andrea Ligios
  • 49,480
  • 26
  • 114
  • 243
Jiro Manio
  • 137
  • 10

1 Answers1

0

I have this <s:action> tag in my JSP

You should not use that tag, it's an old and useless technology, drop it ASAYC.

Is this because of the singleton default model of the Struts2 action? I have tried @Scope("prototype") but if I use it it doesn't display the error at all

Actions are ThreadLocal. What you're referring to with "default model" is the default scope (Singleton) of a Spring bean, and hence of a Struts2 Action if managed by Spring. And it would be wrong, you should use scope="prototype" in that case, to make the Spring managed actions working correctly as ThreadLocal objects.

This question is not answerable more than this right now; just drop the <s:action/> tag, use scope="prototype" (or drop Spring, at least on actions handling) and see what happens, then if it still doesn't work, come back here and ask again: it will be easy to help you then.

Community
  • 1
  • 1
Andrea Ligios
  • 49,480
  • 26
  • 114
  • 243
  • I'll see what I can do about the action tag. The problem is that the JSP calling the action is unknown (can be any filename) so I had no choice but to return the result via action tag. – Jiro Manio May 19 '16 at 08:16
  • That's not right: why *any unknown* JSP should be able to embed a login window inside of it ? If a login is needed, just redirect the whole page to a login page (eventually storing the URL of the page you're coming from), then after a succesful login come back to it. Easier and more clean, imho – Andrea Ligios May 19 '16 at 08:18
  • otherwise use an iframe – Andrea Ligios May 19 '16 at 08:21
  • Or don't use the login fragment as a page, but as a reusable component that can be dropped into any page. – Dave Newton May 19 '16 at 13:02