java - 即使在 jsp 页面中提供 taglib 之后,JSTL sessionScope 属性也不起作用
问题描述
我正在创建一个 Demo Spring MVC 应用程序,并且正在尝试使用 Interceptor 维护 Session。一切工作正常流入,但是当我尝试使用 JSTL sessionScope在 JSP 页面上获取会话对象值时,如下所示:${sessionScope.LoginSession.firstName},jsp 页面不接受它,它正在打印这个 sessionScope 行,虽然我已经正确添加了 taglib 和 evrything。
当我尝试获取这样的值时,我正在正确获取会话值:session.getAttribute("LoginSession"),但它不适用于 JSTL sessionScope。
我的 JSP 页面是:
pageEncoding="ISO-8859-1"%>
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<!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=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<div align="center">
<h1>Carwale Header</h1>
</div>
<div align="right">
<%
Object user = session.getAttribute("LoginSession");
System.out.println("Value from jsp "+user);
%>
<c:out value="${sessionScope.LoginSession.firstName}"></c:out>
<c:choose>
<c:when test="${sessionScope.LoginSession!=null}">
<c:out value="Welcome," />
<a href="addProduct.do"> <c:out
value="${sessionScope.LoginSession.firstName}" />
</a>
<div align="right">
<a href="logout.do">Logout</a>
</div>
</c:when>
</c:choose>
</div>
</body>
</html>
我的 web.xml 文件如下所示:
<web-app xmlns="http://java.sun.com/xml/ns/javaee" version="2.3"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_3.xsd">
<display-name>Archetype Created Web Application</display-name>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext-dao.xml</param-value>
</context-param>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
POM中的JSTL依赖:
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
我期望它应该正确地给我会话值,但是在 JSP 页面 sessionScope 值显示为它被写入:${sessionScope.LoginSession.firstName}
解决方案
推荐阅读
- go - golang中如何实现反向代理支持nginx渐进式下载?
- python - python - 如何在Python的数据框中应用将多个数字拆分到列的字段的函数?
- linux - 如何使用 diff 命令使用忽略匹配行选项区分 2 个文件
- apache-spark - spark结构化流批处理数据刷新问题(按子句分区)
- firebase - 我在“应用引擎”应用程序中收到一些未知请求,想知道它们是什么
- python - 为什么即使指定了 Y lim,Matplotlib 条形图也会切出高值?
- html - 在方形空间中调整 iframe 的大小以适应任何屏幕尺寸
- typescript - 具有静态工厂的抽象父类的子类的类型
- flutter - 即使在颤振应用程序窗口之外如何获得鼠标位置
- dataframe - 当数据位于两个不同的数据帧中时,如何显示阴影错误带?