Forum

I am getting status 404 while running Spring MVC app on server  

  RSS

nitinvv22
New Member
Joined:2 years  ago
Posts: 2
14/08/2017 12:06 pm  

Hello,

I am trying to create a basic Spring MVC app but when I run it, I am getting 404 status on my web browser.

Any suggestion please.

HTTP Status 404 – Not Found

Type Status Report

Message /WEB-INF/users_view.jsp

Description The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.

Apache Tomcat/9.0.0.M26

I Here is my controller file

@Controller
public class UserController {

    @RequestMapping(value = "/users", method = RequestMethod.GET)
    public String showUsers(ModelMap model) {
        return "users_view";
    }
}

And web.xml

<display-name>User</display-name>
<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:applicationContext.xml</param-value>
</context-param>
<!-- Creates the Spring Container shared by all Servlets and Filters -->
<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- Process application servlet -->
<servlet>
    <servlet-name>appServlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            classpath:applicationContext.xml
        </param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>appServlet</servlet-name>
    <url-pattern>*.do</url-pattern>
</servlet-mapping>

applicationcontext.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation= "http://www.springframework.org/schema/beans
                            http://www.springframework.org/schema/beans/spring-beans.xsd
                            http://www.springframework.org/schema/context
                            http://www.springframework.org/schema/context/spring-context.xsd">

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

    <context:component-scan base-package="ru.pravvich" />
</beans>

 


ReplyQuote
admin
Member Admin
Joined:2 years  ago
Posts: 7
14/08/2017 12:12 pm  

Looks like your mapping is not proper.

Can you tell me where are you keeping all of your view files.

Thanks


ReplyQuote
nitinvv22
New Member
Joined:2 years  ago
Posts: 2
14/08/2017 12:15 pm  

I am keeping my view files under WEB-INF\views


ReplyQuote
admin
Member Admin
Joined:2 years  ago
Posts: 7
14/08/2017 12:18 pm  

Please change your applicationcontext.xml like below and then try :

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation= "http://www.springframework.org/schema/beans
                            http://www.springframework.org/schema/beans/spring-beans.xsd
                            http://www.springframework.org/schema/context
                            http://www.springframework.org/schema/context/spring-context.xsd">

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

    <context:component-scan base-package="ru.pravvich" />
</beans>

ReplyQuote
  
Working

Please Login or Register