gpt4 book ai didi

java - Spring MVC jsp c :if tag doesn't work

转载 作者:行者123 更新时间:2023-12-01 10:39:56 24 4
gpt4 key购买 nike

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<!DOCTYPE html>
<html>
<head>
<!-- jQuery -->
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
</head>
<body>

<c:if test="${error}">
<script>
alert("You must have something...");
</script>
</c:if>



</body>
</html>

jsp文件有

<c:if test="${error}">
<script>
alert("You must have something...");
</script>
</c:if>

Spring Controller 是

@RequestMapping(value = "/sample/board.do", method = RequestMethod.POST)
public ModelAndView updateBoard(@ModelAttribute HistoryBoard historyBoard) throws Exception {
ModelAndView mv = new ModelAndView("redirect");

mv.addObject("error", true);

return mv;
}

它使 url http://localhost:8080/test/board/board.do?error=true

但是c:if标签不起作用

<c:if test="${not empty error}">
<h1>TEST</h1>
</c:if>

c:if 不为空也不起作用。

如何修复这个标签?

最佳答案

错误是一个参数,而不是范围变量。

<c:if test="${not empty param.error}">
<h1>TEST</h1>
</c:if>

关于java - Spring MVC jsp c :if tag doesn't work,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34480409/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com