Skip to content

Instantly share code, notes, and snippets.

@ruudud
Created April 9, 2013 12:41
Show Gist options
  • Save ruudud/5345393 to your computer and use it in GitHub Desktop.
Save ruudud/5345393 to your computer and use it in GitHub Desktop.
javax Servlet 3, Tomcat 7, JSP with JSTL
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%-- This file placed in the WebContent folder --%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Books</title>
</head>
<body>
<ul>
<c:forEach varStatus="loop" var="book" items="${books}">
<li>Index: ${loop.index}, Bok: ${book}</li>
</c:forEach>
</ul>
</body>
</html>
package editio;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet(value="/books", name="listbooks-servlet")
public class ListBooksServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String[] books = { "Bambi", "Donald Duck" };
request.setAttribute("books", books);
request.getRequestDispatcher("/books.jsp").forward(request, response);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment