Created
April 9, 2013 12:41
-
-
Save ruudud/5345393 to your computer and use it in GitHub Desktop.
javax Servlet 3, Tomcat 7, JSP with JSTL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%@ 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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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