Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/338.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/sharepoint/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用JSTL设置会话变量并在servlet/controller类中访问它_Java_Jsp_Jakarta Ee_Servlets_Jstl - Fatal编程技术网

Java 使用JSTL设置会话变量并在servlet/controller类中访问它

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中执行以下代码: 您可以使

如果我使用JSTL设置会话变量,如下所示:

<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>