美好的一天!
我正在阅读Manning的struts2书,其中一个主题是使用语法使用OGNL访问静态变量 @[fullClassName]@[property or methodCall]
所以我在我的程序上尝试了它,我的代码如下:
豆:
public class ContactsBean {
private static int count = 1;
//getter and setter
}
Run Code Online (Sandbox Code Playgroud)
行动:
private ContactsBean contacts;
//getters and setters
Run Code Online (Sandbox Code Playgroud)
JSP:
<s:property value="@com.demo.bean.ContactsBean@count" />
or
<s:property value="@vs@count" /> //valuestack method
Run Code Online (Sandbox Code Playgroud)
但它不起作用.我错过了什么吗?谢谢.
在Java servlet中,有<context-param>.在桌面应用程序中,我们通常定义自己的配置文件.
我应该在哪里为Struts2应用程序添加配置参数?例如,我的应用程序需要为用户输入设置时间限制,或者保存和读取存储在某处的文件,或者用户输入错误密码的最长时间等.我希望这些内容可配置.
人们通常在Struts2应用程序中执行此操作的方式是什么?任何最佳做法?
为什么我们要使用该setAttribute()方法设置ServletContext参数,因为我们可以通过设置参数web.xml并使用它来获取它们来完成同样的事情getInitParameter()?