Issue
I try to add image to the product detail JSP page. Here is the table structure of table:
CREATE TABLE PRODUCTS (
ID VARCHAR(25) PRIMARY KEY,
NAME VARCHAR(50),
DESCRIPTION VARCHAR(250),
UNIT_PRICE DECIMAL,
MANUFACTURER VARCHAR(50),
CATEGORY VARCHAR(50),
CONDITION VARCHAR(50),
UNITS_IN_STOCK BIGINT,
UNITS_IN_ORDER BIGINT,
DISCONTINUED BOOLEAN
);
Here are the products in my database:
INSERT INTO PRODUCTS VALUES ('P1234', 'iPhone 6s', 'Apple iPhone 6s smartphone with 4.00-inch 640x1136 display and 8-megapixel rear camera','500','Apple','Smartphone','New',450,0,false);
INSERT INTO PRODUCTS VALUES ('P1235', 'Dell Inspiron', 'Dell Inspiron 14-inch Laptop (Black) with 3rd Generation Intel Core processors',700,'Dell','Laptop','New',1000,0,false);
INSERT INTO PRODUCTS VALUES ('P1236', 'Nexus 7', 'Google Nexus 7 is the lightest 7 inch tablet With a quad-core Qualcomm Snapdragon™ S4 Pro processor', 300,'Google','Tablet','New',1000,0,false);
Here is the content of the Product controller:
// sayfa 103'te eklendi
@RequestMapping("/product")
public ModelAndView getProductById(@RequestParam("id") String productId, Model model) {
ModelAndView netice = new ModelAndView("product");
netice.addObject("product", productService.getProductById(productId));
System.out.println("109");
// model.addAttribute("product",productService.getProductById(productId));
return netice;
}
@RequestMapping("/product2")
public String getProduct2ById(@RequestParam("id") String productId, Model model) {
System.out.println("117");
Product product = productService.getProductById(productId);
model.addAttribute("product", product);
return "product2";
}
Here is the content of the product.jsp in which related with the working example:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet"
href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css">
<title>Products</title>
</head>
<body>
<section>
<div class="jumbotron">
<div class="container">
<h1>Products</h1>
</div>
</div>
</section>
<section class="container">
<div class="row">
<div class="col-md-5">
<!-- The point that prints photo to the user -->
<img src="<c:url value="/img/${product.productId}.png"> </c:url>" alt="image" style = "width:100%"/>
<h3>${product.name}</h3>
<p>${product.description}</p>
<p>
<strong>Item Code : </strong><span class="label label warning">${product.productId}
</span>
</p>
<p>
<strong>manufacturer</strong> : ${product.manufacturer}
</p>
<p>
<strong>category</strong> : ${product.category}
</p>
<p>
<strong>Available units in stock </strong> : ${product.unitsInStock}
</p>
<h4>${product.unitPrice}USD</h4>
<p>
<a href="<spring:url value="/listproducts" />"
class="btn btn-default"> <span
class="glyphicon-hand-left glyphicon"></span> back
</a> <a href="#" class="btn btn-warning btn-large"> <span
class="glyphicon-shopping-cart glyphicon"> </span> Order Now
</a>
</p>
</div>
</div>
</section>
</body>
</html>
Here is the content of the product2.jsp in which related with the erroneous example:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet"
href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css">
<title>Products</title>
</head>
<body>
<section>
<div class="jumbotron">
<div class="container">
<h1>Products</h1>
</div>
</div>
</section>
<section class="container">
<div class="row">
<div class="col-md-5">
<!-- The point that prints photo to the user -->
<img src="<c:url value="/img/${product.productId}.png"> </c:url>" alt="image" style = "width:100%"/>
<h3>${product.name}</h3>
<p>${product.description}</p>
<p>
<strong>Item Code : </strong>
<span class="label label warning">${product.productId} </span>
</p>
<p>
<strong>manufacturer</strong> : ${product.manufacturer}
</p>
<p>
<strong>category</strong> : ${product.category}
</p>
<p>
<strong>Available units in stock </strong> :
${product.unitsInStock}
</p>
<p>
<a
href=" <spring:url value="/product2?id=${product.productId}" /> "
class="btn btn-primary"> <span
class="glyphicon-info-sign glyphicon" />
</span> Details
</a>
</p>
<a href="<spring:url value="product" />" class="btn btn-default"> <span class="glyphicon-hand-left glyphicon"></span> back
</a>
</div>
</div>
</section>
</body>
</html>
I am getting the error below at product2.jsp :
org.springframework.web.servlet.DispatcherServlet noHandlerFound WARNING: No mapping for GET /springmvc197/%3Cc:url%20value=
What do I wrong? Thanks in advance.
Update-1
the product2.jsp in which related with the erroneous example lacks the <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> directive. In the comment below, Mr allkenang intuitively find the solution. The original post has not contained the directives in the jsp file.
Just a thought, may not be the issue.. Can you please double check your tag library (c:) import on your product2.jsp page? Because the error states "/springmvc197/<c:url value=", it is not able to understand c:
Solution
Looks to me that you have a typo in your url. It should read:
<spring:url value="/product2?id=${product.productId}" />
instead of
<spring:url value="/product?id=${product.productId}" />
Answered By - allkenang
Answer Checked By - Senaida (JavaFixing Volunteer)