2
votes

I am using pre setup Maven project from openshift and when I`m running the app on Tomcat the answer is "HTTP Status 404 - /WEB-INF/views/hello.jsp" Here is the web.xml

<display-name>Spring MVC Application</display-name>
    <servlet>
        <servlet-name>dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>WEB-INF/dispatcher-servlet.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>dispatcher</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

dispatcher-servlet

<bean id="jspViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix" value="/WEB-INF/views/"/>
    <property name="suffix" value=".jsp"/>
</bean>

hello.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>

    <html>
    <head>
        <title></title>
    </head>
    <body>
    <h1>Message : ${message}</h1>
    </body>
    </html>

and controller

@Controller
@RequestMapping("/welcome")
public class Test {
    @RequestMapping(method = RequestMethod.GET)
    public String printWelcome(ModelMap model) {
        model.addAttribute("message", "Spring 3 MVC - Hello World");
        return "hello";
    }
}

My IDEA Spring service shows that it is not able to resolve "hello" in "return "hello";" and there is no error in log just shows "HTTP Status 404 - /WEB-INF/views/hello.jsp" when i ask for http://localhost:9999/welcome; Appreciate everyone`s answer

PS here is the source code if anyone is interested, thanks

1
please add the error or exception logs. - Imran
Well, there is no error in log just shows "HTTP Status 404 - /WEB-INF/views/hello.jsp" when i ask for localhost:9999/welcome. the server starts just fine - Gregory Mazur
Provide context name in URL (localhost:9999/yourProjectName/welcome) and hit again. - 2787184
Thank you, already tried, does not help. Added source from github - Gregory Mazur
BTW localhost:9999/restauranter/welcome shows HTTP Status 404 only without /WEB-INF/views/hello.jsp. which means controller works.... probably - Gregory Mazur

1 Answers

2
votes

In the view resolver you are pointing to /WEB-INF/views instead use value="/WEB-INF/pages/" Then hello.jsp should shows up.