Struts框架中常量文件的使用
来源:互联网 发布:w3c php手册 编辑:程序博客网 时间:2024/05/16 18:18
对于Struts应用,提倡将属性key常量定义在一个java文件Constants.java中
把一些常量文件定义在Constants.java中可以提高Action类的独立性。当属性key文件发生改变时,只要修改Constants.java文件,而不需要修改Action类。
public final class Constants{
public static final String PERSON_KEY="personbean";
public static final String LOGIN_USER_KEY = "loginUser";
public static final String USER_LIST_KEY = "users";
}
一.Action类把数据存放在request范围内,以便向视图组件传递信息。
//Action访问(更新)模型组件
PersonBean pb=new PersonBean();
pb.setUserName(userName);
pb.saveToPeristentStore();
//Action类把数据(PersonBean对象)存放在request范围内
request.setAttribute(Constants.PERSON_KEY,pb);
//hello.jsp通过一个名为Constants.PERSON_KEY的属性key来读取PersonBean对象:
<logic:present name=Constants.PERSON_KEY scope="request">
<h2>
Hello<bean:write name=Constants.PERSON_KEY property="userName"/>!<p>
</h2>
<logic:present>
二..Action类把数据存放在session范围内
Action中:
if (User.checkUser(db, username, password)
&& "admin".equals(User.getUserGrade(db, username))) {
User user = User.search(db, username, password);
session.setAttribute(Constants.LOGIN_USER_KEY, user);
Vector userVector = User.searchUsers(db);
session.setAttribute(Constants.USER_LIST_KEY, userVector);
Jsp中:
Vector userVector = (Vector) session
.getAttribute(Constants.USER_LIST_KEY);
- Struts框架中常量文件的使用
- Class文件中常量池的理解
- C++中常量的定义与使用
- PHP中常量的定义和使用
- 在objc项目中常量的使用
- Struts2中文件struts.properties中常量的意义
- Struts2的struts.xml配置中常量含义
- 关于头文件中常量和静态常量的用处
- Struts2中常量的配置
- struts2_5_struts中常量的配置
- PHP中常量的定义
- Java中常量的应用
- Kotlin中常量的探究
- java类读取properties文件中常量
- struts框架的使用
- 关于接口中常量的访问方法
- C中常量参与运算的问题
- sql语句中常量的处理
- 分页(转)
- VS2005快捷键
- Apache httpd.conf
- 使用javascript生成日历
- 读《自己动手写操作系统》
- Struts框架中常量文件的使用
- 存储过程 VS 嵌入代码的sql语句
- My 5th Times!
- 折腾了两天,把google搜索加上了,输入框输入内容回车后却不管用,郁闷
- 反射技术与设计模式
- CodeSmith,SqlServer,C#中的类型对照
- LINUX常用网络配置文件的介绍
- Core Java2(7Th) study(2)The situations that when to throw exception!
- .net学习地址