BAEL-325: Refactored to use multi-module structure.
This commit is contained in:
parent
2d678d6b32
commit
4576a1e3ae
|
@ -0,0 +1,45 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>front-controller</artifactId>
|
||||
<packaging>war</packaging>
|
||||
|
||||
<parent>
|
||||
<artifactId>patterns-parent</artifactId>
|
||||
<groupId>com.baeldung.patterns</groupId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<relativePath>..</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>javax.servlet-api</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-war-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-maven-plugin</artifactId>
|
||||
<configuration>
|
||||
<webApp>
|
||||
<contextPath>/front-controller</contextPath>
|
||||
</webApp>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
|
@ -0,0 +1,38 @@
|
|||
package com.baeldung.patterns.front.controller;
|
||||
|
||||
import com.baeldung.patterns.front.controller.commands.FrontCommand;
|
||||
import com.baeldung.patterns.front.controller.commands.UnknownCommand;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
|
||||
public class FrontControllerServlet extends HttpServlet {
|
||||
@Override
|
||||
protected void doGet(
|
||||
HttpServletRequest request,
|
||||
HttpServletResponse response
|
||||
) throws ServletException, IOException {
|
||||
FrontCommand command = getCommand(request);
|
||||
command.init(getServletContext(), request, response);
|
||||
command.process();
|
||||
}
|
||||
|
||||
private FrontCommand getCommand(HttpServletRequest request) {
|
||||
try {
|
||||
Class type = Class.forName(
|
||||
String.format(
|
||||
"com.baeldung.patterns.front.controller.commands.%sCommand",
|
||||
request.getParameter("command")
|
||||
)
|
||||
);
|
||||
return (FrontCommand) type
|
||||
.asSubclass(FrontCommand.class)
|
||||
.newInstance();
|
||||
} catch (Exception e) {
|
||||
return new UnknownCommand();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
package com.baeldung.patterns.front.controller.commands;
|
||||
|
||||
import javax.servlet.RequestDispatcher;
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
|
||||
public abstract class FrontCommand {
|
||||
protected ServletContext context;
|
||||
protected HttpServletRequest request;
|
||||
protected HttpServletResponse response;
|
||||
|
||||
public void init(
|
||||
ServletContext servletContext,
|
||||
HttpServletRequest servletRequest,
|
||||
HttpServletResponse servletResponse
|
||||
) {
|
||||
this.context = servletContext;
|
||||
this.request = servletRequest;
|
||||
this.response = servletResponse;
|
||||
}
|
||||
|
||||
public abstract void process() throws ServletException, IOException;
|
||||
|
||||
protected void forward(String target) throws ServletException, IOException {
|
||||
target = String.format("/WEB-INF/jsp/%s.jsp", target);
|
||||
RequestDispatcher dispatcher = context.getRequestDispatcher(target);
|
||||
dispatcher.forward(request, response);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
package com.baeldung.patterns.front.controller.commands;
|
||||
|
||||
import com.baeldung.patterns.front.controller.data.Book;
|
||||
import com.baeldung.patterns.front.controller.data.BookshelfImpl;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import java.io.IOException;
|
||||
|
||||
public class SearchCommand extends FrontCommand {
|
||||
@Override
|
||||
public void process() throws ServletException, IOException {
|
||||
Book book = new BookshelfImpl().getInstance()
|
||||
.findByTitle(request.getParameter("title"));
|
||||
if (book != null) {
|
||||
request.setAttribute("book", book);
|
||||
forward("book-found");
|
||||
} else {
|
||||
forward("book-notfound");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
package com.baeldung.patterns.front.controller.commands;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import java.io.IOException;
|
||||
|
||||
public class UnknownCommand extends FrontCommand {
|
||||
@Override
|
||||
public void process() throws ServletException, IOException {
|
||||
forward("unknown");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package com.baeldung.patterns.front.controller.data;
|
||||
|
||||
public interface Book {
|
||||
String getAuthor();
|
||||
|
||||
void setAuthor(String author);
|
||||
|
||||
String getTitle();
|
||||
|
||||
void setTitle(String title);
|
||||
|
||||
Double getPrice();
|
||||
|
||||
void setPrice(Double price);
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
package com.baeldung.patterns.front.controller.data;
|
||||
|
||||
public class BookImpl implements Book {
|
||||
private String author;
|
||||
private String title;
|
||||
private Double price;
|
||||
|
||||
public BookImpl() {
|
||||
}
|
||||
|
||||
public BookImpl(String author, String title, Double price) {
|
||||
this.author = author;
|
||||
this.title = title;
|
||||
this.price = price;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAuthor() {
|
||||
return author;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAuthor(String author) {
|
||||
this.author = author;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Double getPrice() {
|
||||
return price;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPrice(Double price) {
|
||||
this.price = price;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package com.baeldung.patterns.front.controller.data;
|
||||
|
||||
public interface Bookshelf {
|
||||
|
||||
default void init() {
|
||||
add(new BookImpl("Wilson, Robert Anton & Shea, Robert", "Illuminati", 9.99));
|
||||
add(new BookImpl("Fowler, Martin", "Patterns of Enterprise Application Architecture", 27.88));
|
||||
}
|
||||
|
||||
Bookshelf getInstance();
|
||||
|
||||
<E extends Book> boolean add(E book);
|
||||
|
||||
Book findByTitle(String title);
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package com.baeldung.patterns.front.controller.data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class BookshelfImpl extends ArrayList<Book> implements Bookshelf {
|
||||
private static Bookshelf INSTANCE;
|
||||
|
||||
@Override
|
||||
public Bookshelf getInstance() {
|
||||
if (INSTANCE == null) {
|
||||
INSTANCE = new BookshelfImpl();
|
||||
INSTANCE.init();
|
||||
}
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Book findByTitle(String title) {
|
||||
return this.stream()
|
||||
.filter(book -> book.getTitle().toLowerCase().contains(title.toLowerCase()))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
}
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 9.3 KiB |
|
@ -0,0 +1,22 @@
|
|||
@startuml
|
||||
|
||||
class Handler {
|
||||
doGet
|
||||
doPost
|
||||
}
|
||||
|
||||
abstract class AbstractCommand {
|
||||
process
|
||||
}
|
||||
class ConcreteCommand1 {
|
||||
process
|
||||
}
|
||||
class ConcreteCommand2 {
|
||||
process
|
||||
}
|
||||
|
||||
Handler .right.> AbstractCommand
|
||||
AbstractCommand <|-- ConcreteCommand1
|
||||
AbstractCommand <|-- ConcreteCommand2
|
||||
|
||||
@enduml
|
|
@ -0,0 +1,12 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Bookshelf: Title found</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Our Bookshelf contains this title:</p>
|
||||
<h2>${book.getTitle()}</h2>
|
||||
<p>Author: ${book.getAuthor()}</p>
|
||||
<input type="submit" value="Buy it: ${book.getPrice()}$">
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,10 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Bookshelf: Title not found</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Our Bookshelf doesn't contains this title:</p>
|
||||
<h2>${param.get("title")}</h2>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,9 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Bookshelf: Command unknown</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Sorry, this command is not known!</p>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,15 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
|
||||
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
|
||||
version="3.1">
|
||||
<servlet>
|
||||
<servlet-name>front-controller</servlet-name>
|
||||
<servlet-class>com.baeldung.patterns.front.controller.FrontControllerServlet</servlet-class>
|
||||
</servlet>
|
||||
<servlet-mapping>
|
||||
<servlet-name>front-controller</servlet-name>
|
||||
<url-pattern>/</url-pattern>
|
||||
</servlet-mapping>
|
||||
</web-app>
|
|
@ -1,9 +1,9 @@
|
|||
package com.baeldung.patterns;
|
||||
package com.baeldung.patterns.intercepting.filter;
|
||||
|
||||
import com.baeldung.patterns.commands.FrontCommand;
|
||||
import com.baeldung.patterns.commands.UnknownCommand;
|
||||
import com.baeldung.patterns.data.Bookshelf;
|
||||
import com.baeldung.patterns.data.BookshelfImpl;
|
||||
import com.baeldung.patterns.intercepting.filter.commands.FrontCommand;
|
||||
import com.baeldung.patterns.intercepting.filter.commands.UnknownCommand;
|
||||
import com.baeldung.patterns.intercepting.filter.data.Bookshelf;
|
||||
import com.baeldung.patterns.intercepting.filter.data.BookshelfImpl;
|
||||
|
||||
import javax.servlet.ServletConfig;
|
||||
import javax.servlet.ServletException;
|
||||
|
@ -13,7 +13,7 @@ import javax.servlet.http.HttpServletRequest;
|
|||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
|
||||
@WebServlet(name = "front-controller", urlPatterns = "/index")
|
||||
@WebServlet(name = "intercepting-filter", urlPatterns = "/")
|
||||
public class FrontControllerServlet extends HttpServlet {
|
||||
@Override
|
||||
public void init(ServletConfig config) throws ServletException {
|
||||
|
@ -52,7 +52,7 @@ public class FrontControllerServlet extends HttpServlet {
|
|||
try {
|
||||
Class type = Class.forName(
|
||||
String.format(
|
||||
"com.baeldung.patterns.commands.%sCommand",
|
||||
"com.baeldung.patterns.intercepting.filter.commands.%sCommand",
|
||||
request.getParameter("command")
|
||||
)
|
||||
);
|
|
@ -1,6 +1,6 @@
|
|||
package com.baeldung.patterns.commands;
|
||||
package com.baeldung.patterns.intercepting.filter.commands;
|
||||
|
||||
import com.baeldung.patterns.data.Order;
|
||||
import com.baeldung.patterns.intercepting.filter.data.Order;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
@ -13,7 +13,7 @@ public class CheckoutCommand extends FrontCommand {
|
|||
HttpSession session = request.getSession(false);
|
||||
if (request.getMethod().equals("POST")) {
|
||||
session.removeAttribute("order");
|
||||
response.sendRedirect("index?command=Home&message=Thank you for buying!");
|
||||
response.sendRedirect("/?command=Home&message=Thank you for buying!");
|
||||
} else {
|
||||
Order order = (Order) session.getAttribute("order");
|
||||
Double total = order.getItems().entrySet().stream()
|
|
@ -1,7 +1,7 @@
|
|||
package com.baeldung.patterns.commands;
|
||||
package com.baeldung.patterns.intercepting.filter.commands;
|
||||
|
||||
import com.baeldung.patterns.filters.FilterManager;
|
||||
import com.baeldung.patterns.filters.OnIntercept;
|
||||
import com.baeldung.patterns.intercepting.filter.filters.FilterManager;
|
||||
import com.baeldung.patterns.intercepting.filter.filters.OnIntercept;
|
||||
|
||||
import javax.servlet.RequestDispatcher;
|
||||
import javax.servlet.ServletException;
|
|
@ -1,6 +1,6 @@
|
|||
package com.baeldung.patterns.commands;
|
||||
package com.baeldung.patterns.intercepting.filter.commands;
|
||||
|
||||
import com.baeldung.patterns.data.Bookshelf;
|
||||
import com.baeldung.patterns.intercepting.filter.data.Bookshelf;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import java.io.IOException;
|
|
@ -1,4 +1,4 @@
|
|||
package com.baeldung.patterns.commands;
|
||||
package com.baeldung.patterns.intercepting.filter.commands;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpSession;
|
|
@ -1,4 +1,4 @@
|
|||
package com.baeldung.patterns.commands;
|
||||
package com.baeldung.patterns.intercepting.filter.commands;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
@ -11,6 +11,6 @@ public class LogoutCommand extends FrontCommand {
|
|||
HttpSession session = request.getSession(false);
|
||||
session.removeAttribute("username");
|
||||
session.removeAttribute("order");
|
||||
response.sendRedirect("index?command=Home");
|
||||
response.sendRedirect("/?command=Home");
|
||||
}
|
||||
}
|
|
@ -1,9 +1,9 @@
|
|||
package com.baeldung.patterns.commands;
|
||||
package com.baeldung.patterns.intercepting.filter.commands;
|
||||
|
||||
import com.baeldung.patterns.data.Book;
|
||||
import com.baeldung.patterns.data.Bookshelf;
|
||||
import com.baeldung.patterns.data.Order;
|
||||
import com.baeldung.patterns.data.OrderImpl;
|
||||
import com.baeldung.patterns.intercepting.filter.data.Book;
|
||||
import com.baeldung.patterns.intercepting.filter.data.Bookshelf;
|
||||
import com.baeldung.patterns.intercepting.filter.data.Order;
|
||||
import com.baeldung.patterns.intercepting.filter.data.OrderImpl;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
@ -27,7 +27,7 @@ public class OrderCommand extends FrontCommand {
|
|||
Book book = bookshelf.get(isbn);
|
||||
order.add(book, quantity);
|
||||
session.setAttribute("order", order);
|
||||
response.sendRedirect(String.format("index?command=Show&isbn=%s", isbn));
|
||||
response.sendRedirect(String.format("/?command=Show&isbn=%s", isbn));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
package com.baeldung.patterns.commands;
|
||||
package com.baeldung.patterns.intercepting.filter.commands;
|
||||
|
||||
import com.baeldung.patterns.data.Book;
|
||||
import com.baeldung.patterns.data.Bookshelf;
|
||||
import com.baeldung.patterns.intercepting.filter.data.Book;
|
||||
import com.baeldung.patterns.intercepting.filter.data.Bookshelf;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import java.io.IOException;
|
|
@ -1,7 +1,7 @@
|
|||
package com.baeldung.patterns.commands;
|
||||
package com.baeldung.patterns.intercepting.filter.commands;
|
||||
|
||||
import com.baeldung.patterns.data.Book;
|
||||
import com.baeldung.patterns.data.Bookshelf;
|
||||
import com.baeldung.patterns.intercepting.filter.data.Book;
|
||||
import com.baeldung.patterns.intercepting.filter.data.Bookshelf;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import java.io.IOException;
|
|
@ -1,4 +1,4 @@
|
|||
package com.baeldung.patterns.commands;
|
||||
package com.baeldung.patterns.intercepting.filter.commands;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import java.io.IOException;
|
|
@ -1,4 +1,4 @@
|
|||
package com.baeldung.patterns.data;
|
||||
package com.baeldung.patterns.intercepting.filter.data;
|
||||
|
||||
public interface Book {
|
||||
String getIsbn();
|
|
@ -1,4 +1,4 @@
|
|||
package com.baeldung.patterns.data;
|
||||
package com.baeldung.patterns.intercepting.filter.data;
|
||||
|
||||
public class BookImpl implements Book {
|
||||
private String isbn;
|
|
@ -1,4 +1,4 @@
|
|||
package com.baeldung.patterns.data;
|
||||
package com.baeldung.patterns.intercepting.filter.data;
|
||||
|
||||
import java.util.List;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package com.baeldung.patterns.data;
|
||||
package com.baeldung.patterns.intercepting.filter.data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
|
@ -1,4 +1,4 @@
|
|||
package com.baeldung.patterns.data;
|
||||
package com.baeldung.patterns.intercepting.filter.data;
|
||||
|
||||
import java.util.Map;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package com.baeldung.patterns.data;
|
||||
package com.baeldung.patterns.intercepting.filter.data;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
|
@ -1,7 +1,7 @@
|
|||
package com.baeldung.patterns.filters;
|
||||
package com.baeldung.patterns.intercepting.filter.filters;
|
||||
|
||||
import com.baeldung.patterns.commands.FrontCommand;
|
||||
import com.baeldung.patterns.commands.LoginCommand;
|
||||
import com.baeldung.patterns.intercepting.filter.commands.FrontCommand;
|
||||
import com.baeldung.patterns.intercepting.filter.commands.LoginCommand;
|
||||
|
||||
import javax.servlet.*;
|
||||
import javax.servlet.http.HttpServletRequest;
|
|
@ -1,4 +1,4 @@
|
|||
package com.baeldung.patterns.filters;
|
||||
package com.baeldung.patterns.intercepting.filter.filters;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
|
@ -1,4 +1,4 @@
|
|||
package com.baeldung.patterns.filters;
|
||||
package com.baeldung.patterns.intercepting.filter.filters;
|
||||
|
||||
import javax.servlet.*;
|
||||
import javax.servlet.annotation.WebFilter;
|
||||
|
@ -6,7 +6,7 @@ import javax.servlet.annotation.WebInitParam;
|
|||
import java.io.IOException;
|
||||
|
||||
@WebFilter(
|
||||
servletNames = {"front-controller"},
|
||||
servletNames = {"intercepting-filter"},
|
||||
initParams = {@WebInitParam(name = "encoding", value = "UTF-8")}
|
||||
)
|
||||
public class EncodingFilter extends BaseFilter {
|
|
@ -1,4 +1,4 @@
|
|||
package com.baeldung.patterns.filters;
|
||||
package com.baeldung.patterns.intercepting.filter.filters;
|
||||
|
||||
import javax.servlet.*;
|
||||
import java.io.IOException;
|
|
@ -1,4 +1,4 @@
|
|||
package com.baeldung.patterns.filters;
|
||||
package com.baeldung.patterns.intercepting.filter.filters;
|
||||
|
||||
import javax.servlet.FilterChain;
|
||||
import javax.servlet.ServletException;
|
|
@ -1,4 +1,4 @@
|
|||
package com.baeldung.patterns.filters;
|
||||
package com.baeldung.patterns.intercepting.filter.filters;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -11,7 +11,7 @@ import javax.servlet.annotation.WebFilter;
|
|||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.IOException;
|
||||
|
||||
@WebFilter(servletNames = "front-controller")
|
||||
@WebFilter(servletNames = "intercepting-filter")
|
||||
public class LoggingFilter extends BaseFilter {
|
||||
private static final Logger log = LoggerFactory.getLogger(LoggingFilter.class);
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
package com.baeldung.patterns.intercepting.filter.filters;
|
||||
|
||||
public interface OnIntercept {
|
||||
void intercept();
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package com.baeldung.patterns.filters;
|
||||
package com.baeldung.patterns.intercepting.filter.filters;
|
||||
|
||||
import javax.servlet.FilterChain;
|
||||
import javax.servlet.ServletException;
|
|
@ -1,4 +1,4 @@
|
|||
package com.baeldung.patterns.filters;
|
||||
package com.baeldung.patterns.intercepting.filter.filters;
|
||||
|
||||
import javax.servlet.*;
|
||||
import javax.servlet.http.HttpServletRequest;
|
Before Width: | Height: | Size: 5.2 KiB After Width: | Height: | Size: 5.2 KiB |
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 17 KiB |
|
@ -1,4 +1,4 @@
|
|||
<%@ page import="com.baeldung.patterns.data.Book" %>
|
||||
<%@ page import="com.baeldung.patterns.intercepting.filter.data.Book" %>
|
||||
<%@ page import="java.util.List" %>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
@ -10,12 +10,12 @@
|
|||
<% for (Book book : (List<Book>) request.getAttribute("books")) { %>
|
||||
<h2><%= book.getTitle() %></h2>
|
||||
<p>Author: <%= book.getAuthor() %></p>
|
||||
<form action="index?command=Order" method="POST">
|
||||
<form action="/?command=Order" method="POST">
|
||||
<label for="quantity">Quantity:</label>
|
||||
<input type="text" id="quantity" name="quantity" value="1" required>
|
||||
<input type="hidden" name="isbn" value="<%= book.getIsbn() %>">
|
||||
<input type="submit" value="Buy it: <%= book.getPrice() %>$">
|
||||
<a href="index?command=Home">Go back...</a>
|
||||
<a href="/?command=Home">Go back...</a>
|
||||
</form>
|
||||
<% } %>
|
||||
<%@ include file="shopping-cart-hint.jsp"%>
|
|
@ -1,4 +1,4 @@
|
|||
<%@ page import="com.baeldung.patterns.data.Book" %>
|
||||
<%@ page import="com.baeldung.patterns.intercepting.filter.data.Book" %>
|
||||
<%@ page import="java.util.List" %>
|
||||
<!DOCTYPE>
|
||||
<html>
|
||||
|
@ -6,7 +6,7 @@
|
|||
<title>Bookshelf: Home</title>
|
||||
</head>
|
||||
<body>
|
||||
<form action="index?command=Search" method="POST">
|
||||
<form action="/?command=Search" method="POST">
|
||||
<input type="text" id="search" name="q">
|
||||
<input type="submit" value="Go!">
|
||||
</form>
|
||||
|
@ -19,7 +19,7 @@
|
|||
<hr/>
|
||||
<p><b><%= book.getAuthor() %>:</b></p>
|
||||
<h3><%= book.getTitle() %></h3>
|
||||
<a href="index?command=Show&isbn=<%= book.getIsbn() %>">More...</a>
|
||||
<a href="/?command=Show&isbn=<%= book.getIsbn() %>">More...</a>
|
||||
<% } %>
|
||||
<%@ include file="shopping-cart-hint.jsp"%>
|
||||
<%@ include file="visitor-counter.jsp"%>
|
|
@ -6,7 +6,7 @@
|
|||
<body>
|
||||
<p>Please input a username:</p>
|
||||
<h2>Login</h2>
|
||||
<form action="index?command=Login" method="POST">
|
||||
<form action="/?command=Login" method="POST">
|
||||
<input type="text" name="username" placeholder="Username">
|
||||
<input type="hidden" name="redirect" value="<%= (String) request.getAttribute("redirect") %>">
|
||||
<input type="submit" value="Proceed">
|
|
@ -1,4 +1,4 @@
|
|||
<%@ page import="com.baeldung.patterns.data.Order" %>
|
||||
<%@ page import="com.baeldung.patterns.intercepting.filter.data.Order" %>
|
||||
<% if (session != null && session.getAttribute("order") != null) { %>
|
||||
<% Order order = ((Order) session.getAttribute("order")); %>
|
||||
<% if (order != null && order.getItems().size() > 0) { %>
|
||||
|
@ -10,7 +10,7 @@
|
|||
<% } else { %>
|
||||
<%= (order.getItems().size()) %> items.
|
||||
<% } %>
|
||||
<a href="index?command=Checkout">Checkout</a>
|
||||
<a href="/?command=Checkout">Checkout</a>
|
||||
</p>
|
||||
<% } %>
|
||||
<% } %>
|
|
@ -1,5 +1,5 @@
|
|||
<%@ page import="com.baeldung.patterns.data.Book" %>
|
||||
<%@ page import="com.baeldung.patterns.data.Order" %>
|
||||
<%@ page import="com.baeldung.patterns.intercepting.filter.data.Book" %>
|
||||
<%@ page import="com.baeldung.patterns.intercepting.filter.data.Order" %>
|
||||
<%@ page import="java.util.Map" %>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
@ -22,7 +22,7 @@
|
|||
<p>
|
||||
<b>Total: <%= request.getAttribute("total") %></b>
|
||||
</p>
|
||||
<form action="index?command=Checkout" method="POST">
|
||||
<form action="/?command=Checkout" method="POST">
|
||||
<input type="submit" value="Donate :)">
|
||||
</form>
|
||||
</body>
|
|
@ -0,0 +1,9 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Bookshelf: Command unknown</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Sorry, this command is not known!</p>
|
||||
</body>
|
||||
</html>
|
|
@ -1,5 +1,5 @@
|
|||
<% Integer counter = (Integer) request.getAttribute("counter"); %>
|
||||
<% if (counter != null && counter > 0) { %>
|
||||
<hr/>
|
||||
<p>You are visitor #<%= counter %>. <a href="index?command=Logout">Logout</a></p>
|
||||
<p>You are visitor #<%= counter %>. <a href="/?command=Logout">Logout</a></p>
|
||||
<% } %>
|
|
@ -4,60 +4,55 @@
|
|||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.baeldung.patterns</groupId>
|
||||
<artifactId>patterns-parent</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<modules>
|
||||
<module>front-controller</module>
|
||||
<module>intercepting-filter</module>
|
||||
</modules>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-modules</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<relativePath>..</relativePath>
|
||||
</parent>
|
||||
|
||||
<groupId>com.baeldung.patterns</groupId>
|
||||
<artifactId>patterns</artifactId>
|
||||
<packaging>war</packaging>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>javax.servlet-api</artifactId>
|
||||
<version>3.1.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<version>1.7.21</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>javax.servlet-api</artifactId>
|
||||
<version>3.1.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.5.1</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-war-plugin</artifactId>
|
||||
<version>3.0.0</version>
|
||||
<configuration>
|
||||
<failOnMissingWebXml>false</failOnMissingWebXml>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-maven-plugin</artifactId>
|
||||
<version>9.3.11.v20160721</version>
|
||||
<configuration>
|
||||
<webApp>
|
||||
<contextPath>/</contextPath>
|
||||
</webApp>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
<pluginManagement>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.5.1</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-war-plugin</artifactId>
|
||||
<version>3.0.0</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-maven-plugin</artifactId>
|
||||
<version>9.3.12.v20160915</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
</build>
|
||||
</project>
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
package com.baeldung.patterns.filters;
|
||||
|
||||
public interface OnIntercept {
|
||||
void intercept();
|
||||
}
|
Loading…
Reference in New Issue