这个session对象为什么会报错呢?
这是我测试一下session对象的程序
<%@ page contentType= "text/html;charset=GB2312 " %>
<HTML>
<BODY bgcolor=cyan> <FONT Size=5>
<BODY>
<%String s=session.getId();
%>
<P> 您的session对象的ID是:
<BR>
<%=s%>
<BODY>
<HTML>
报错如下,请高手给指点一下。
------解决方案-------------------- <%@ page contentType= "text/html;charset=GB2312 " %>
<HTML>
<BODY>
<%String s = session.getId();%>
<P> 您的session对象的ID是:
<BR>
<%=s%>
</BODY>
</HTML>
去掉中间的换行就没问题了;
不去掉换行的时候便已成了下面的代码段:
out.write( "\r\n ");
out.write( " <HTML> \r\n ");
out.write( " <BODY> \r\n ");
out.write( " ");
String s = session.getId();
out.write( "\r\n ");
out.write( " <P> 您的session对象的ID是:\r\n ");
out.write( " <BR> \r\n ");
out.print(s);
out.write( "\r\n ");
out.write( " </BODY> \r\n ");
out.write( " </HTML> ");
去掉换行的时候:
out.write( "\r\n ");
out.write( " <HTML> \r\n ");
out.write( " <BODY> \r\n ");
out.write( " ");
String s = session.getId();
out.write( "\r\n ");
out.write( " <P> 您的session对象的ID是:\r\n ");
out.write( " <BR> \r\n ");
out.print(s);
out.write( "\r\n ");
out.write( " </BODY> \r\n ");
out.write( " </HTML> ");
中间少了2个空行,你如果是记事本之类写的代码的话这两个空行就可能包含非法的空格;
若是在集成环境下写一般不会出错的。
你看看你的错误代码,就是出现了非法字符引起的。
------解决方案-------------------- <%@ page contentType= "text/html;charset=GB2312 " %>
<HTML>
<BODY bgcolor=cyan> <FONT Size=5>
<BODY>
<%
String s=session.getId();
%>
<P> 您的session对象的ID是:
<BR>
<%=s%>
</BODY>
</HTML>
我这样就可以显示出来了,估计你的代码语法有错误~~