Sigmar Lessa 0 Denunciar post Postado Abril 16, 2016 Sou novo em java web e preciso buscar no Mysql as imagens para um banner em jquery. Porem usando o Forward ele fica em loop e não consigo mostrar. Segue codigos banner.jsp <jsp:forward page="/BannerController?action=listarBanner"></jsp:forward> <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <div id="wrapper"> <div class="slider-wrapper theme-default"> <div id="slider" class="nivoSlider" > <c:forEach var="b" items="${banner}"> <img src= <c:out value="${b.imgbanner}" /> alt="" width="635" height="342" /> </c:forEach> </div> </div> </div> BannerController package br.apetite.controller; import br.apetite.dao.BannersDAO; import java.io.IOException; import javax.servlet.RequestDispatcher; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class BannerController extends HttpServlet { BannersDAO dao ; public BannerController() { super(); dao = new BannersDAO(); } String forward = "banner.jsp"; protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { } @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String action = request.getParameter("action"); if (action.equalsIgnoreCase("listarBanner")) { request.setAttribute("banner", dao.ListaBanner()); } RequestDispatcher view = request.getRequestDispatcher(forward); view.forward(request, response); } @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response); } @Override public String getServletInfo() { return "Short description"; } } bannerDao package br.apetite.dao; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.util.ArrayList; import java.util.List; import br.apetite.model.Banner; import java.sql.Connection; /** * * @author Sigmar */ public class BannersDAO extends Dao { //Lista os banners Principais private Connection connection; public BannersDAO() { connection = Dao.getConnection(); } public List<Banner> ListaBanner() { List<Banner> imgbanners = new ArrayList<Banner>(); try { Statement statement = connection.createStatement(); ResultSet rs = statement.executeQuery("SELECT * FROM banner where active='Sim'"); while (rs.next()) { Banner b = new Banner(); b.setimgBanner(rs.getString("banner_url")); b.setBanner_URL(rs.getString("banner_reurl")); imgbanners.add( b ); } } catch (SQLException e) { e.printStackTrace(); } return imgbanners; } } Compartilhar este post Link para o post Compartilhar em outros sites