I am creating a Demo Spring MVC application, and I am trying to maintain Session with Interceptor. Everything is working fine inflow, But when I am trying to get session object value on JSP page with JSTL sessionScope like this: ${sessionScope.LoginSession.firstName} ,jsp page is not accepting it and it is printing this sessionScope line as it is, although i have added taglib and evrything properly.
I am getting session value correctly when I am trying to get value like this: session.getAttribute("LoginSession"), but it is not working with JSTL sessionScope.
My JSP page is:
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>
My web.xml file looks like this:
<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>
JSTL Dependency in POM:
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
I am Expecting that it should give me session Value properly but in JSP Page sessionScope value is appearing as it was written: ${sessionScope.LoginSession.firstName}