Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
336 views
in Technique[技术] by (71.8m points)

struts2 - Is there a different way to configuring actions in Struts 2?

I have requirement to migrate legacy (Struts 1) code to Struts2.

If there are multiple methods in same action class, can we configure them in single <action> tag?

struts.xml

 <?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<package name="default" extends="struts-default">

<action name="product" 
        class="com.ProductAction"
        method="show">
<result name="success">welcome.jsp</result>
</action>

<action name="product" 
        class="com.ProductAction"
        method="showErr">
<result name="error">error.jsp</result>
</action>

</package>
</struts>    

Here, I have single action i.e. product and single action class i.e. ProductAction. So, can I configure both the methods (show, showErr) in single <action> tag?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The action name is overridden if used in the same package. The action name maps to a specific method or execute.

You can use wildcard mapping to put a method name in the action.

<action name="*product" class="com.ProductAction" method="{1}">

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...