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
<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
<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
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/? It is okay to access if you set it as the index in 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.
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.
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.