沒有發現我從這個網址用SpringMVC控制器/
https://aishwaryavaishno.wordpress.com/2013/07/12/spring-mvchibernate-annotation-based-mysql-maven-json-simple-example/
下一個教程從教程中,我在我的控制器有這樣的
@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();
}
我制訂我的DispatcherServlet和的contextConfigLocation到我的web.xml文件
<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>
</servlet>
<servlet-mapping>
<servlet-name>SpringDispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/mvc-dispatcher-servlet.xml</param-value>
</context-param>
<session-config>
<session-timeout>30</session-timeout>
</session-config>
假設這是我從控件的默認網址LER映射
@RequestMapping(value="/")
public ModelAndView test(HttpServletResponse response) throws IOException{
return new ModelAndView("home","musicDetForm",new MusicDetails());
}
現在,當我啓動我的應用程序到這個網址
http://localhost:8080/MusicStore/
我的項目結構
的Tomcat的屏幕截圖這是我的servlet引擎返回的HTTP狀態錯誤404.
請問什麼可能是錯了嗎?
請分享你的異常堆棧跟蹤,如果它說404錯誤,它不是擊中服務器可能是你的項目打包結構的問題。並請張貼您的項目包結構以供分析。 –
@PraveenKumar我已經添加了我的項目結構 – Blaze
的屏幕截圖,您的項目結構沒有正確形成,因爲我將您的HomeController.java看作類文件。它不被識別爲Java文件。這就是爲什麼你會得到這個例外,我編輯過,以顯示錯誤指示,一旦同行評審它,你會看到它。另外,請發佈eclipse項目構面設置。 –