[烧脑时刻]EL表达式1分钟完事
Posted Chan_炽烽
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[烧脑时刻]EL表达式1分钟完事相关的知识,希望对你有一定的参考价值。
- 一天,程序员A问我,我们比比谁的知识点多,反应快。我回答:那就看谁最快用EL表达式的显示在页面上吧。
- 话不多说,计时开始。
- 项目的结构如上,大概就是一个Family的JavaBean,一个jsp页面,再加上Tomcat的包
- Family.java
-
1 package com.chan.basic.domain; 2 3 /** 4 * Created by Chan on 2017/3/21. 5 */ 6 public class Family { 7 private String wife; 8 private String cat; 9 private String children; 10 private String dog; 11 12 public String getWife() { 13 return wife; 14 } 15 16 public void setWife(String wife) { 17 this.wife = wife; 18 } 19 20 public String getCat() { 21 return cat; 22 } 23 24 public void setCat(String cat) { 25 this.cat = cat; 26 } 27 28 public String getChildren() { 29 return children; 30 } 31 32 public void setChildren(String children) { 33 this.children = children; 34 } 35 36 public String getDog() { 37 return dog; 38 } 39 40 public void setDog(String dog) { 41 this.dog = dog; 42 } 43 }
- 值得一提的是IDEA,快速getter和setter的快捷键是Alt + Insert .
- index.jsp
-
1 <%@ page import="com.chan.basic.domain.Family" %> 2 <%-- 3 Created by IntelliJ IDEA. 4 User: Administrator 5 Date: 2017/3/22 6 Time: 17:49 7 To change this template use File | Settings | File Templates. 8 --%> 9 <%@ page contentType="text/html;charset=UTF-8" language="java" %> 10 <html> 11 <head> 12 <title></title> 13 </head> 14 <body> 15 <% 16 //NEW 17 Family me =new Family(); 18 //SET 19 me.setDog("Tom"); 20 me.setWife("Jack"); 21 me.setChildren("James"); 22 me.setCat("Tomcat"); 23 //REQUEST 24 request.setAttribute("myFamily",me); 25 %> 26 <h1>使用EL表达式,秒杀你</h1> 27 <%--request应为requestScope--%> 28 ${requestScope.myFamily.cat} 29 </body> 30 </html>
- 然后再运行Tomcat,比程序员A快了几秒,哈哈哈哈。
以上是关于[烧脑时刻]EL表达式1分钟完事的主要内容,如果未能解决你的问题,请参考以下文章