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>Insert title here</title>
</head>
<body>
<%
String[] arr={"Java Web开发典型模块大全","Java范例完全自学手册","JSP项目开发全程实录"};//定义一维数组
request.setAttribute("book",arr); //将数组保存到request对象中
%>
<%
String[] arr1=(String[])request.getAttribute("book");//获取保存到request范围内的变量
//通过循环和EL输出一维数组的内容
for(int i=0;i<arr1.length;i++){
request.setAttribute("requestI",i);
%>

${requestI}:${book[requestI]}<br><!-- 输出数组中第i个元素 -->
<%} %>


</body>
</html>









//



<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8" import ="java.util.*"%>
<!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>
<%
List<String> list = new ArrayList<String>(); //声明一个List集合的对象
list.add("饼干"); //添加第1个元素
list.add("牛奶"); //添加第2个元素
list.add("果冻"); //添加第3个元素
session.setAttribute("goodsList",list); //将List集合保存到session对象中
%>
<%
List<String> list1=(List<String>)session.getAttribute("goodsList");//获取保存到session范围内的变量
//通过循环和EL输出List集合的内容
for(int i=0;i<list1.size();i++){
request.setAttribute("requestI",i);//将循环增量保存到request范围内
%>

${requestI}:${goodsList[requestI]}<br><!-- 输出集合中的第i个元素 -->
<%} %>


</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>
<%
request.setAttribute("userName","mr"); //定义request范围内的变量userName
request.setAttribute("pwd","mrsoft"); //定义pwd范围内的变量pwd
%>
userName=${userName}<br> <!-- 输入变量userName -->
pwd=${pwd}<br> <!-- 输入变量pwd -->
\${userName!="" and (userName=="明日") }: <!-- 将EL原样输出 -->
${userName!="" and userName=="明日" }<br> <!-- 输出由关系和逻辑运算符组成的表达式的值 -->
\${userName=="mr" and pwd=="mrsoft" }: <!-- 将EL原样输出 -->
${userName=="mr" and pwd=="mrsoft" } <!-- 输出由关系和逻辑运算符组成的表达式的值 -->


</body>
</html>











//





<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8" %>
<jsp:useBean id="user" scope="page" class="com.wgh.UserInfo" type="com.wgh.UserInfo">
<jsp:setProperty name="user" property="name" value="明日科技"/>
</jsp:useBean>


<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>通过pageScope隐含对象读取page范围内的JavaBean的属性值</title>
</head>
<body>
${pageScope.user.name}
</body>
</html>













//



<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>获取Web应用初始化参数并显示</title>
</head>
<body>
版权所有:${initParam.company}
</body>
</html>










//



<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="/stringDeal" prefix="wghfn"%>
<%request.setCharacterEncoding("UTF-8"); %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>显示结果</title>
</head>
<body>
内容为:<br>
${wghfn:shiftEnter(param.content)}
</body>
</html>










//



<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>定义EL函数处理字符串中的回车换行符和空格符</title>
</head>
<body>
<form name="form1" method="post" action="deal.jsp">
  <textarea name="content" cols="30" rows="5"></textarea>
  <br>
  <input type="submit" name="Button" value="提交" >
</form>


</body>
</html>













//




<%@ page language="java" contentType="text/html; charset=GB18030"
    pageEncoding="GB18030"%>
<%
request.setCharacterEncoding("GB18030");
%>
${empty param.username?"用户名为空":param.username}
<br>
${empty param.pwd?"密码为空":param.pwd}
<br>
<a href="index.jsp">返回</a>











//




<%@ page language="java" contentType="text/html; charset=GB18030"
    pageEncoding="GB18030"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB18030">
<title>用户登录</title>
</head>
<body>
<form name="form1" method="post" action="deal.jsp">
  <table width="349" height="237" border="0" align="center" cellpadding="0" cellspacing="0" background="images/bg.gif">
  <tr>
    <td width="116" height="86">&nbsp;</td>
    <td width="233" valign="bottom"><input name="username" type="text" id="username" style="border:1px solid #B99500; width:160px;">
      *</td>
  </tr>
  <tr>
    <td height="40">&nbsp;</td>
    <td valign="bottom"><input name="pwd" type="password" id="pwd" style="border:1px solid #B99500; width:160px;">
      *</td>
  </tr>
  <tr>
    <td colspan="2" align="center">&nbsp; <input type="image" name="imageField" src="images/bt_1.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="image" name="imageField" src="images/bt_2.gif" onClick="form1.reset();return false;">
     </td>
    </tr>
