简体   繁体   English

奇怪的错误:在URL映射spring mvc上找不到资源

[英]strange error: resource not found on url mapping spring mvc

Everything seems alright but when I launch my application, I get a strange error of resource not found. 一切似乎都很好,但是当我启动应用程序时,出现一个奇怪的资源错误错误。 This is my controller class 这是我的控制器课

@Controller
public class HomeController {

        @Autowired
        private IMusicStoreService musicStoreService;

    @RequestMapping(value="/")
    public ModelAndView test(HttpServletResponse response) throws IOException{

        return new ModelAndView("home","musicDetForm",new MusicDetails());
    }

        @RequestMapping(value="AddSong",method = RequestMethod.POST)
        @ResponseBody
        public String addSong(@ModelAttribute("musicDetForm") MusicDetails musicDetails){
           return musicStoreService.addSong(musicDetails);
        }

        @RequestMapping(value = "SongList/",method = RequestMethod.GET)
        @ResponseBody
        public List<MusicDetails> getSongList(){
            return musicStoreService.getSongList();
        }
}

This is a code section from my pom.xml file 这是我pom.xml文件中的代码部分

<properties>
    <failOnMissingWebXml>false</failOnMissingWebXml>
        <java.version>1.6</java.version>
        <spring.version>3.1.0.RELEASE</spring.version>
        <cglib.version>2.2.2</cglib.version>
</properties>

This is my web.xml file 这是我的web.xml文件

<display-name>MusicStore</display-name>
    <context-param>
        <param-name>contextClass</param-name>
        <param-value>
            org.springframework.web.context.support.AnnotationConfigWebApplicationContext
        </param-value>
    </context-param>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <servlet>
        <servlet-name>SpringDispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextClass</param-name>
            <param-value>
                org.springframework.web.context.support.AnnotationConfigWebApplicationContext
            </param-value>
        </init-param>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>aish.vaishno.musicstore</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>SpringDispatcher</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

    <session-config>
        <session-timeout>30</session-timeout>
    </session-config>
</web-app>

When I launch my application on tomcat using sts, no error is shown on my build but I get this error 当我使用sts在tomcat上启动我的应用程序时,我的构建没有显示任何错误,但出现此错误

HTTP Status 404 - /MusicStore/

Why am I getting the above error despite that my mapping seems okay. 尽管我的映射似乎还可以,但为什么仍然出现上述错误?

Are you storing the MusicStore inside the WEB-INF/? 您是否将MusicStore存储在WEB-INF /中? It is okay to access if you set it as the index in web.xml 如果将其设置为web.xml中的索引,则可以访问

However,once you send request ,the response normally send to the URL you provided, and should be a 'JSP' file,but not servlet. 但是,一旦发送请求,响应通常就会发送到您提供的URL,并且应该是“ JSP”文件,而不是servlet。

In your case, the code are messed up quite a bit,i didn't see any View or JSP or web page to follow your MusicStore controller, sure you can directly print it but that's not a good practice. 在您的情况下,代码混乱了很多,我没有看到任何View或JSP或网页跟随您的MusicStore控制器,请确保您可以直接打印它,但这不是一个好习惯。

If you could provide more of the code content,it may be more helpful. 如果您可以提供更多的代码内容,则可能会更有帮助。 The solution is now see if you could access index page when you first load your servlet, or check the mapping. 现在的解决方案是,当您第一次加载servlet或检查映射时,是否可以访问索引页面。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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