在/

时间:2016-04-28 11:59:58

标签: java spring jsp tomcat servlets

我正在跟进此网址的教程

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>

假设这是我在控制器映射中的默认网址

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

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

现在我将我的应用程序启动到此URL

http://localhost:8080/MusicStore/

我的项目结构的屏幕截图

enter image description here

我的servlet引擎Tomcat返回HTTP状态错误404。

请问可能出错?

Error Notification

2 个答案:

答案 0 :(得分:0)

将以下代码放在mvc-dispatcher-servlet.xml中以配置viewResolver

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

然后在/ WEB-INF / views /

中添加您的jsp文件

答案 1 :(得分:-1)

您是否配置了viewResolver?

@Bean     public UrlBasedViewResolver setupViewResolver(){

WITH CTE
AS
(
SELECT CountryID, CountryName, City
FROM Country 
INNER JOIN City 
    on Country.Id = City.id
)
SELECT DISTINCT CountryName, City
FROM CTE