zoukankan      html  css  js  c++  java
  • EL与JSTL的简单使用

    首先我们在request域放入一些数据:

    package ELServletPack;
    
    import java.io.IOException;
    import java.util.HashMap;
    import java.util.Map;
    
    import javax.servlet.ServletException;
    import javax.servlet.annotation.WebServlet;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    @WebServlet("/ELServlet")
    public class ELServlet extends HttpServlet {
           
        protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
                request.setCharacterEncoding("utf-8");
                response.setCharacterEncoding("utf-8");
                response.setContentType("text/html; charset=UTF-8");
                
                request.setAttribute("name", "zs");
                System.out.println("访问到了");
                Map<String,String> map  = new HashMap<>();
                map.put("1", "lisi");
                map.put("2", "ww");
                map.put("3", "zl");
                
                request.setAttribute("mapElements", map);
        
                request.getRequestDispatcher("El.jsp").forward(request, response);;
        }
    
        protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            // TODO Auto-generated method stub
            doGet(request, response);
        }
    
    }

    新建jsp文件,读取request域中数据

    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
    <%@ taglib uri="http://java.sun.com/jsp/jstl/core"  prefix="c" %>
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title>Insert title here</title>
    </head>
    <body>
        ----request域---<br/>
            ${requestScope.name }<br/>
        --------Map对象-------<br/>
        ${requestScope.mapElements["1"]}<br/>
        ${requestScope.mapElements["2"]}<br/>
        ${requestScope.mapElements["3"]}<br/>
        
        --JSTL---request <br/>
        <c:out value="${requestScope.name}"/>
    
    </body>
    </html>
  • 相关阅读:
    this.$route和this.$router的区别
    HTTP请求方式中get和post的区别
    如何使用NPM?CNPM又是什么?
    javascript通过navigator.userAgent识别各种浏览器
    用JS添加和删除class类名
    前端布局神器display:flex
    强大的display:grid
    自动化测试的那些事儿
    selenium家族发展史
    第八章、函数进阶之字典生成式与匿名函数
  • 原文地址:https://www.cnblogs.com/aierben/p/14533926.html
Copyright © 2011-2022 走看看