</table>
</form>
</body>
</html>














//




<%@ page language="java" contentType="text/html; charset=GB18030"
    pageEncoding="GB18030"%>
<%
request.setCharacterEncoding("GB18030");
%>


<%
/*
String user=request.getParameter("user"); //获取文本框的值
String pwd=request.getParameter("pwd"); //获取密码域的值
String email=request.getParameter("email"); //获取文本框的值
String sex=request.getParameter("sex"); //获取单选按钮的值
/*****************获取复选框的值**********************/
/*
String[] arrAffect=request.getParameterValues("affect");//获取复选框的值
String affect="";
if(arrAffect!=null){
//通过for循环遍历获取到的数组
for(int i=0;i<arrAffect.length;i++){
affect+=arrAffect[i]+",";//输出当前元素
}
System.out.println(affect.length());
affect=affect.substring(0,affect.length()-1);//去除字符串中最后一个逗号
}
/*****************************************************/
/*
String memo=request.getParameter("memo"); //获取编辑框的值
*/
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB18030">
<title>获取用户注册信息</title>
<style>
td,body{
padding:5px;
font-size:12px;
}
</style>
</head>
<body>
<form name="form1" method="post" action="">
<table width="400" height="30" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#333333">
  <tr>
    <td width="76" align="center" bgcolor="#FFFFFF">用&nbsp;户&nbsp;名:</td>
    <td width="324" bgcolor="#FFFFFF">&nbsp;${param.user }</td>
  </tr>
  <tr>
    <td align="center" bgcolor="#FFFFFF">密&nbsp;&nbsp;&nbsp;&nbsp;码:</td>
    <td bgcolor="#FFFFFF">&nbsp;${param.pwd }</td>
  </tr>
  <tr>
    <td align="center" bgcolor="#FFFFFF">E-mail:</td>
    <td bgcolor="#FFFFFF">&nbsp;${param.email }</td>
  </tr>
  <tr>
    <td align="center" bgcolor="#FFFFFF">性&nbsp;&nbsp;&nbsp;&nbsp;别:</td>
    <td bgcolor="#FFFFFF">&nbsp;${param.sex }</td>
  </tr>
  <tr>
    <td align="center" bgcolor="#FFFFFF">爱 &nbsp;&nbsp;&nbsp;&nbsp;好:</td>
    <td bgcolor="#FFFFFF">&nbsp;${paramValues.affect[0]} ${paramValues.affect[1]} ${paramValues.affect[2]} ${paramValues.affect[3]}</td>
  </tr>
  <tr>
    <td align="center" bgcolor="#FFFFFF">备&nbsp;&nbsp;&nbsp;&nbsp;注:</td>
    <td bgcolor="#FFFFFF">&nbsp;${param.memo }</td>
  </tr>
  <tr>
    <td colspan="2" align="center" bgcolor="#FFFFFF"><a href="index.jsp">返回</a></td>
    </tr>
</table>
</form>
</body>
</html>













<%@ page language="java" contentType="text/html; charset=GB18030"
    pageEncoding="GB18030"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB18030">
<title>用户注册</title>
<style>
td,body{
padding:5px;
font-size:12px;
}
</style>
</head>
<body>
<form name="form1" method="post" action="deal.jsp">
<table width="400" height="30" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td width="76" align="center">用&nbsp;户&nbsp;名:</td>
    <td width="324">
      <input name="user" type="text" id="user">    </td>
  </tr>
  <tr>
    <td align="center">密&nbsp;&nbsp;&nbsp;&nbsp;码:</td>
    <td><input name="pwd" type="password" id="pwd"></td>
  </tr>
  <tr>
    <td align="center">确认密码:</td>
    <td><input name="pwd1" type="password" id="pwd1"></td>
  </tr>
  <tr>
    <td align="center">E-mail:</td>
    <td><input name="email" type="text" id="email" size="45"></td>
  </tr>
  <tr>
    <td align="center">性&nbsp;&nbsp;&nbsp;&nbsp;别:</td>
    <td><input name="sex" type="radio" value="男" checked="checked">
      男 
      <input name="sex" type="radio" value="女">
      女</td>
  </tr>
  <tr>
    <td align="center">爱 &nbsp;&nbsp;&nbsp;&nbsp;好:</td>
    <td><input name="affect" type="checkbox" id="affect" value="游泳">
      游泳
      <input name="affect" type="checkbox" id="affect" value="旅游">
      旅游
      <input name="affect" type="checkbox" id="affect" value="看书">
      看书
      <input name="affect" type="checkbox" id="affect" value="唱歌">
      唱歌</td>
  </tr>
  <tr>
    <td align="center">备&nbsp;&nbsp;&nbsp;&nbsp;注:</td>
    <td><textarea name="memo" cols="43" rows="5" id="memo"></textarea></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td><input type="submit" name="Submit" value="注册">
      <input type="reset" name="Submit2" value="重置"></td>
  </tr>
