第一JSP頁面上,我有 -一個新的會話,會話變量返回的是空
<%@ page language="java" %>
<%@ page import="java.io.*,java.util.*" %>
<html>
<head>
<style type="text/css">
body {
font-family:verdana,arial,sans-serif;
font-size:10pt;
margin:10px;
background-color:#ff9900;
}
</style>
<%
session.setAttribute("theName", "abc");
%>
<li><a href="http://localhost:8080/auto/second.jsp" target="content">click here!!</a></li><br />
</body>
</html>
上second.jsp,我有,
<%@ page language="java" %>
<%@ page import="java.io.*,java.util.*" %>
<html>
<head>
Hello, <%out.print(session.getAttribute("theName")); %>
</table>
</body>
</html>
但是這裏會話變量「theName
」的值返回爲空。 我也同時在第一頁和第二頁做了<% out.print(session.getId()); %>
和問題是兩個不同的會話ID返回象 - 230EC6DA6ECD25BC96268942D0ACE5EB
C2399D151F0D6D6002D16A126EDDC9FB
(在第二頁)(上接第頁)
這似乎是原因該會話變量未成功傳遞。我也嘗試過
<%@ page session="false" %>
這樣就不會在second.jsp中創建新的會話。但是,如果我在second.jsp使用<%@ page session="false" %>
,那麼它會拋出異常碧玉 -
Jul 23, 2012 5:23:47 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet jsp threw exception
org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: 32
<%out.print(session.getAttribute("theName"));
at org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:93)
at org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
at org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:451)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:328)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:307)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:295)
at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:565)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:308)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:259)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:172)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:843)
at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:679)
at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1303)
請建議我如何可以通過會話變量從一個JSP頁面到另一個。提前感謝任何幫助!
'<%@網頁會議=「假」%>'意味着*不使用一個會話*,不*不創建一個新的會話,但使用任何現有的*躺在*。 – 2012-07-23 14:47:03
您可以將您的會話ID添加到您的鏈接中作爲'JSESSSIONID'參數。 – 2012-07-23 14:50:37
@ T.J。 - 我怎麼能做到這一點?因爲我認爲新的會話是在新的JSP頁面中默認創建的。糾正我,如果我錯了。 – anujin 2012-07-23 14:51:38