我们知道EL表达式很容易获得基本属性值
例如
request.setAttribute(“age”,11);
我们的EL表达式
${requestScope.age}
在如果是这样的呢
User_table ut=new User_table();
ut.setPwd("abc");
ut.setUserid("aabb");
ut.setBirth(new Date());
request.setAttribute("users",ut);
package com.bean;
import java.text.SimpleDateFormat;
import java.util.Date;
public class User_table {
private String userid;
private String pwd;
private Date birth;
public Date getBirth() {
return birth;
}
public void setBirth(Date birth) {
this.birth = birth;
}
public String getUserid() {
return userid;
}
public void setUserid(String userid) {
this.userid = userid;
}
public String getPwd() {
return pwd;
}
public void setPwd(String pwd) {
this.pwd = pwd;
}
@Override
public String toString() {
return "User_table{" +
"userid='" + userid + '\'' +
", pwd='" + pwd + '\'' +
'}';
}
}
${requestScope.users.userid}<br/>
${requestScope.users.pwd}<br/>
你如何更好的格式化日期呢
修改你的User_table.java代码
package com.bean;
import java.text.SimpleDateFormat;
import java.util.Date;
public class User_table {
private String userid;
private String pwd;
private Date birth;
public String getBirthinfo(){//这这样一个方法
//这个方法名字第一定是get****第一个字母大写。
if(null!=birth){
SimpleDateFormat sdf=new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");
return sdf.format(birth);
}
return null;
}
public Date getBirth() {
return birth;
}
public void setBirth(Date birth) {
this.birth = birth;
}
public String getUserid() {
return userid;
}
public void setUserid(String userid) {
this.userid = userid;
}
public String getPwd() {
return pwd;
}
public void setPwd(String pwd) {
this.pwd = pwd;
}
@Override
public String toString() {
return "User_table{" +
"userid='" + userid + '\'' +
", pwd='" + pwd + '\'' +
'}';
}
}
最后在你的JSP页面中的EL表达式
${requestScope.users.userid}<br/>
${requestScope.users.pwd}<br/>
${requestScope.users.birthinfo}<br/>
//birthinfo 就是你写的方法名字,不带get并且都是小写
运行结果
来源:CSDN
作者:风学长
链接:https://blog.csdn.net/zhang6132326/article/details/103949590