0

I'm very new in Spring development. Please advice what I missed in my mini project. The Spring configuration defined in main.Main class by annotations (see below). Application starts succesefull, with message "...RequestMappingHandlerMapping : Mapped "{[/hello],methods=[GET]}..."

But when I tryed to open page http://localhost:8080/hello?name=MyUserName, I recieve error message: "...org.springframework.web.util.NestedServletException: Handler processing failed; nested exception is java.lang.NoClassDefFoundError: javax/servlet/jsp/jstl/core/Config..."

Seems to me that I has't completed configure DispatcherServlet to map controller output to View. But what I missed?

This is main.Main class:

@Configuration
@EnableWebMvc
@ComponentScan({"controllers"})
@EnableAutoConfiguration
public class Main {

public static void main(String[] args){
    SpringApplication.run(Main.class, args);
}

@Bean
public InternalResourceViewResolver viewResolver() {
    InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
    viewResolver.setViewClass(JstlView.class);
    viewResolver.setPrefix("WEB-INF/views/");
    viewResolver.setSuffix(".html");
    return viewResolver;
}
}

There is Controller intended to deal with user request:

@Controller
public class HelloController {
private static final String PAGE_URL = "/hello";

@RequestMapping(value = PAGE_URL,method = RequestMethod.GET)
public String getHelloMessage(@RequestParam("name") String name, Model model){
    String str = (name == null) || name.equals("") ? "World" : name;
    model.addAttribute("name", str);
    return "hello";
}
}

This is View class (hello.html) located in the /WEB-INF/views/ directory Class project structure for HelloController application

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
vzateychuk
  • 301
  • 1
  • 3
  • 12

1 Answers1

1

The error message is incomplete but, it looks like you are missing the jstl.jar in your runtime.

Try to add that dependency to your project. http://mvnrepository.com/artifact/javax.servlet/jstl/1.2

Be careful if you deploy the jstl.jar inside your app, the majority of application servers have a version of this jar.

A more complete answer can be found here : java.lang.NoClassDefFoundError: javax/servlet/jsp/jstl/core/Config

Community
  • 1
  • 1
  • Dear Francois, this really helpful. This problem resolved now. But there is now problem rised up: "....No mapping found for HTTP request with URI [/WEB-INF/views/hello.html] in DispatcherServlet with name 'dispatcherServlet'..." Looks like there is no mapping to "hello.html". But this is strange because I expected that this code must configure DispatcherServlet to know all Views (*.html): 'code'@Bean public InternalResourceViewResolver viewResolver() { .... } Am I wrong? – vzateychuk Aug 15 '16 at 17:16
  • If you have a new question, ask a new Question instead of changing an existing and already answered Question. – BalusC Aug 15 '16 at 18:26
  • Sorry, my fault, I'd close this question since it completely clear. – vzateychuk Aug 15 '16 at 18:28