A
A
Anton Vasilyuk2018-11-21 20:56:12
Java
Anton Vasilyuk, 2018-11-21 20:56:12

Why Servlet on IntelliJ IDEA doesn't work correctly?

Greetings. The problem is this. I'm on Mac OS. In general, I put the tomcat into the idea, I put it normally, it works with the simplest projector. But as I connect a larger educational project, miracles begin. Then it doesn't work doesn't work... "The origin server did not find a current representation for the target resource or is not willing to disclose that one exists." Dependencies in web.xml are correctly spelled out. Yes, he must find something. By the way, I put it in web.app index.html and I can’t contact it in a brazen server either. What is it ... And the simplest project, such as taking a writer from the response and drowning out hello world there, normally outputs it. What could be?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Orkhan, 2018-11-21
Hasanly @azerphoenix

Hello!
I'm learning spring myself and working in intellij idea
https://stackoverflow.com/questions/43186315/tomca...
It's basically just a 404 error (it didn't find your index.html).
Pay attention to the following points -
1) you are running tomcat externally, not embedded. For example, when I need to deploy to a server, I need to pay attention to: prefix & suffix, as well as contextPath.
It is possible that you are opening the page localhost:8080, but you need to open it, for example, localhost:8080/${contextPath}
For example, prefix and suffix to prescribe:

resolver.setPrefix("resources/templates/");
resolver.setSuffix(".html");

Here is an example of my code:
@Configuration
@EnableWebMvc
@Profile("production")
public class WebMvcConfig implements WebMvcConfigurer {

    @Bean
    public ITemplateResolver templateResolver() {
        SpringResourceTemplateResolver resolver = new SpringResourceTemplateResolver();
        resolver.setPrefix("resources/templates/");
        resolver.setSuffix(".html");
        resolver.setTemplateMode(TemplateMode.HTML);
        resolver.setCacheable(false);
        return resolver;
    }

    @Bean
    public SpringTemplateEngine templateEngine() {
        SpringTemplateEngine templateEngine = new SpringTemplateEngine();
        templateEngine.setTemplateResolver(templateResolver());
        templateEngine.addDialect(new SpringSecurityDialect());
        templateEngine.addDialect(new Java8TimeDialect());
        return templateEngine;
    }


    @Bean
    public ViewResolver viewResolver() {
        ThymeleafViewResolver thymeleafViewResolver = new ThymeleafViewResolver();
        thymeleafViewResolver.setTemplateEngine(templateEngine());
        thymeleafViewResolver.setCharacterEncoding("UTF-8");
        return thymeleafViewResolver;
    }


    @Component
    public class CustomContainer implements
            WebServerFactoryCustomizer<TomcatServletWebServerFactory> {

        @Override
        public void customize(TomcatServletWebServerFactory factory) {
            factory.setContextPath("/wpat");
        }
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/js/**")
                .addResourceLocations("/resources/static/js/");
        registry.addResourceHandler("/css/**")
                .addResourceLocations("/resources/static/css/");
        registry.addResourceHandler("/images/**")
                .addResourceLocations("/resources/static/images/");
        registry.addResourceHandler("/lang/**")
                .addResourceLocations("/resources/static/lang/");
        registry.addResourceHandler("/uploads/**")
                .addResourceLocations("/resources/static/uploads/");
    }


}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question