I have a separate JSP file in which I store session variables.
So I can use them in all other JSP's and don't write value manually (it goes from enums):
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page pageEncoding="UTF-8"
contentType="text/html;charset=UTF-8"
language="java"
import="by.shyshaliaksey.webproject.controller.command.CommandValue,
by.shyshaliaksey.webproject.controller.command.RequestAttribute,
by.shyshaliaksey.webproject.controller.command.RequestParameter,
by.shyshaliaksey.webproject.controller.command.PagePath,
by.shyshaliaksey.webproject.controller.command.FilePath,
by.shyshaliaksey.webproject.controller.command.SessionAttribute,
by.shyshaliaksey.webproject.model.entity.Role" %>
<c:set var="CONTROLLER" scope="session" value="${SessionAttribute.CONTROLLER.getValue()}"/>
<c:set var="ERROR_INFORMATION" scope="session" value="${SessionAttribute.ERROR_INFO.getValue()}"/>
<!-- Command values -->
<c:set var="OPEN_HOME_PAGE" scope="session" value="${CommandValue.OPEN_HOME_PAGE.getValue()}"/>
<c:set var="OPEN_ABOUT_PAGE" scope="session" value="${CommandValue.OPEN_ABOUT_PAGE.getValue()}"/>
<c:set var="OPEN_LOGIN_PAGE" scope="session" value="${CommandValue.OPEN_LOGIN_PAGE.getValue()}"/>
And I am using:
<c:if test="${CONTROLLER == null}">
<jsp:include page="${SESSION_VARIABLES}"/>
</c:if>
To test if there is session variables in current session. In all jsp pages.
The question is:
What is the best practice to set session variables to use them in jsp's?
Aucun commentaire:
Enregistrer un commentaire