Book Image

Spring MVC Beginner's Guide

By : Amuthan Ganeshan
Book Image

Spring MVC Beginner's Guide

By: Amuthan Ganeshan

Overview of this book

Table of Contents (19 chapters)
Spring MVC Beginner's Guide
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Time for action – adding the product details page


So far in our product listing page, we have only shown product information such as the product's name, description, price, and available units in stock. However, we haven't shown information such as the manufacturer's name, category, product ID, and so on. Let's create a product details page displaying this information as follows:

  1. Open the ProductController class and add one more request mapping method as follows:

    @RequestMapping("/product")
    public String getProductById(@RequestParam("id") String productId, Model model) {
      model.addAttribute("product", productService.getProductById(productId));
      return "product";
    }
  2. Add one more JSP view file called product.jsp under the directory src/main/webapp/WEB-INF/views/, and add the following code snippet into it and save it:

    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
    
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    ...