Struts2为action中的属性提供了依赖注入的功能。在struts的配置文件中,我们可以很方便地为action中的属性注入值。
注意:属性必须提供setter方法
package struts2.example.action;
public class HelloWorldAction {
private String savePath;
public String getSavePath() {
return savePath;
}
public void setSavePath(String savePath) {
this.savePath = savePath;
}
public String execute() throws Exception{
return "success";
}
}
<package name="csdn" namespace="/" extends="struts-default">
<action name="list" class="struts2.example.action.HelloWorldAction" method="execute">
<param name="savePath">/images</param>
<result name="success">/WEB-INF/page/index.jsp</result>
</action>
</package>
常量可以在struts.xml或struts.properties中配置,建议在
struts.xml中配置,两种配置方式如下:
<struts>
<constant name="struts.action.extension" value="do"/>
</struts>
在struts.properties中配置常量:
struts.action.extension=do
如果配置的常量有多个,可用逗号”,”分开
常量可在下面多个配置文件中进行定义:
struts.default.xml
struts.plugin.xml
struts.xml
struts.properties
如果在多个文件中配置了同一个常量,则后一个文件中配置的常量值会覆盖前面文件中
配置的常量值
struts2不会上传文件总大小大于限制的文件