You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by yang shoujun <ya...@139.com> on 2012/11/13 13:52:51 UTC

回复:[struts2] 's method attribute doesn't work

Your form action shoud be employAction!doSearch.do

Wu Ming <rd...@gmail.com>编写:

>Hi,
>
>I'm using struts-2.3.4 and running apache tomcat 7.
>
>I have a form in search.jsp. There are two submit buttons: "Search"
>and "Add New" button. I had set each button with their own method
>attribute:
>
><s:form name="searchForm" action="employeeAction" method="post">
>    <s:textfield name="id" label="Employee ID"/>
>    <s:textfield name="name" label="Employee Name"/>
>
>    <s:submit value="Search" method="doSearch"/>
>    <s:submit value="Add New" method="doAddNew"/>
></s:form>
>
>
>In struts.xml:
>
><?xml version="1.0" encoding="UTF-8" ?>
><!DOCTYPE struts PUBLIC
>    "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
>    "http://struts.apache.org/dtds/struts-2.3.dtd">
>
><struts>
>
>    <constant name="struts.enable.DynamicMethodInvocation" value="false" />
>    <constant name="struts.devMode" value="true" />
>
>    <package name="default" namespace="/" extends="struts-default">
>
>        <global-results>
>            <result name="error">/error.jsp</result>
>        </global-results>
>
>        <global-exception-mappings>
>            <exception-mapping exception="java.lang.Exception" result="error"/>
>        </global-exception-mappings>
>
>    </package>
>
>    <package name="example" namespace="/example" extends="default">
>
>        <action name="employeeAction" class="example.EmployeeAction">
>           <result name="search">/example/search.jsp</result>
>           <result name="add">/example/add.jsp</result>
>        </action>
>
>    </package>
></struts>
>
>
>In EmployeeAction class:
>
>public class EmployeeAction extends ActionSupport {
>
>    private static final Logger logger =
>Logger.getLogger(EmployeeAction.class);    //log4j
>
>    @Override
>    public String execute() throws Exception {
>
>        logger.info("Calling execute!");
>
>        return SUCCESS;
>    }
>
>    public String doSearch() throws Exception {
>
>        logger.info("Calling doSearch!");
>
>        return "search";
>    }
>
>    public String doAddNew() throws Exception {
>
>        logger.info("Calling doAddNew!");
>
>        return "add";
>    }
>}
>
>The problem is when I clicked "Search" or "Add New" button in jsp, the
>method doSearch() or doAddNew() was never called, instead execute()
>method was called.
>
>What is wrong with my code above? Anyone know?
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>

Re: 回复:[struts2] 's method attribute doesn't work

Posted by Wu Ming <rd...@gmail.com>.
On Mon, Nov 19, 2012 at 5:49 PM, Wu Ming <rd...@gmail.com> wrote:

>
> Clearly, the solution (using boolean property) in the example doesn't work
> (I tried in v2.4). I think somebody has to update the tutorial page.
>
>
Sorry, I got typo. I mean struts v2.3.4, not v.2.4.

Re: 回复:[struts2] 's method attribute doesn't work

Posted by Lukasz Lenart <lu...@apache.org>.
2012/11/19 Wu Ming <rd...@gmail.com>:
> Hi,
>
> Why there are so many struts2 wiki pages? The contents are muchly same and
> only one that has a comment page.
>
> http://struts.apache.org/2.2.3/docs/multiple-submit-buttons.html      (this
> one, the old version, came from google result. There are also other
> versions)
> http://struts.apache.org/2.3.4.1/docs/multiple-submit-buttons.html   (the
> latest version)
> https://cwiki.apache.org/confluence/display/WW/Multiple+Submit+Buttons
>  (this one has the comments)

They differ, in some areas. Basically when we release a new version we
also releasing docs - as there is no something like a version in
Confluence.

