日期:2014-05-17  浏览次数:20659 次

关于ServletContext的一点疑惑
<html>
  <head>
  <base href="<%=basePath%>">  
  <title>聊天室</title>  
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">  
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
  </head>  
  <body>
<h1 align="center">聊天室</h1>
<br>
<hr>
<font color="blue">
<%
String content=(String)getServletContext().getAttribute(new String("content")); out.println(content);
getServletContext().setAttribute("content",content+request.getParameter("content")+"<br>");
%>
</font>
<hr>
<form action="liaoliao.jsp">
<input type="text" name="content">
<input type="submit" value="发言"><input type="reset" value="重置">
</form>
  </body>
</html>

为什么在getAttribute方法中传一个new String("content") 不是传一个名称嘛,怎么会是对象 不懂

------解决方案--------------------
对象应该是放在一个字符串中的
------解决方案--------------------
Java code
public java.lang.Object getAttribute(java.lang.String name)

------解决方案--------------------
lz可能对字符串常量和字符串对象有疑惑,比如下面的声明
Java code
String s="java";
String s=new String("java");