0

Why JSP don't convert into HTML? so, I don't know what to show you

  @Bean
    public UrlBasedViewResolver urlBasedViewResolver(){
        UrlBasedViewResolver resolver = new UrlBasedViewResolver();
        resolver.setPrefix("/WEB-INF/views/");
        resolver.setSuffix(".jsp");
        resolver.setViewClass(JstlView.class);
        return resolver;
    }


@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
    registry.addResourceHandler("/WEB-INF/views/**").addResourceLocations("/WEB-INF/views/");
}

One of my JSPs...

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Edit word</title>
</head>
<body>
<form action="edit" method="post">        
    <input name="id" type="hidden" value="${id}">
    <input type="submit">
</form>
</body>
</html>

...

@RequestMapping(value = "/words/edit",method = RequestMethod.GET)
public String editWord(Model model, @RequestParam(required = false) String userID){
    model.addAttribute("words",wordService.getAll());
    return "/words/edit";
}

Displays as just opened JSP in browser:
That return my controller

structure of pages

JVic
  • 161
  • 1
  • 12
  • Welcome to Stack Overflow! Please review our [SO Question Checklist](http://meta.stackoverflow.com/questions/260648/stack-overflow-question-checklist) to help you to ask a good question, and thus get a good answer. – Joe C Oct 19 '16 at 21:12
  • Welcome, what is the result of the browser request ? An error, the jsp code, an other page ? If the last one, have you some 404 error management, htaccess, ... ? – AxelH Oct 20 '16 at 07:19
  • @AxelH, That return for all my pages. please watch [that one of results](https://i.stack.imgur.com/ewH5t.png) – JVic Oct 20 '16 at 07:28
  • Ok well you don't ask to convert the jsp I think. Read this http://docs.spring.io/spring-framework/docs/current/spring-framework-reference/html/mvc.html#mvc-redirecting . I am not a professional of this technology but this should do it – AxelH Oct 20 '16 at 07:39
  • Just a note : I doubt you need the `/` in the name of the file `/words/edit` -> `words/edit`. That should resolve into /WEB-INF/views/ **words/edit** .jsp – AxelH Oct 20 '16 at 08:46
  • @AxelH, and this variant I tired too..( – JVic Oct 20 '16 at 08:52

2 Answers2

0

Please return "words/edit" instead of "/words/edit". You have already set resolver.setPrefix("/WEB-INF/views/"); returning ""/words/edit" results in "//words/edit" .

  • I don't have edit.jsp in views folder. But i have then in views\words\. Please watch my [structure of pages](https://i.stack.imgur.com/3ZqNh.jpg) – JVic Oct 19 '16 at 21:34
  • I don't have edit.jsp in views folder. But i have **it** in views\words\. – JVic Oct 19 '16 at 21:38
0

I believe that using a UrlBasedViewResolver will only redirect to the file but a JSP need to be parse/compile.

The doc of Spring tell you that there is InternalResourceViewResolver and InternalResourceView that internally forward the jsp file. This will parse the file as you need.

For view technologies such as JSPs that are processed through the Servlet or JSP engine, this resolution is usually handled through the combination of InternalResourceViewResolver and InternalResourceView, which issues an internal forward or include via the Servlet API’s RequestDispatcher.forward(..) method or RequestDispatcher.include() method.

Source : http://docs.spring.io/spring-framework/docs/current/spring-framework-reference/html/mvc.html#mvc-redirecting

AxelH
  • 14,325
  • 2
  • 25
  • 55
  • unfortunately, but I tried to use as InternalResourceViewResolver and as InternalResourceView. The result is the same – JVic Oct 20 '16 at 08:43
  • @Виктор For a correct usage of these object, check existing answers : http://stackoverflow.com/questions/24980839/spring-mvc-viewresolver-not-mapping-to-html-files – AxelH Oct 20 '16 at 09:00