Web代码:
测试1:
<%--
Created by IntelliJ IDEA.
User: 鄢秋实
Date: 2018/1/4
Time: 15:04
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<%--
使用EL可以获得JSP四大域中的域属性
这与昨天学到的PageContext的全域查找是一个意思
EL表达式格式:
${}
--%>
${name}
</body>
</html>
测试2:
<%--
Created by IntelliJ IDEA.
User: 鄢秋实
Date: 2018/1/4
Time: 16:18
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>参数param</title>
</head>
<body>
<%--
获取请求参数中,参数名为name的值
并输出到jsp页面中
--%>
${param.name}
${paramValues.hobbies[0]}
</body>
</html>
测试3:
<%--
Created by IntelliJ IDEA.
User: 鄢秋实
Date: 2018/1/4
Time: 16:29
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>cookie</title>
</head>
<body>
${cookie.JSESSIONID.value}
</body>
</html>
测试4:
<%--
Created by IntelliJ IDEA.
User: 鄢秋实
Date: 2018/1/4
Time: 16:43
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="wsh" uri="http://wsh.com" %>
<html>
<head>
<title>EL函数库</title>
</head>
<body>
<%--
判断参数str是否以e结尾
--%>
${fn:endsWith(param.str,"e")}
${wsh:reverse("abcdef",6)}
</body>
</html>
Index:
<%--
Created by IntelliJ IDEA.
User: 鄢秋实
Date: 2018/1/4
Time: 15:02
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>$Title$</title>
</head>
<body>
$END$
</body>
</html>
JAVA代码:
ELUtil:
package com.yanqiushi.util;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class ELUtil {
/**
* 1. 必须是静态方法
* 2. 方法必须有返回值
* @param input
* @return
*/
public static String reverse(String input,int length){
char[] chars1 = input.toCharArray();
String output = "";
for (int i = chars1.length-1 ; i >= 0 ; i--){
output += chars1[i];
}
return output;
}
}
FindServlet:
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet(name = "FindServlet",urlPatterns = "/find")
public class FindServlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setAttribute("name","request");
request.getSession().setAttribute("name","session");
getServletContext().setAttribute("name","servletContext");
request.getRequestDispatcher("1_hello.jsp");
}
}