关于jstl标签库的forEach,out的简单使用记录

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_28553681/article/details/79499711

笃信好学,自然宽和

// @WebServlet 在Tomcat 6.0没有此类 ,Tomcat 7.0的server.api才有;可以将Tomcat 7.0下的\lib\servlet-api.jar文件拷贝到项目的WebRoot\WEB-INF\lib目录,然后导入到工程中。

@WebServlet("/TestCaipiao") 

public class TestCaipiao extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
GetNum getNum = new GetNum();
List<Num> list = getNum.getNum();

request.setAttribute("num1", list);
request.getRequestDispatcher("index.jsp").forward(request, response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
}

}

---------------------

          <a href="TestCaipiao"><h3>这是测试使用的jsp</h3></a>

<table align="center" border="1" width="300" height="100" >
   
    <tr>
        <td id="redball" align="center">RedBall</td>
        <td id="blueball" align="center">BlueBall</td>
    </tr>
        <c:forEach items="${num1}" var="num">
        <tr>
            <td id="r1" align="center"><c:out value="${num.redball}"></c:out></td>
            <td id="b1" align="center"><c:out value="${num.blueball}"></c:out></td> 
        </tr>
        </c:forEach>

    </table>


--------------------------------------------------------------------------------

使用c:forEach,c:out标签,需要在项目中加入jstl的jar包;在配置文件web.xml中进行如下配置;

<jsp-config>
<taglib>
<taglib-uri>http://java.sun.com/jstl/fmt</taglib-uri>
<taglib-location>/WEB-INF/fmt.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>http://java.sun.com/jstl/fmt-rt</taglib-uri>
<taglib-location>/WEB-INF/fmt-rt.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>http://java.sun.com/jstl/core</taglib-uri>
<taglib-location>/WEB-INF/c.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>http://java.sun.com/jstl/core-rt</taglib-uri>
<taglib-location>/WEB-INF/c-rt.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>http://java.sun.com/jstl/sql</taglib-uri>
<taglib-location>/WEB-INF/sql.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>http://java.sun.com/jstl/sql-rt</taglib-uri>
<taglib-location>/WEB-INF/sql-rt.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>http://java.sun.com/jstl/x</taglib-uri>
<taglib-location>/WEB-INF/x.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>http://java.sun.com/jstl/x-rt</taglib-uri>
<taglib-location>/WEB-INF/x-rt.tld</taglib-location>
</taglib>
</jsp-config>

猜你喜欢

转载自blog.csdn.net/qq_28553681/article/details/79499711