首页 > 代码库 > [烧脑时刻]EL表达式1分钟完事
[烧脑时刻]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 //NEW17 Family me =new Family();18 //SET19 me.setDog("Tom");20 me.setWife("Jack");21 me.setChildren("James");22 me.setCat("Tomcat");23 //REQUEST24 request.setAttribute("myFamily",me);25 %>26 <h1>使用EL表达式,秒杀你</h1>27 <%--request应为requestScope--%>28 ${requestScope.myFamily.cat}29 </body>30 </html>
- 然后再运行Tomcat,比程序员A快了几秒,哈哈哈哈。
[烧脑时刻]EL表达式1分钟完事
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。