There are three places where you can find docs:
1. http://cwiki.apache.org/confluence/display/WW/ - the original
source of all docs based on Confluence with comments and so on
2. https://cwiki.apache.org/WW/ - automatically exported docs which
can be used for release or to update snapshot version
3. http://struts.apache.org/2.x/docs/ - snapshot version of docs,
updated periodically from 2. If you're up-to-date with Struts 2
version it's the best place to go ;-)

And of course there are version of docs for each released Struts 2
version, as you mentioned above. Yes, I know it's misleading but it's
the best approach in which we can satisfy all the opposite needs -
keep docs for each version, have snapshot docs, have one source of
docs

Maybe we can add something like a note to each page to help users find
the source eg.
{note}If you looking for the original source of this document please
go to http://cwiki.apache.org/confluence/display/WW/$page.id{note}

WDYT?

> Unfortunately, the commented version didn't show up in my google result. I
> never know until Lukasz gave the link.

Yes, this is the second disadvantage and that's why I've asked if I
can put the comment as a part of a page. It's the best approach right
now.
Maybe adding similar note could help, eg. {note}To see comments to
this page please go to
http://cwiki.apache.org/confluence/display/WW/$page.id#comment{note}

> Clearly, the solution (using boolean property) in the example doesn't work
> (I tried in v2.4). I think somebody has to update the tutorial page.

This somebody can be you ;-) Contribute to documentation is the
easiest way to contribute, you must fill ICLA and send it to
secretary, after approval ask INFRA to grant you access to the docs
and done, you can change docs on your own :-)

> This one also related to the "multiple submit buttons" issue:
> https://cwiki.apache.org/confluence/display/WW/HTML+form+buttons+HOWTO

Thanks, I'll link it to them Multiple+Submit+Buttons page


Regards
-- 
Łukasz
+ 48 606 323 122 http://www.lenart.org.pl/

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


Re: 回复:[struts2] 's method attribute doesn't work

Posted by Wu Ming <rd...@gmail.com>.
Hi,

Why there are so many struts2 wiki pages? The contents are muchly same and
only one that has a comment page.

http://struts.apache.org/2.2.3/docs/multiple-submit-buttons.html      (this
one, the old version, came from google result. There are also other
versions)
http://struts.apache.org/2.3.4.1/docs/multiple-submit-buttons.html   (the
latest version)
https://cwiki.apache.org/confluence/display/WW/Multiple+Submit+Buttons
 (this one has the comments)

Unfortunately, the commented version didn't show up in my google result. I
never know until Lukasz gave the link.

Clearly, the solution (using boolean property) in the example doesn't work
(I tried in v2.4). I think somebody has to update the tutorial page.

This one also related to the "multiple submit buttons" issue:
https://cwiki.apache.org/confluence/display/WW/HTML+form+buttons+HOWTO


Regards,
WM

On Mon, Nov 19, 2012 at 4:23 PM, Lukasz Lenart <lu...@apache.org>
wrote:
> 2012/11/13 Wu Ming <rd...@gmail.com>:
>> Hi,
>>
>> Never mind, I had found the solution: you have to set
>> "struts.enable.DynamicMethodInvocation" to true.
>
> Did you try out that solution [1] ?
>
> [1] https://cwiki.apache.org/confluence/display/WW/Multiple+Submit+Buttons
>
>
> Regards
> --
> Łukasz
> + 48 606 323 122 http://www.lenart.org.pl/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>

Re: 回复:[struts2] 's method attribute doesn't work

Posted by Lukasz Lenart <lu...@apache.org>.
2012/11/13 Wu Ming <rd...@gmail.com>:
> Hi,
>
> Never mind, I had found the solution: you have to set
> "struts.enable.DynamicMethodInvocation" to true.

Did you try out that solution [1] ?

[1] https://cwiki.apache.org/confluence/display/WW/Multiple+Submit+Buttons


Regards
-- 
Łukasz
+ 48 606 323 122 http://www.lenart.org.pl/

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


Re: 回复:[struts2] 's method attribute doesn't work