</table>
</form>
</body>
</html>










//




<%@ page language="java" contentType="text/html; charset=GB18030"
    pageEncoding="GB18030"%>
<%@ taglib uri="/codeShift" prefix="wghfn"%>
用户名:${wghfn:codeShift(param.username)}
<br>
密&nbsp;&nbsp;码:${wghfn:codeShift(param.pwd)}
<br>
<a href="index.jsp">返回</a>










//




<%@ page language="java" contentType="text/html; charset=GB18030"
    pageEncoding="GB18030"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB18030">
<title>用户登录</title>
</head>
<body>
<form name="form1" method="post" action="deal.jsp">
  <table width="349" height="237" border="0" align="center" cellpadding="0" cellspacing="0" background="images/bg.gif">
  <tr>
    <td width="116" height="86">&nbsp;</td>
    <td width="233" valign="bottom"><input name="username" type="text" id="username" style="border:1px solid #B99500; width:160px;">
      *</td>
  </tr>
  <tr>
    <td height="40">&nbsp;</td>
    <td valign="bottom"><input name="pwd" type="password" id="pwd" style="border:1px solid #B99500; width:160px;">
      *</td>
  </tr>
  <tr>
    <td colspan="2" align="center">&nbsp; <input type="image" name="imageField" src="images/bt_1.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="image" name="imageField" src="images/bt_2.gif" onClick="form1.reset();return false;">
     </td>
    </tr>
</table>
</form>
</body>
</html>













//




<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>应用&lt;c:import&gt;标签导入网站Banner</title>
</head>
<body style=" margin:0px;">
<c:set var="typeName" value="流行金曲 | 经典老歌 | 热舞DJ | 欧美金曲 | 少儿歌曲 | 轻音乐 | 最新上榜"/>
<!-- 导入网站的Banner -->
<c:import url="navigation.jsp" charEncoding="UTF-8">
<c:param name="typeList" value="${typeName}"/>
</c:import>


</body>
</html>













<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%request.setCharacterEncoding("UTF-8"); %>
<table width="901" height="128" border="0" align="center" cellpadding="0" cellspacing="0" background="images/bg.jpg">
  <tr>
    <td width="16" height="91">&nbsp;</td>
    <td width="885">&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td style=" font-size:11pt; color:#FFFFFF"><b>${param.typeList}</b></td>
  </tr>
</table>










//




<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>应用&lt;c:url&gt;标签生成带参数的URL地址</title>
</head>
<body>
<c:url var="path" value="register.jsp" scope="page">
<c:param name="user" value="mr"/>
<c:param name="email" value="wgh717@sohu.com"/>
</c:url>
<a href="${pageScope.path }">提交注册</a>
</body>
</html>












//



<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>重定向页面并传递参数</title>
</head>
<body>
<c:redirect url="main.jsp">
<c:param name="user" value="cdd"/>
</c:redirect>
</body>
</html>










//




<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>显示结果</title>
</head>
<body>
[${param.user }]您好,欢迎访问我公司网站!
</body>
</html>









//






<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>根据是否登录显示不同的内容</title>
</head>
<body>
<c:if var="result" test="${empty param.username}">
  <form name="form1" method="post" action="">
用户名:
      <input name="username" type="text" id="username">
    <br>
    <br>
    <input type="submit" name="Submit" value="登录">
  </form>
</c:if>
<c:if test="${!result}">
[${param.username }] 欢迎访问我公司网站!
</c:if>
</body>
</html>









//


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值