P
P
P_Alexander2018-06-15 14:26:43
Java
P_Alexander, 2018-06-15 14:26:43

How to map to the path "/" index.html?

Good afternoon, I’m learning a spin, how, at the start of the application, would index.html be called by default?
that is, if the default path is localhost:8080/MakeYourDream - then I saw index.html on it.
All html files are here - /WEB-INF/view/
Where did I make a mistake or what did I not add?
web.xml

<servlet>
        <servlet-name>servlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/app-config.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>servlet</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/spring-servlet.xml</param-value>
    </context-param>

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

spring-servlet
<bean id="templateResolve" class="org.thymeleaf.spring5.templateresolver.SpringResourceTemplateResolver">
        <property name="prefix" value="/WEB-INF/view/"/>
        <property name="suffix" value=".html"/>
        <property name="templateMode" value="HTML5"/>
    </bean>

controller
@Controller
public class MainController {

    @RequestMapping(value = "/", method = RequestMethod.GET)
    public String index(Model model){
        model.addAttribute("message", "Hello index");
        return "index";
    }
}

Stacktrace
14:17:35,048 WARN  [org.springframework.web.servlet.PageNotFound] (default task-1) No mapping found for HTTP request with URI [/MakeYourDream/] in DispatcherServlet with name 'servlet'
14:17:44,292 WARN  [org.springframework.web.servlet.PageNotFound] (default task-1) No mapping found for HTTP request with URI [/MakeYourDream/] in DispatcherServlet with name 'servlet'
14:18:09,112 WARN  [org.springframework.web.servlet.PageNotFound] (default task-1) No mapping found for HTTP request with URI [/MakeYourDream/INDEX] in DispatcherServlet with name 'servlet'
14:18:35,091 WARN  [org.springframework.web.servlet.PageNotFound] (default task-1) No mapping found for HTTP request with URI [/MakeYourDream/index] in DispatcherServlet with name 'servlet'

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
P_Alexander, 2018-06-18
@P_Alexander

So I DECIDED!! it's been 3 days!!!
What was the problem!?!? in that by default, maven creates a project and immediately lies index.jsp which will be the default page (unless, of course, it is configured by default to such a path / ) since I wanted to use thymleaf templates, I don’t need .jsp anymore, I need .html then I created the index.html page, but I didn’t delete the index.jsp page, but marked it as text (there is such a function in the idea, if more specifically - Mark as a plain text) because I thought this file would not participate with this label, BUT FUCK! WILL!!! In general, apparently during assembly, two files with the same names and even different extensions clashed, and I grabbed such an error.
I deleted the index.jsp file, everything worked)))
The treatment is simple, NEVER CREATE FILES WITH THE SAME NAMES.

A
Alexey Cheremisin, 2018-06-15
@leahch

It is you who needs to describe in the servlet container which application you will map by default. For cat Tom it is described here - https://tomcat.apache.org/tomcat-7.0-doc/default-s... (file $CATALINA_BASE/conf/web.xml) and here https://stackoverflow.com/questions /14325171/setti...
(you can place your war file as ROOT.war)
Well, smoke docks from your container.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question