更新时间:2023-10-06 13:03:10
将对象放在会话或请求中的servlet中:
Put the object either in session or request in servlet like :
String shared = "shared";
request.setAttribute("sharedId", shared); // add to request
request.getSession().setAttribute("sharedId", shared); // add to session
this.getServletConfig().getServletContext().setAttribute("sharedId", shared); // add to application context
您可以在jsp中读取它:
You can read it in jsp like :
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<body>
<cut value= "${shared}"/>
<cut value= "${requestScope.shared}"/>
<cut value= "${requestScope.request.shared}"/>
${shared}
或者使用带有代码的scriptlet读取它:
Or read it using scriptlet with code :
<%
String shared = (String)request.getAttribute("sharedId");
String shared1 = (String)request.getSession().getAttribute("sharedId");
String shared2 = (String)this.getServletConfig().getServletContext().getAttribute("sharedId");
%>