在请求中存取属性

一、在请求中保存属性

public void setAttribute(String name, Object o){}

request.setAttribute("message","信息内容"); // 这里是String类型

二、在请求中获取属性

public Object getAttribute(String name){}
Object o
= request.getAttribute("message"); if(o!=null){ // 判断是否为空,防止空指针 String str = o.toString(); // 类型转换 //其他操作 }

猜你喜欢

转载自www.cnblogs.com/YeHuan/p/10876447.html