如下两个jsp是按照书上的例子写的,最后运行结果是:当前登陆的用户名为: null  当前登陆的密码为: null
很纳闷为什么是空值呢?是不是我写的位置不对,不太确定request01.jsp写的是不是完整,是照书上敲得。
request01.jsp:<% request.setAttribute("user", "admin");
request.setAttribute("password", "888888");
 %>
 <jsp:forward page="request02.jsp">
 </jsp:forward>request02.jsp:<%@ page language="java" import="java.util.*" pageEncoding="gb2312"%>
<html>
  <head>
    <title>新闻管理系统</title>
  </head>
  
  <body>
  <h2>
  当前登陆的用户名为:
  <%=request.getAttribute("user") %>
  </h2>
  <br>
  <h2>
  当前登陆的密码为:
  <%=request.getAttribute("password") %>
  </h2>   
  </body>
</html>

解决方案 »

  1.   

    运行环境是Eclipse+MyEclipse+Tomcat,我运行的是request02.jsp
      

  2.   

    这个肯定是没有问题的,
    你不会是直接进到:request02.jsp这个页面去访问的吧,那肯定是null了。
    你要通过request01.jsp这个页面转发过去才行呀。
      

  3.   

    如果运行request01.jsp,会出现以下错误提示:
    e Exception reportmessage /request01.jsp (line: 20, column: 1) Expecting "jsp:param" standard action with "name" and "value" attributesdescription The server encountered an internal error that prevented it from fulfilling this request.不知道这是什么情况,该怎么解决呢?
      

  4.   


    如果运行request01.jsp,会出现以下错误提示:
    e Exception reportmessage /request01.jsp (line: 20, column: 1) Expecting "jsp:param" standard action with "name" and "value" attributesdescription The server encountered an internal error that prevented it from fulfilling this request.
      

  5.   

    已经解决了,希望其他新手不要被同样的问题困扰。
    request01.jsp 中:
    <jsp:forward page="request02.jsp">
    </jsp:forward>这里有问题,如果是成对出现的话,必须有 <jsp:param />标签。 你直接修改成自闭合的标签就好了。修改如下:
      <jsp:forward page="request02.jsp"  />