我是JSP初学者,按一本书上的代码在我机器上运行,为什么总是不对呢?
有两个页面。一个是index.jsp,一个是showportal.jsp。在index.jsp中作选择之后,跳转到showportal.
index的代码如下:
<html>
   <head>
     <title>first page</title>
   </head>
<body>
     <form action="showportal.jsp" method="get">
     <select name="portchoice">
     <option>news</option>
    <option>entertainment</option></select>
    <input type="submit" value="Select"/>
    </form>
  </body>
</html>
showportal的代码如下:
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head><title>second page. </title></head>
<c:choose>
<c:when test="${param.portchoice == 'news'}">   
  <body> 
    <h1>News</h1>
  </body>
</c:when>
<c:when test="${param.portchoice=='entertainment'}">
   <body> 
    <h1>Entertainment</h1>
   </body>
</c:when>
<c:otherwise>
<body>
<h1>Otherwise.</h1>
</body>
</c:otherwise>
</c:choose>
</html>
运行时,为什么无论在index中选择的是new还是entertainment, showportal中显示的都是Otherwise呢?

解决方案 »

  1.   

    我测试了没问题 选什么输出什么貌似你的jstl标签无效的样子 是不是正常安装了
      

  2.   

    一开始提示缺标签文件,我在tomcat的jsp-example文件夹里复制了jstl.jar和standard.jar,也许版本不对,我再重新下,thanks!
      

  3.   

    <%
    String str = request.getParameter("portchoice");
    if ("news".equals(str)) {
    %>
    <body>
    <h1>News</h1>
    </body><%
    } else if ("entertainment".equals(str)) {
    %>
    <body>
    <h1>Entertainment</h1>
    </body>
    <%
    } else {
    %>
    <body>
    <h1>Otherwise.</h1>
    </body>
    <%
    }
    %>
    用这段代码来代替<c:choose>*</c:choose>块
    测试结果看看