javaweb中表达式语言
来源:互联网 发布:孪生素数c语言 编辑:程序博客网 时间:2024/06/14 08:44
理解表达式EL并不是一种通用的编程语言,它只是一种数据访问语言。网页作者通过它可以很方便的在jsp页面中访问应用程序数据,无需使用小脚本(<%和%>)或jsp请求时表达式(<%=和%>),甚至不用学习Java语言就可以使用表达式语言。所以它有很多方便之处。
我们利用上一章Javabean的内容来进行改编EL语言显示数据。
- 首先我们需要建立一个javabean的类,该类中一定要包含无构造参数的构造函数。
package com;public class Customer {private String username;private String password;public Customer(){};//不带参数的构造函数//带参数的构造函数public Customer(String username,String password){this.username = username;this.password = password;}//getter方法public String getusername(){return this.username;};public String getpassword(){return this.password;};//setter方法public void setusername(String username){this.username = username;};public void setpassworde(String password){this.password = password;};}
- 然后编写登陆页面:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>login</title></head><!-- 页面的样式文件 --><style type="text/css">body{background-color : #eee;}#first{width:500px;margin:30px auto;}</style><body><div id="first">${sessionScope.message}<br><br><form action="login" method="post" ><table><tr><td>用户名:</td><td><input type="text" name="username"></td></tr><tr><td>密 码:</td><td><input type="password" name="password"></td></tr><tr><td><input type="checkbox" name="check" value="check"/>自动登录<br></td></tr><tr><td><input type="submit" value="确认"></td><td><input type="reset" value="取消"></td></tr></table></form></div></body></html>
- 在login.java 中使用javabean的实例customer来进行参数传递(相当于C):
package com;import java.io.IOException;import javax.servlet.*;import javax.servlet.http.*;import javax.servlet.annotation.WebServlet;;@WebServlet(name="/Login",urlPatterns={"/login"})public class Login extends HttpServlet {private static final long serialVersionUID = 1L; public Login() { super(); }protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {String username = request.getParameter("username");String password = request.getParameter("password");//构建类对象Customer customer = new Customer(username,password);HttpSession session = request.getSession();synchronized(session){session.setAttribute("customer", customer);}RequestDispatcher rd = request.getRequestDispatcher("/ELshow.jsp");rd.forward(request, response);}}
- 最后编写一个显示界面的jsp文件实现显示功能(使用EL语言):
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>ELshow</title></head><body><h1>用理解表达式语言EL访问Javabean元素</h1><h2>用户信息如下:</h2><table boder="1"><tr><td>用户名:</td><td>${customer.username}</td></tr><tr><td>密码:</td><td>${customer.password}</td></tr></table></body></html>
然后在页面上进行URL访问,就会得到用户的信息。
相关的EL语言还有很多的功能,它有自己的运算符,能够实现算术运算、关系运算、逻辑运算、条件运算、empty运算等等。大家可以查找相应的资料进行学习。
0 0
- javaweb中表达式语言
- javaWeb之表达式语言EL
- 14.JavaWeb基础 EL(表达式语言)
- javaweb 中 el表达式问题总结
- 深入分析JavaWeb Item48 -- Struts2中OGNL表达式与ValueStack
- 深入分析JavaWeb 48 -- Struts2中OGNL表达式与ValueStack
- maven工具构建 javaweb 工程中不支持el表达式
- C语言中逗号表达式
- C语言中函数表达式
- javaweb之EL表达式
- javaweb el表达式
- JavaWeb-EL表达式
- JavaWeb-EL表达式
- javaWeb--EL表达式
- JavaWeb:EL表达式
- 01-JavaWeb-EL表达式
- JavaWeb之El表达式
- Javaweb之EL表达式
- 关于xx-net的小细节
- HQL语句多表联合查询的视图
- Navicat for Oracle连接数据库时报错"ORA-12737 set ZHS16GBK"
- [leetcode:python]1.Two Sum
- 理解JSON
- javaweb中表达式语言
- 浏览器缓存初识
- reactNative搭建开发环境
- Java中的多线程你只要看这一篇就够了
- 基于zookeeper实现分布式锁
- python编程快速上手 第6章 实践项目 自己写的答案
- CNN数据增强(1)
- 使用Nvidia Jetson TX1,在新的C++工程中调用caffe
- 大型网站架构之分布式消息队列