Re: Weird behavior with Struts form and namespace attribute

Lukasz Lenart <[email protected]> Sun, 14 Sep 2025 16:27:02 +0200
Newsgroups gmane.comp.jakarta.struts.user
Message-ID <CAMopvkNagyO3VDDFL9ttnVKoa3uSSu+E8Pk2BMk7xRDKWaE8dQ@mail.gmail.com>
sob., 13 wrz 2025 o 14:05 Selim H <[email protected]> napisa=C5=82(a=
):
>
> Hello,
>
> I'm following the Struts tutorial, and if I strictly follow the
> tutorial "Processing forms"
> https://struts.apache.org/getting-started/processing-forms, I use
> Struts2-core 7.0.0 and Jetty maven plugin v11.0.25
>
> The error happens because of that portion of the register.jsp code:
>     <s:form action=3D"register">
>       <s:textfield name=3D"personBean.firstName" label=3D"First name" />
>       <s:textfield name=3D"personBean.lastName" label=3D"Last name" />
>       <s:textfield name=3D"personBean.email"  label =3D"Email"/>
>       <s:textfield name=3D"personBean.age"  label=3D"Age"  />
>       <s:submit/>
>     </s:form>
>
> I start from index.jsp that contains a link <a href=3D"register.jsp">Regi=
ster</a>.

This is wrong, you must always use action instead of directly invoking JSP =
page
https://struts.apache.org/security/#never-expose-jsp-files-directly


> When I click on the link get a JasperException caused by the following on=
e :
> java.lang.NullPointerException: Cannot invoke
> "java.util.List.add(Object)" because "tags" is null

but there are no "tags" in your form?

> So I checked out the struts-example official repo and saw that the
> namespace attribute was specified
>
> e.g if I instead write this
> <s:form action=3D"register" namespace=3D"">
> ........ (fields)
> </s:form>
>
> For some reason it works. I've read the struts tag reference, and if
> you don't specify the namespace it default to "current namespace".
>
> The exception seems to only happens when I directly link to a jsp :
> Let's say I have a foo.jsp containing the same form code, and in
> index.jsp I add a link to an action FooAction that just returns
> foo.jsp, then the form display properly.
>
> So my guess is that JSP doesn't go through the mapping of struts.xml
> and for some reasons using <s:form> without an attribute tag causes
> this exception, but why ? I can't find a reason why and the tutorial
> assumes the code shown is supposed to work, but it isn't.

When you call JSP directly all the Struts machinery is omitted, always
use actions

Cheers
=C5=81ukasz