1. 会话的销毁
1.1 设置会话的超时时间
<session-config>
<session-timeout>30</session-timeout>
</session-config>
单位为分
1.2 在代码进行设置程序的超时时间
session.setMaxInactiveInterval(20*60); 单位是秒
2. 若一个session已经销毁了,结果就无法调用其中的属性,否则会报无效状态异常
情况一:
resp.setContentType("html/text");
PrintWriter pWriter = resp.getWriter();
HttpSession session = req.getSession();
session.setAttribute("foo", "42");
session.setMaxInactiveInterval(0);
if (session.isNew())
{
pWriter.println("this is a new session!");
}
else
{
pWriter.println("welcome back!");
}
pWriter.println("Foo" + session.getAttribute("foo"));
情况二:
resp.setContentType("html/text");
PrintWriter pWriter = resp.getWriter();
HttpSession session = req.getSession();
session.setAttribute("foo", "42");
session.setAttribute("bar", "420");
session.invalidate();
String foo = (String)session.getAttribute("foo");
pWriter.println("Foo"+foo);
3. 会话的迁移
上下文、servletConfig、session ,在从一个JVN迁移到另一个JVM时候,上下文和servletConfig会进行复制,session会迁移。及在分布式系统中,只会保持一份session
即session从一个VM钝化,从另一个VM激活。
4. jsp的编译过程
myjsp.jsp --> myjso_jsp.java --> myjso_jsp.class --> myjsp_jsp (servlet)
4.1 scriptlet代码:
<html><body>
<% out.printLn(Count.getCount());%>
</body></html>
4.2 表达式代码:
<html><body>
<%= Count.getCount()%>
</body></html>
4.3 第三种方式
<html><body>
<%! int a = 1 >
<%= Count.getCount()%>
</body></html>
4.1. 4.2 两者进行比较发现:表达式没有out对象和分号
表达式代码中Count.getCount()会被转化为out.printLn(Count.getCount());
4.1 4.2 声明的变量都是在service方法内,4.3方法是在service方法之外。
<body>
This is my JSP page. <br>
<%! int b = 6; %>
<% int a = 5; %>
<%=a %>
<%=b %>
</body>
编译之后为:
public final class Count_jsp extends org.apache.jasper.runtime.HttpJspBase
implements org.apache.jasper.runtime.JspSourceDependent {
int b = 6;
。。。。。。
public void _jspService(HttpServletRequest request, HttpServletResponse response) ---对应到servlet中的service方法
throws java.io.IOException, ServletException {
.......
int a = 5;
.....
out.print(a );
out.write("\r\n");
out.write(" ");
out.print(b );
}
1.1 设置会话的超时时间
<session-config>
<session-timeout>30</session-timeout>
</session-config>
单位为分
1.2 在代码进行设置程序的超时时间
session.setMaxInactiveInterval(20*60); 单位是秒
2. 若一个session已经销毁了,结果就无法调用其中的属性,否则会报无效状态异常
情况一:
resp.setContentType("html/text");
PrintWriter pWriter = resp.getWriter();
HttpSession session = req.getSession();
session.setAttribute("foo", "42");
session.setMaxInactiveInterval(0);
if (session.isNew())
{
pWriter.println("this is a new session!");
}
else
{
pWriter.println("welcome back!");
}
pWriter.println("Foo" + session.getAttribute("foo"));
情况二:
resp.setContentType("html/text");
PrintWriter pWriter = resp.getWriter();
HttpSession session = req.getSession();
session.setAttribute("foo", "42");
session.setAttribute("bar", "420");
session.invalidate();
String foo = (String)session.getAttribute("foo");
pWriter.println("Foo"+foo);
3. 会话的迁移
上下文、servletConfig、session ,在从一个JVN迁移到另一个JVM时候,上下文和servletConfig会进行复制,session会迁移。及在分布式系统中,只会保持一份session
即session从一个VM钝化,从另一个VM激活。
4. jsp的编译过程
myjsp.jsp --> myjso_jsp.java --> myjso_jsp.class --> myjsp_jsp (servlet)
4.1 scriptlet代码:
<html><body>
<% out.printLn(Count.getCount());%>
</body></html>
4.2 表达式代码:
<html><body>
<%= Count.getCount()%>
</body></html>
4.3 第三种方式
<html><body>
<%! int a = 1 >
<%= Count.getCount()%>
</body></html>
4.1. 4.2 两者进行比较发现:表达式没有out对象和分号
表达式代码中Count.getCount()会被转化为out.printLn(Count.getCount());
4.1 4.2 声明的变量都是在service方法内,4.3方法是在service方法之外。
<body>
This is my JSP page. <br>
<%! int b = 6; %>
<% int a = 5; %>
<%=a %>
<%=b %>
</body>
编译之后为:
public final class Count_jsp extends org.apache.jasper.runtime.HttpJspBase
implements org.apache.jasper.runtime.JspSourceDependent {
int b = 6;
。。。。。。
public void _jspService(HttpServletRequest request, HttpServletResponse response) ---对应到servlet中的service方法
throws java.io.IOException, ServletException {
.......
int a = 5;
.....
out.print(a );
out.write("\r\n");
out.write(" ");
out.print(b );
}