简体   繁体   中英

HTTP Status 404 – Not Found - JAVA MVC

Why I am getting double slash at WEB-INF/view//admin. I am new at Java MVC so please any suggestion, what am I doing wrong?

here is my code `

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

web.xml

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

Controller -

@Controller
    public class ControllerClass {
@RequestMapping(value = "/deck", method = RequestMethod.GET)
        public ModelAndView viewDeckPage(ModelMap model, HttpServletRequest request) {
            System.out.println("in get method..");
            
                return new ModelAndView("/admin/deck");
        }
}

Remove the trailing slash so your prefix is /WEB-INF/view

There are 2 slashes because first one is coming from the view resolver which is /WEB-INF/view/ and the second one you are returning as view name which is /admin/deck (slash before admin).

To resolve this you have to return only view name without a prefixed slash ie admin/deck

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM