Java 使用JSTL设置会话变量并在servlet/controller类中访问它
如果我使用JSTL设置会话变量,如下所示:Java 使用JSTL设置会话变量并在servlet/controller类中访问它,java,jsp,jakarta-ee,servlets,jstl,Java,Jsp,Jakarta Ee,Servlets,Jstl,如果我使用JSTL设置会话变量,如下所示: <c:set var="para" value="${CLIENT_LOGO}" scope="session" /> 注意:我不是在寻找在jsp中打印值的解决方案,比如: <c:out value="${sessionScope.para}" /> 但是,我想知道是否有任何解决方案可以在Java类中获得它。您必须在servlet中执行以下代码: 您可以使用JSTL设置会话 您必须在servlet中执行以下代码: 您可以使
<c:set var="para" value="${CLIENT_LOGO}" scope="session" />
注意:我不是在寻找在jsp中打印值的解决方案,比如:
<c:out value="${sessionScope.para}" />
但是,我想知道是否有任何解决方案可以在Java类中获得它。您必须在servlet中执行以下代码: 您可以使用JSTL设置会话
您必须在servlet中执行以下代码: 您可以使用JSTL设置会话
可以通过参考此代码来解决此问题
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<html>
<body>
This JSP stores the ultimate answer in a session-scoped variable where
the other JSPs in the web application can access it.
<p />
<c:set var="theUltimateAnswer" value="${41+1}" scope="session" />
Click <a href="displayAttributes.jsp">here</a> to view it.
</body>
</html>
用于显示值
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<html>
<head>
<title>Retrieval of attributes</title>
</head>
<body>
The ultimate answer is <c:out value="${sessionScope.theUltimateAnswer}" /> <br/>
</body>
</html>
可以通过参考此代码来解决此问题
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<html>
<body>
This JSP stores the ultimate answer in a session-scoped variable where
the other JSPs in the web application can access it.
<p />
<c:set var="theUltimateAnswer" value="${41+1}" scope="session" />
Click <a href="displayAttributes.jsp">here</a> to view it.
</body>
</html>
用于显示值
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<html>
<head>
<title>Retrieval of attributes</title>
</head>
<body>
The ultimate answer is <c:out value="${sessionScope.theUltimateAnswer}" /> <br/>
</body>
</html>
request.getSession.getatributepara;应该在servlet中工作,但确保在访问servlet中的会话之前必须执行设置会话的页面;应该在servlet中工作,但确保在访问servlet中的会话之前必须执行设置会话的页面。您解决了问题吗?
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<html>
<head>
<title>Retrieval of attributes</title>
</head>
<body>
The ultimate answer is <c:out value="${sessionScope.theUltimateAnswer}" /> <br/>
</body>
</html>