I can not access a form page

3

I'm doing a Spring Alura course, but I can not access a form page via the link link. It gives the following error:

  

HTTP Status 404 - Not Found   Type Status Report

     

Message /casadocode/products/WEB-INF/views/products/form.jsp

     

Description The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.

     

Apache Tomcat / 9.0.5

I think it's the wrong way. I guess I should not have this /produtos between the project name and /WEB-INF . Is that the problem? Why is it adding this /produtos ?

Follow the controller source and configuration class below:

Class ProductsController:

package br.com.casadocodigo.loja.controllers;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

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

@Controller
public class ProdutosController {

    @Autowired
    private ProdutoDAO produtoDao;

    @RequestMapping("/produtos")
    public String gravar(Produto produto) {
        System.out.println(produto);
        this.produtoDao.gravar(produto);
        return "produtos/ok";
    }

    @RequestMapping("/produtos/form")
    public String form() {
        System.out.println("Entrando em método FORM");
        return "produtos/form";
    }

}

AppWebConfiguration class:

package br.com.casadocodigo.loja.conf;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.view.InternalResourceViewResolver;

import br.com.casadocodigo.loja.controllers.HomeController;
import br.com.casadocodigo.loja.daos.ProdutoDAO;

@EnableWebMvc
@ComponentScan(basePackageClasses={HomeController.class, ProdutoDAO.class})
public class AppWebConfiguration {

    @Bean
    public InternalResourceViewResolver internalResourceViewResolver() {
        InternalResourceViewResolver resolver = new InternalResourceViewResolver();
        resolver.setPrefix("WEB-INF/views/");
        resolver.setSuffix(".jsp");
        return resolver;
    }
}
    
asked by anonymous 20.06.2018 / 19:22

1 answer

1

Spring is prepared to handle urls with multiple "/" . Modify this line:

resolver.setPrefix("WEB-INF/views/");

for

resolver.setPrefix("/WEB-INF/views/");

    
20.07.2018 / 20:35