session的用法
动手编写了一个简单的例子用于复习session的用法:
包括4个文件:
index.jsp
session.jsp
link.jsp
next.jsp
index.jsp文件:
<%@ page contentType="text/html;charset=gb2312" %>
<form method=post action=session.jsp>
姓名:
<input type=text name=name><br>
<input type=submit value="确定">
</form>
用于提交一个字符串.
session.jsp文件:
<%@ page contentType="text/html;charset=gb2312" %>
<%
String name=new String(request.getParameter("name").getBytes("ISO-8859-1"),"GBK");
session.setAttribute("yourname",name);
%>
你的名字:
<%
out.println(name);
%>
<a href=link.jsp>link</a>
用于接收并储存字符串变量的值.
link.jsp
<%@ page contentType="text/html;charset=gb2312" %>
<%
String name=(String)session.getAttribute("yourname");
%>
你的名字:
<%
out.println(name);
%>
<a href=index.jsp>首页</a>
<a href=next.jsp>next</a>
next.jsp
<%@ page contentType="text/html;charset=gb2312" %>
<%
String name=(String)session.getAttribute("yourname");
%>
你的名字2:
<%
out.println(name);
%>
<a href=index.jsp>首页</a>
<a href=next.jsp>next</a>
lunzi
2005-06-07 02:40:20
评论:4
阅读:6253
引用:0
@2007-03-02 11:53:24 游客
<input type=submit value="确定">
</form>
用于提交一个字符串.
session.jsp文件:
<%@ page contentType="text/html;charset=gb2312" %>
<%
String name=new String(request.getParameter("name").getBytes("ISO-8859-1"),"GBK");
session.setAttribute("yourname",name);
%>
你的名字:
<%
out.println(name);
%>
<a href=link.jsp>link</a>
用于接收并储存字符串变量的值.
link.jsp
<%@ page contentType="text/html;charset=gb2312" %>
<%
String name=(String)session.getAttribute("yourname");
%>
你的名字:
<%
out.println(name);
%>
<a href=index.jsp>首页</a>
<a href=next.jsp>next</a>
next.jsp
<%@ page contentType="text/html;charset=gb2312" %>
<%
String name=(String)session.getAttribute("yourname");
</form>
用于提交一个字符串.
session.jsp文件:
<%@ page contentType="text/html;charset=gb2312" %>
<%
String name=new String(request.getParameter("name").getBytes("ISO-8859-1"),"GBK");
session.setAttribute("yourname",name);
%>
你的名字:
<%
out.println(name);
%>
<a href=link.jsp>link</a>
用于接收并储存字符串变量的值.
link.jsp
<%@ page contentType="text/html;charset=gb2312" %>
<%
String name=(String)session.getAttribute("yourname");
%>
你的名字:
<%
out.println(name);
%>
<a href=index.jsp>首页</a>
<a href=next.jsp>next</a>
next.jsp
<%@ page contentType="text/html;charset=gb2312" %>
<%
String name=(String)session.getAttribute("yourname");
aa
@2007-03-02 11:52:29 游客
还可以了,不过就是觉得有点看不懂的拉,哈哈!!
@2006-03-25 17:09:06 游客
<input type=submit value="确定">
</form>
用于提交一个字符串.
session.jsp文件:
<%@ page contentType="text/html;charset=gb2312" %>
<%
String name=new String(request.getParameter("name").getBytes("ISO-8859-1"),"GBK");
session.setAttribute("yourname",name);
%>
你的名字:
<%
out.println(name);
%>
<a href=link.jsp>link</a>
用于接收并储存字符串变量的值.
link.jsp
<%@ page contentType="text/html;charset=gb2312" %>
<%
String name=(String)session.getAttribute("yourname");
%>
你的名字:
<%
out.println(name);
%>
<a href=index.jsp>首页</a>
<a href=next.jsp>next</a>
next.jsp
<%@ page contentType="text/html;charset=gb2312" %>
<%
String name=(String)session.getAttribute("yourname");
</form>
用于提交一个字符串.
session.jsp文件:
<%@ page contentType="text/html;charset=gb2312" %>
<%
String name=new String(request.getParameter("name").getBytes("ISO-8859-1"),"GBK");
session.setAttribute("yourname",name);
%>
你的名字:
<%
out.println(name);
%>
<a href=link.jsp>link</a>
用于接收并储存字符串变量的值.
link.jsp
<%@ page contentType="text/html;charset=gb2312" %>
<%
String name=(String)session.getAttribute("yourname");
%>
你的名字:
<%
out.println(name);
%>
<a href=index.jsp>首页</a>
<a href=next.jsp>next</a>
next.jsp
<%@ page contentType="text/html;charset=gb2312" %>
<%
String name=(String)session.getAttribute("yourname");
ffffff
@2006-03-25 17:08:43 fffff
<input type=submit value="确定">
</form>
用于提交一个字符串.
session.jsp文件:
<%@ page contentType="text/html;charset=gb2312" %>
<%
String name=new String(request.getParameter("name").getBytes("ISO-8859-1"),"GBK");
session.setAttribute("yourname",name);
%>
你的名字:
<%
out.println(name);
%>
<a href=link.jsp>link</a>
用于接收并储存字符串变量的值.
link.jsp
<%@ page contentType="text/html;charset=gb2312" %>
<%
String name=(String)session.getAttribute("yourname");
%>
你的名字:
<%
out.println(name);
%>
<a href=index.jsp>首页</a>
<a href=next.jsp>next</a>
next.jsp
<%@ page contentType="text/html;charset=gb2312" %>
<%
String name=(String)session.getAttribute("yourname");
</form>
用于提交一个字符串.
session.jsp文件:
<%@ page contentType="text/html;charset=gb2312" %>
<%
String name=new String(request.getParameter("name").getBytes("ISO-8859-1"),"GBK");
session.setAttribute("yourname",name);
%>
你的名字:
<%
out.println(name);
%>
<a href=link.jsp>link</a>
用于接收并储存字符串变量的值.
link.jsp
<%@ page contentType="text/html;charset=gb2312" %>
<%
String name=(String)session.getAttribute("yourname");
%>
你的名字:
<%
out.println(name);
%>
<a href=index.jsp>首页</a>
<a href=next.jsp>next</a>
next.jsp
<%@ page contentType="text/html;charset=gb2312" %>
<%
String name=(String)session.getAttribute("yourname");