Posted by "J. Garcia" <jo...@gmail.com>.
Good!


On Sun, Nov 18, 2012 at 10:39 PM, Lukasz Lenart <lu...@apache.org>wrote:

> 2012/11/14 J. Garcia <jo...@gmail.com>:
> > Beware of this vulnerability:
> >
> >
> http://www.brucephillips.name/blog/index.cfm/2011/2/19/Struts-2-Security-Vulnerability--Dynamic-Method-Invocation
>
> I've added additional note about that to the docs
>
> https://cwiki.apache.org/confluence/display/WW/submit
>
>
> Regards
> --
> Łukasz
> + 48 606 323 122 http://www.lenart.org.pl/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: 回复:[struts2] 's method attribute doesn't work

Posted by Lukasz Lenart <lu...@apache.org>.
2012/11/14 J. Garcia <jo...@gmail.com>:
> Beware of this vulnerability:
>
> http://www.brucephillips.name/blog/index.cfm/2011/2/19/Struts-2-Security-Vulnerability--Dynamic-Method-Invocation

I've added additional note about that to the docs

https://cwiki.apache.org/confluence/display/WW/submit


Regards
-- 
Łukasz
+ 48 606 323 122 http://www.lenart.org.pl/

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


Re: 回复:[struts2] 's method attribute doesn't work

Posted by "J. Garcia" <jo...@gmail.com>.
Beware of this vulnerability:

http://www.brucephillips.name/blog/index.cfm/2011/2/19/Struts-2-Security-Vulnerability--Dynamic-Method-Invocation

Cheers,
J.


On Tue, Nov 13, 2012 at 4:41 PM, Wu Ming <rd...@gmail.com> wrote:

> Hi,
>
> Never mind, I had found the solution: you have to set
> "struts.enable.DynamicMethodInvocation" to true.
>
>
> On Tue, Nov 13, 2012 at 7:52 PM, yang shoujun <ya...@139.com> wrote:
> > Your form action shoud be employAction!doSearch.do
> >
> > Wu Ming <rd...@gmail.com>编写:
> >
> >>Hi,
> >>
> >>I'm using struts-2.3.4 and running apache tomcat 7.
> >>
> >>I have a form in search.jsp. There are two submit buttons: "Search"
> >>and "Add New" button. I had set each button with their own method
> >>attribute:
> >>
> >><s:form name="searchForm" action="employeeAction" method="post">
> >>    <s:textfield name="id" label="Employee ID"/>
> >>    <s:textfield name="name" label="Employee Name"/>
> >>
> >>    <s:submit value="Search" method="doSearch"/>
> >>    <s:submit value="Add New" method="doAddNew"/>
> >></s:form>
> >>
> >>
> >>In struts.xml:
> >>
> >><?xml version="1.0" encoding="UTF-8" ?>
> >><!DOCTYPE struts PUBLIC
> >>    "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
> >>    "http://struts.apache.org/dtds/struts-2.3.dtd">
> >>
> >><struts>
> >>
> >>    <constant name="struts.enable.DynamicMethodInvocation" value="false"
> />
> >>    <constant name="struts.devMode" value="true" />
> >>
> >>    <package name="default" namespace="/" extends="struts-default">
> >>
> >>        <global-results>
> >>            <result name="error">/error.jsp</result>
> >>        </global-results>
> >>
> >>        <global-exception-mappings>
> >>            <exception-mapping exception="java.lang.Exception"
> result="error"/>
> >>        </global-exception-mappings>
> >>
> >>    </package>
> >>
> >>    <package name="example" namespace="/example" extends="default">
> >>
> >>        <action name="employeeAction" class="example.EmployeeAction">
> >>           <result name="search">/example/search.jsp</result>
> >>           <result name="add">/example/add.jsp</result>
> >>        </action>
> >>
> >>    </package>
> >></struts>
> >>
> >>
> >>In EmployeeAction class:
> >>
> >>public class EmployeeAction extends ActionSupport {
> >>
> >>    private static final Logger logger =
> >>Logger.getLogger(EmployeeAction.class);    //log4j
> >>
> >>    @Override
> >>    public String execute() throws Exception {
> >>
> >>        logger.info("Calling execute!");
> >>
> >>        return SUCCESS;
> >>    }
> >>
> >>    public String doSearch() throws Exception {
> >>
> >>        logger.info("Calling doSearch!");
> >>
> >>        return "search";
> >>    }
> >>
> >>    public String doAddNew() throws Exception {
> >>
> >>        logger.info("Calling doAddNew!");
> >>
> >>        return "add";
> >>    }
> >>}
> >>
> >>The problem is when I clicked "Search" or "Add New" button in jsp, the
> >>method doSearch() or doAddNew() was never called, instead execute()
> >>method was called.
> >>
> >>What is wrong with my code above? Anyone know?
> >>
> >>---------------------------------------------------------------------
> >>To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> >>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: 回复:[struts2] 's method attribute doesn't work

