问题描述
package com.svse.struts.action;import java.util.List;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import org.apache.struts.action.ActionForm;import org.apache.struts.action.ActionForward;import org.apache.struts.action.ActionMapping;import org.apache.struts.actions.DispatchAction;import com.svse.struts.entity.TBoard;import com.svse.struts.entity.TType;import com.svse.struts.form.BoardForm;import com.svse.struts.impl.BoardImpl;import com.svse.struts.impl.TypeImpl;import com.svse.struts.service.BoardService;import com.svse.struts.service.TypeService;public class BoardAction extends DispatchAction{private BoardService boardService = new BoardImpl();private TypeService typeService = new TypeImpl();/*** * */public ActionForward all(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response){BoardForm boardForm = (BoardForm) form;//怎么在demo.jsp页面中显示所查询的type.getTName()和board.getBName()的值,向这样嵌套循环,用什么标签<c:foreach>还是<logic>?第二个循环是根据第一个循环条件获得的List<TType> typeList = typeService.getAllType();for (TType type : typeList) {System.out.println(type.getTName());List<TBoard> title = boardService.getAllTitle(type.getTId());//根据ID查询所有版面信息request.setAttribute("title", title);for (TBoard board : title) {System.out.println("________________"+board.getBName());}}return new ActionForward("/user/demo.jsp",false);//请求转发}}
解决方案
应该是这样吧<c:forEach items="action里传递到页面的集合1" var="集合1"> <c:forEach items="action里传递到页面的集合2" var="集合2"> <c:if test="集合2.属性==集合1属性"> 显示内容,既可以获取集合1的,也可以获取集合2的 </c:if> </c:forEach></c:forEach>
解决方案二:
都可以
解决方案三:
两个都可以吧