首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2EE开发 >

Unreachable code解决方法

2013-12-11 
Unreachable code我的 JSP页面中有段代码如下:div classcontentul classclass_dateli idclas

Unreachable code
我的 JSP页面中有段代码如下:


<div class="content">
        <ul class="class_date">
            <li id="class_month">
             <%
            TopicBiz tb=new TopicBizImpl(); 
                List<Topics> topics=tb.getTopics();
                request.setAttribute("topics",topics);
                String topicId=request.getParameter("ntid");
                if(topicId==null) response.sendRedirect("Index.jsp");
                return;
                 %>
                 <c:forEach var="topic" items="${topics}" varStatus="status">
                 <a href="CIndex.jsp?ntid=${topic.tid}"><b><c:out value="${topic.tname}"></c:out></b></a>
                 </c:forEach>

报错信息:

An error occurred at line: 170 in the jsp file: /pages/CIndex.jsp
Unreachable code
167:                 String topicId=request.getParameter("ntid");
168:                 if(topicId==null) response.sendRedirect("Index.jsp");
169:                 return;
170:                  %>
171:                  <c:forEach var="topic" items="${topics}" varStatus="status">
172:                  <a href="CIndex.jsp?ntid=${topic.tid}"><b><c:out value="${topic.tname}"></c:out></b></a>
173:                  </c:forEach>

如果代码都写在<% %>里使用return 就不会报错,但是我想使用JSTL 标签,我想知道怎样写可以在执行到response.sendRedirect()方法时代码不会往下继续执行,并且我仍然可以使用JSTL标签?
[解决办法]
官方的:http://docs.oracle.com/javaee/5/jstl/1.1/docs/tlddocs/fn/tld-summary.html
其他的也可以看看http://www.blogjava.net/SkyWinder/archive/2008/11/07/239289.html

热点排行