Posted by Wu Ming <rd...@gmail.com>.
Hi,

Never mind, I had found the solution: you have to set
"struts.enable.DynamicMethodInvocation" to true.


On Tue, Nov 13, 2012 at 7:52 PM, yang shoujun <ya...@139.com> wrote:
> Your form action shoud be employAction!doSearch.do
>
> Wu Ming <rd...@gmail.com>编写:
>
>>Hi,
>>
>>I'm using struts-2.3.4 and running apache tomcat 7.
>>
>>I have a form in search.jsp. There are two submit buttons: "Search"
>>and "Add New" button. I had set each button with their own method
>>attribute:
>>
>><s:form name="searchForm" action="employeeAction" method="post">
>>    <s:textfield name="id" label="Employee ID"/>
>>    <s:textfield name="name" label="Employee Name"/>
>>
>>    <s:submit value="Search" method="doSearch"/>
>>    <s:submit value="Add New" method="doAddNew"/>
>></s:form>
>>
>>
>>In struts.xml:
>>
>><?xml version="1.0" encoding="UTF-8" ?>
>><!DOCTYPE struts PUBLIC
>>    "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
>>    "http://struts.apache.org/dtds/struts-2.3.dtd">
>>
>><struts>
>>
>>    <constant name="struts.enable.DynamicMethodInvocation" value="false" />
>>    <constant name="struts.devMode" value="true" />
>>
>>    <package name="default" namespace="/" extends="struts-default">
>>
>>        <global-results>
>>            <result name="error">/error.jsp</result>
>>        </global-results>
>>
>>        <global-exception-mappings>
>>            <exception-mapping exception="java.lang.Exception" result="error"/>
>>        </global-exception-mappings>
>>
>>    </package>
>>
>>    <package name="example" namespace="/example" extends="default">
>>
>>        <action name="employeeAction" class="example.EmployeeAction">
>>           <result name="search">/example/search.jsp</result>
>>           <result name="add">/example/add.jsp</result>
>>        </action>
>>
>>    </package>
>></struts>
>>
>>
>>In EmployeeAction class:
>>
>>public class EmployeeAction extends ActionSupport {
>>
>>    private static final Logger logger =
>>Logger.getLogger(EmployeeAction.class);    //log4j
>>
>>    @Override
>>    public String execute() throws Exception {
>>
>>        logger.info("Calling execute!");
>>
>>        return SUCCESS;
>>    }
>>
>>    public String doSearch() throws Exception {
>>
>>        logger.info("Calling doSearch!");
>>
>>        return "search";
>>    }
>>
>>    public String doAddNew() throws Exception {
>>
>>        logger.info("Calling doAddNew!");
>>
>>        return "add";
>>    }
>>}
>>
>>The problem is when I clicked "Search" or "Add New" button in jsp, the
>>method doSearch() or doAddNew() was never called, instead execute()
>>method was called.
>>
>>What is wrong with my code above? Anyone know?
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>

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