javaBean_EL 水深无声 2022-06-13 02:56 109阅读 0赞 <%@ 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>Insert title here</title> </head> <body> <%-- <!-- El四则运算 --> <h4>$\{1+1\}</h4> <h4>$\{2-3\}</h4> <h4>$\{7/2\}</h4> <h4>$\{7%2\}</h4> <h4>$\{1==2\}</h4> <h4>$\{1==1\}</h4> <p>$\{true||false\}</p>$\{3>2 ? '大于':'小于'\} <p>$\{true&&false\}</p>$\{!true\} $\{empty 'abc'\} $\{empty ''\} $\{empty ""\} $\{3>2 ? "大于":"小于"\} --%> <!-- El表达式取参数 --><!-- request.getParameter("userName") --> <h4>$\{param.userName\}</h4> <h4>$\{param.passWord\}</h4> <!-- EL表达式访问Bean --> <!-- Emp emp=new Emp(); --> <jsp:useBean id="emp" class="svlt.Emp" scope="page"></jsp:useBean> <!-- emp.setName(request.getParameter("userName")) --> <jsp:setProperty property="name" name="emp" param="userName"/> <jsp:setProperty property="age" name="emp" param="passWord"/> <h4>name:$\{emp.name\}</h4><!-- emp.getName --> <h4>name:$\{emp.age\}</h4><!-- emp.getAge --> </body> </html> \------------------表单提交-------------- <%@ 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>Insert title here</title> </head> <body> <form action="ElDemo.jsp"> userName  :<input type="text" name="userName"/><br> passWord:<input type="password" name="passWord"/><br> <input type="submit" value="smmm" /> </form> </body> </html> \-------------------------Emp类------------------ package svlt; public class Emp \{ String name; int age; public Emp() \{ super(); \} public String getName() \{ return name; \} public void setName(String name) \{ this.name = name; \} public int getAge() \{ return age; \} public void setAge(int age) \{ this.age = age; \} \} \-------------------------------- <%//向不同范围内写入参数 request.setAttribute("user\_name","request user\_name"); session.setAttribute("user\_name","sesssion user\_name"); application.setAttribute("user\_name","application user\_name"); %> <h5>Request:$\{requestScope\['user\_name'\]\}</h5> <h5>Session:$\{sessionScope\['user\_name'\]\}</h5> <h5>Not set Scope:$\{user\_name\}</h5>
还没有评论,来说两句吧...