2 u011766899 u011766899 于 2013.11.05 10:38 提问

jsp session,app内置对象问题

以下是一个实例的三个页面,第二个页面中的app对象换成session对象为什么第三个页面就得不到数据了呢?
第一个页面
》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》
<%@page contentType="text/html;charset=UTF-8"pageEncoding="UTF-8"%>


teachers and students

teachers and students platform


teacher:唐爱国

name:

header:

message:



》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》
第二个页面
<%@page contentType="text/html;charset=UTF-8"pageEncoding="UTF-8"%>
<%@page import="java.util.*"%>


teachers and students

teachers and students platform


<%!Vector v=new Vector();
ServletContext application;
synchronized void sendMessage(String s)
{
application=getServletContext();
v.add(s);
application.setAttribute("Mess",v);
}
%>
<%
String a=session.getId();
request.setCharacterEncoding("UTF-8");
String name=request.getParameter("peopleName");
String title=request.getParameter("title");
String messages=request.getParameter("messages");
if(name=="")
{
name="guest"+(int)(Math.random()*10000);
}
if(title=="")
{
title="no header";
}
if(messages=="")
{
messages="no message";
}
String s=name+"#"+title+"#"+messages;
sendMessage(s);
%>


congratulations!<%=a %>







》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》
第三个页面
<%@page contentType="text/html;charset=UTF-8"pageEncoding="UTF-8"%>
<%@page import="java.util.*" %>
<%request.setCharacterEncoding("UTF-8");%>


teachers and students


<%Vector v=new Vector();
v=(Vector)application.getAttribute("Mess");
String a=session.getId();
%>

teachers and students platform


total.like below:





<%for(int i=0;i {
String message=(String)v.elementAt(i);
String[] fenxi=message.split("#");
int j=0;
%>


<%while(j {
String str=fenxi[j];
j++;
%>

<%} %>

<%} %>

number

speaker

title

body

;<%=i+1 %> <%=str %>

back


Csdn user default icon
上传中...
上传图片
插入图片