businessListWeb.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ page import="java.util.List, com.manager.servlet.Company"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Java Standard Taglib</title>
</head>
<body>
Lista de empresas: <br />
<ul>
<c:forEach items ="${companies}" var ="company"/>
<li>${company.name}</li>
</ul>
</body>
</html>
BusinessListServlet.java
package com.manager.servlet;
import java.io.IOException;
import java.util.List;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class BusinessListServlet
*/
@WebServlet("/BusinessList")
public class BusinessListServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#service(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
DataBaseCompany dbc = new DataBaseCompany();
List<Company> listC = dbc.getCompanies();
request.setAttribute("companies", listC);
RequestDispatcher rd = request.getRequestDispatcher("/businessListWeb.jsp");
rd.forward(request, response);
}
}
Company.java
package com.manager.servlet;
import java.util.Date;
public class Company {
private int id;
private String name;
private Date openDate = new Date();
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Date getOpenDate() {
return openDate;
}
public void setOpenDate(Date openDate) {
this.openDate = openDate;
}
}
DataBaseCompany.java
package com.manager.servlet;
import java.util.ArrayList;
import java.util.List;
public class DataBaseCompany {
private static List<Company> listDB = new ArrayList<>();
public void addCompany(Company c) {
DataBaseCompany.listDB.add(c);
}
public List<Company> getCompanies(){
return DataBaseCompany.listDB;
}
}
Antes da utilização do jstl o programa cadastrada a empresa cadastrada. Agora a página não declara erro, mas no local onde deveria listar, não aparece o nome da empresa. Gostaria de saber o que posso fazer para solucionar esse problema.
Grato.