zoukankan      html  css  js  c++  java
  • Maven搭建Spring MVC时使用jstl无效

    1 Maven引入依赖jar包:jstl.jar和standard.jar 

    <dependency>
          <groupId>javax.servlet</groupId>
          <artifactId>jstl</artifactId>
          <version>1.2</version>
          <scope>runtime</scope>
        </dependency> 
        <dependency>
          <groupId>taglibs</groupId>
          <artifactId>standard</artifactId>
          <version>1.1.2</version>
        </dependency>

    页面中引入jstl 即 

    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

    2.Jsp2.0一下版本默认不开启EL 所以需要在页面上添加 <%@ page isELIgnored="false" %>

    <%@ page isELIgnored="false" %>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
    <html >
    ....

    jsp2.0以上版本可以配置web.xml文件,默认开启EL

    <web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
    http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

    ...

    一个简单的Demo

    <%--<%@ page isELIgnored="false" %>--%>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
    <%@ page contentType="text/html;charset=UTF-8" language="java"  pageEncoding="UTF-8"  %>
    <html>
    <body>
    <h2>Hello World!</h2>
    <h3>
    <c:out value="${name}"></c:out></h3>
    <h4>
        <c:out value="${age}"></c:out>
    </h4>
    美女:
    <c:set  var="motto" scope="session">约么</c:set>
    <c:out value="${motto}"></c:out>
    </body>
    </html>
    @Controller
    @RequestMapping("/home")
    public class HomeController {
        @RequestMapping(value = "/index/{name}",method = RequestMethod.GET)
        public String Index(@PathVariable String name, @RequestParam String age, Model model ){
           model.addAttribute("name",name);
           model   .addAttribute("age",age);
           return "index"; 
        }  
    }
  • 相关阅读:
    Python之pytest 基础
    unittest和pytest的区别
    Selenium 常用定位对象元素的方法
    ORCAl存储过程
    Mysql的存储过程
    TestNG 搭建测试框架 自动化测试
    通过junit/TestNG+java 实现自动化测试
    查看APP用到的图片方法
    码农干私活的建议(转)
    Android的onCreateOptionsMenu()创建菜单Menu详解(转)
  • 原文地址:https://www.cnblogs.com/ylsforever/p/7661453.html
Copyright © 2011-2022 走看看