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
477 views
in Technique[技术] by (71.8m points)

java - What is the default package name for Struts in struts.xml?

I created a new class called RegesterAction but I didn't keep this class in any package. How can I configure this class in the struts.xml?

Below is the struts.xml file but I'm unable to understand the attribute values "default" and struts-default.

<struts>
    <package name="default" extends="struts-default">
        <action name="*Register" method="{1}" class="RegisterAction">
            <result name="populate">/register.jsp</result>
</package>
</struts>
See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

Packages in Struts2 slightly different that the packages in the Java but usage is the same to separate the code into different modules used with their own namespace, so it's not clashes with action names. To better understand the concept of packages and namespaces you may look at Struts 2 Namespace configuration example and explanation tutorial.

If you keep classes in the source folder and it doesn't belong to the package sooner or later you will end up with the problem naming new classes and heavy code management.

The Struts2 framework has the package named struts-default that contains all necessary things to be able to use in your application configuration via extending your packages by putting this name into extends attribute of your <package> tag. You could also include other default packages from other plugins, i.e. json-default, etc.

As long as namespace is related to the package name you could compare the package names used by the Java language and package namespaces in the Struts2 framework and you may find it similar, however they are absolutely different. For example the default namespace used by the Struts2 is "" that is used when the action or result name not found in the other packages/namespaces. This is almost equivalent if you use namespace="/" which is the package root of the application.

It doesn't matter how do you name your root package with default of root but not with the name already used by the framework i.e. struts-default, if you omit the namespace attribute then the default namespace will be used. That is similar to the Java, if you omit the package declaration then default package is used.

The concept default might spread through other terms, for example there's a default action, default result, default interceptor stack, etc. The framework is also utilizes name default for default implementations of the known interfaces, and so on. There's no a singular meaning the word default. Generally if you omit something with the code then framework will use it's default settings.


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

...