Created
January 30, 2012 19:29
-
-
Save Promichel/1706157 to your computer and use it in GitHub Desktop.
So gehts bei mir
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 de.promichel.beans; | |
/** | |
* Created by Patrick Trautmann | |
* <p/> | |
* Contact: patrick.trautmann@gmail.com | |
* Date: 30.01.12 | |
* Time: 20:09 | |
*/ | |
public class Book { | |
private String author; | |
private String title; | |
public Book() { | |
} | |
public Book(String author, String title) { | |
this.author = author; | |
this.title = title; | |
} | |
public String getAuthor() { | |
return author; | |
} | |
public void setAuthor(String author) { | |
this.author = author; | |
} | |
public String getTitle() { | |
return title; | |
} | |
public void setTitle(String title) { | |
this.title = title; | |
} | |
} |
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/jstl/core_rt" %> | |
<%-- | |
Created by IntelliJ IDEA. | |
User: Promichel | |
Date: 30.01.12 | |
Time: 20:10 | |
To change this template use File | Settings | File Templates. | |
--%> | |
<%@ page contentType="text/html;charset=UTF-8" language="java" %> | |
<form method="POST" id="form" action="/books"> | |
<fieldset> | |
<legend>Search Books from author '${sessionScope.author}'</legend> | |
<div class="clearfix"> | |
<label for="author">Author</label> | |
<div class="input"> | |
<input type="text" id="author" name="author" class="xlarge" value="${sessionScope.author}" /> | |
</div> | |
</div> | |
<div class="actions"> | |
<input type="submit" class="btn primary" value="Search" name="submit" /> | |
</div> | |
</fieldset> | |
</form> | |
<div class="clearfix"> | |
<div class="page-header"> | |
<h3>Found books</h3> | |
</div> | |
<table class="bordered-table zebra-striped"> | |
<thead> <tr> <th></th> | |
<th>ID</th> | |
<th>Author</th> | |
<th>Title</th> | |
</tr> | |
</thead> | |
<c:forEach var="a" items="${sessionScope.books}" > | |
<tr> | |
<td>${a.author} </td> | |
<td>${a.title} </td> | |
</tr> | |
</c:forEach> | |
</table> | |
</div> | |
<div class="alert-message"> | |
Type in Book id or author's name. SESSION (${pageContext.session.id}) <br /> | |
${sessionScope.err_msg} | |
${sessionScope.books} | |
</div> |
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 de.promichel.servlet; | |
import de.promichel.beans.Book; | |
import javax.servlet.ServletException; | |
import javax.servlet.http.HttpServlet; | |
import javax.servlet.http.HttpServletRequest; | |
import javax.servlet.http.HttpServletResponse; | |
import javax.servlet.http.HttpSession; | |
import java.io.IOException; | |
import java.util.ArrayList; | |
import java.util.List; | |
/** | |
* Created by Patrick Trautmann | |
* <p/> | |
* Contact: patrick.trautmann@gmail.com | |
* Date: 30.01.12 | |
* Time: 20:08 | |
*/ | |
public class SearchBookServlet extends HttpServlet { | |
private List<Book> books; | |
private String author; | |
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { | |
HttpSession session = request.getSession(true); | |
author = request.getParameter("author"); | |
session.setAttribute("author", author); | |
//Dummy List impl | |
books = new ArrayList<Book>(5); | |
for(int i = 0; i <= 5; i++) { | |
System.out.println("Create Dummy Book Object"); | |
books.add(new Book(author, author + " " + i)); | |
} | |
System.out.println("Push ArrayList to Session Scope"); | |
session.setAttribute("books", books); | |
} | |
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { | |
} | |
} |
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
<?xml version="1.0" encoding="UTF-8"?> | |
<web-app | |
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" | |
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd | |
http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" | |
id="WebApp_ID" version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" | |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | |
<display-name>Archetype Created Web Application</display-name> | |
<servlet> | |
<servlet-name>SearchBookServlet</servlet-name> | |
<servlet-class>de.promichel.servlet.SearchBookServlet</servlet-class> | |
</servlet> | |
<servlet-mapping> | |
<servlet-name>SearchBookServlet</servlet-name> | |
<url-pattern>/books</url-pattern> | |
</servlet-mapping> | |
</web-app> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment