Solucionado (ver solução)

Importante

Você está vendo a versão anterior da nova experiência da Alura que estamos preparando para você. Em breve, ela ganha uma identidade visual novinha totalmente pensada em potencializar seus estudos!

Solucionado
(ver solução)
12
respostas

detalhe

dentro de todas as paginas, quando clik no menu home do cabeçalho, eu consigo ser direcionado corretamente para a home, menos dentro da pagina detalhe, que me encaminha para o link

http://localhost:8080/casadocodigo/WEB-INF/views/produtos/detalhe.jsp

como corrijo isso?

12 respostas

Oi Giulia,

Estranho isso :D

Poste aqui o código da sua página de detalhes e também do cabecalho.jsp e do template.tag.

Pagina detalhe

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ taglib uri="http://www.springframework.org/tags" prefix="s"%>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@ taglib tagdir="/WEB-INF/tags" prefix="tags" %>

<tags:pageTemplate titulo="${produto.titulo}">


<article id="${produto.id}">
        <header id="product-highlight" class="clearfix">
            <div id="product-overview" class="container">
                <img width="280px" height="395px" src="http://cdn.shopify.com/s/files/1/0155/7645/products/css-eficiente-featured_large.png?v=1435245145"
                    class="product-featured-image" />
                <h1 class="product-title">${produto.titulo}</h1>
                <p class="product-author">
                    <span class="product-author-link"> </span>
                </p>
                <p class="book-description">${produto.descricao}</p>
            </div>
        </header>

        <section class="buy-options clearfix">
            <form:form servletRelativeAction="/carrinho/add" method="post" cssClass="container">
                <input type="hidden" value="${produto.id}" name="produtoId">
                    <ul id="variants" class="clearfix">

                        <c:forEach items="${produto.precos}" var="preco">
                            <li class="buy-option">
                                <input type="radio" name="tipoPreco" class="variant-radio" 
                                    id="tipo" value="${preco.tipo}" checked="checked" /> 
                                <label class="variant-label">${preco.tipo}</label> 
                                <small class="compare-at-price">${preco.valor + 10}</small>
                                <p class="variant-price">${preco.valor}</p>
                            </li>
                        </c:forEach>

                    </ul>
                <button type="submit" class="submit-image icon-basket-alt" title="${produto.titulo}"></button>
            </form:form>
        </section>

        <div class="container">
            <section class="summary">
                <ul>
                    <li>
                        <h3>E muito mais... <a href='/pages/sumario-java8'>veja o sumário</a>.</h3>
                    </li>
                </ul>
            </section>

            <section class="data product-detail">
                <h2 class="section-title">Dados do livro:</h2>
                <p>
                    Número de páginas: <span>${produto.paginas}</span>
                </p>
                <p>Data de publicação: <span class="publishedAt">
                <fmt:formatDate pattern="dd/MM/yyyy" value="${produto.dataLancamento.time}"/></p>
                <p>
                    Encontrou um erro? <a href='/submissao-errata' target='_blank'>Submeta uma errata</a>
                </p>
            </section>
        </div>
    </article>
</tags:pageTemplate>

Cabeçalho

<%@ taglib uri="http://www.springframework.org/tags" prefix="s"%>
    <header id="layout-header">
        <div class="clearfix container">
            <a href="${s:mvcUrl('HC#index').build()}" id="logo"> </a>
            <div id="header-content">
                <nav id="main-nav">

                    <ul class="clearfix">
                        <li><a href="${s:mvcUrl('CCC#itens').build()}" rel="nofollow">Carrinho
                        (${carrinhoCompras.quantidade})</a></li>
                        <li><a href="/pages/sobre-a-casa-do-codigo" rel="nofollow">Sobre Nós</a></li>
                        <li><a href="/pages/perguntas-frequentes" rel="nofollow">Perguntas Frequentes</a></li>
                    </ul>
                </nav>
            </div>
        </div>
    </header>
    <nav class="categories-nav">
        <ul class="container">
            <li class="category"><a href="${s:mvcUrl('HC#index').build()}">Home</a></li>
            <li class="category"><a href="/collections/livros-de-agile"> Agile </a></li>
            <li class="category"><a href="/collections/livros-de-front-end"> Front End </a></li>
            <li class="category"><a href="/collections/livros-de-games"> Games </a></li>
            <li class="category"><a href="/collections/livros-de-java"> Java </a></li>
            <li class="category"><a href="/collections/livros-de-mobile"> Mobile </a></li>
            <li class="category"><a href="/collections/livros-desenvolvimento-web"> Web </a></li>
            <li class="category"><a href="/collections/outros"> Outros </a></li>
        </ul>
    </nav>

Template

<%@ tag language="java" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

<%@ attribute name="titulo" required="true" %>
<%@ attribute name="bodyClass" required="false" %>
<%@ attribute name="extraScripts" fragment="true" %>

<c:url value="/" var="contextPath" />

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <meta http-equiv="X-UA-Compatible" 
            content="IE=edge,chrome=1" />
        <meta name="viewport" content="width=device-width, 
            initial-scale=1, maximum-scale=1" />
        <link rel="icon" 
            href="//cdn.shopify.com/s/files/1/0155/7645/t/177/assets/favicon.ico?11981592617154272979" 
                type="image/ico" />
        <link href="https://plus.googlecom/108540024862647200608" 
            rel="publisher" />
        <title>${titulo } - Casa do Código</title>
        <link href="${contextPath}resources/css/cssbase-min.css" 
            rel="stylesheet" type="text/css" media="all" />
        <link href='http://fonts.googleapis.com/css?family=Droid+Sans:400,700' 
            rel='stylesheet' />
        <link href="${contextPath}resources/css/fonts.css" rel="stylesheet" 
            type="text/css" media="all" />
        <link href="${contextPath}resources/css/fontello-ie7.css" 
            rel="stylesheet" type="text/css" media="all" />
        <link href="${contextPath}resources/css/fontello-embedded.css" 
            rel="stylesheet" type="text/css" media="all" />
        <link href="${contextPath}resources/css/fontello.css" 
            rel="stylesheet" type="text/css" media="all" />
        <link href="${contextPath}resources/css/style.css" 
            rel="stylesheet" type="text/css" media="all" />
        <link href="${contextPath}resources/css/layout-colors.css" 
            rel="stylesheet" type="text/css" media="all" />
        <link href="${contextPath}resources/css/responsive-style.css" 
            rel="stylesheet" type="text/css" media="all" />
        <link href="${contextPath}resources/css/guia-do-programador-style.css" 
            rel="stylesheet" type="text/css" media="all" />
        <link href="${contextPath}resources/css/produtos.css" 
            rel="stylesheet" type="text/css" media="all" />
        <link rel="canonical" href="http://www.casadocodigo.com.br/" />
        <link href="${contextPath}resources/css/book-collection.css" 
            rel="stylesheet" type="text/css" media="all" />
    </head>

    <body class="${bodyClass}">

    <%@ include file="/WEB-INF/views/cabecalho.jsp" %>

    <jsp:doBody />

    <jsp:invoke fragment="extraScripts"></jsp:invoke>

    <%@ include file="/WEB-INF/views/rodape.jsp" %>

    </body>
</html>

Pois é, aparentemente não tem erro no link:

<a href="${s:mvcUrl('HC#index').build()}">Home</a>

Manda exibir o código fonte no navegador, na página de detalhes, e veja como que está sendo gerado o href desse link.

No código Fonte o link e gerado conforme citado acima no erro. E o interessante e que so e gerado assim na pagina detalhes. Nas demais funciona corretamente

Isso de somente acontecer na página de detalhes que está estranho, pois o cabecalho está sendo importado no template.

Provavelmente o problema é algo específico da página de detalhes.

Faz o seguinte, apague todo o conteudo da página de detalhes, e veja se o link funciona corretamente:

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ taglib uri="http://www.springframework.org/tags" prefix="s"%>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@ taglib tagdir="/WEB-INF/tags" prefix="tags" %>

<tags:pageTemplate titulo="${produto.titulo}">
</tags:pageTemplate>

coloquei o codigo abaixo

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ taglib uri="http://www.springframework.org/tags" prefix="s"%>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@ taglib tagdir="/WEB-INF/tags" prefix="tags" %>

<tags:pageTemplate titulo="${produto.titulo}">
<a href="${s:mvcUrl('HC#index').build()}">Home</a>
</tags:pageTemplate>

e fui encaminhado para

http://localhost:8080/casadocodigo/WEB-INF/views/produtos/detalhe.jsp

Bom, a última coisa a analisar seria o Controller...

Por desencargo, poste aqui o código do seu HomeController.

eu importei o projeto de exemplo e deu mesmo erro, segue o link do meu projeto inteiro. tb segue HomeController

https://mega.nz/#!qJRDiITI!PFoTejm2BnERkYM5Nk7beFl_tcRH0pNZQp7lGCsH1M4

package br.com.casadocodigo.loja.controllers;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import br.com.casadocodigo.loja.daos.ProdutoDAO;
import br.com.casadocodigo.loja.models.Produto;

@Controller
public class HomeController {

    @Autowired
    private ProdutoDAO produtoDao;

    @RequestMapping("/")
    @Cacheable(value="produtosHome")
    public ModelAndView index() {
        List<Produto> listar = produtoDao.listar();
        ModelAndView modelAndView = new ModelAndView("home");
        modelAndView.addObject("produtos", listar);

        return modelAndView;
    }
}

Oi Giulia,

Testei aqui o projeto que você mandou e pra mim o link funcionou normalmente em todas as páginas, inclusive na de detalhes: https://ibb.co/cAhjzd

Chutaria então que é cache do browser ou algum bug no eclipse.

Teste em outro browser e crie um novo workspace no eclipse e importe o projeto novamente...

Esse é um daqueles errinhos bizarros que não fazem o menor sentido :D

solução!

o erro acontecia no controller,

o metodo com a / antes de alunos dava erro, eu tirei barra e funcionou.

ModelAndView modelAndView = new ModelAndView("/alunos/alunos");

ficou assim

ModelAndView modelAndView = new ModelAndView("alunos/alunos");