2015-09-06 84 views
-1

我正在创建一个使用maven,spring来设置spring项目的环境。设置spring和maven

但我得到的错误,而试图执行此URL http://localhost:8080/assignment2_farooqab/WEB-INF/pages/index.jsp[ ^]

错误是 HTTP状态404 的资源不可用

我认为这个问题是由于这个文件mvcdispather XML

<

beans xmlns="http://www.springframework.org/schema/beans" 
     xmlns:context="http://www.springframework.org/schema/context" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:schemaLocation=" 
     http://www.springframework.org/schema/beans  
     http://www.springframework.org/schema/beans/spring-beans-3.2.xsd 
     http://www.springframework.org/schema/context 
     http://www.springframework.org/schema/context/spring-context-3.2.xsd"> 

     <context:component-scan base-package="no.uio.inf5750.assignment2_farooqab" /> 

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

</beans> 

basecontroller.java文件

package no.uio.inf5750.assignment2_farooqab.controller; 

import org.springframework.stereotype.Controller; 
import org.springframework.ui.ModelMap; 
import org.springframework.web.bind.annotation.RequestMapping; 
import org.springframework.web.bind.annotation.RequestMethod; 
import org.springframework.web.bind.annotation.PathVariable; 


@Controller 
public class BaseController { 

     @RequestMapping(value="/", method = RequestMethod.GET) 
     public String welcome(ModelMap model) { 

       model.addAttribute("message", "Maven Web Project + Spring 3 MVC - welcome()"); 

       //Spring uses InternalResourceViewResolver and return back index.jsp 
       return "index"; 

     } 

     @RequestMapping(value="/welcome/{name}", method = RequestMethod.GET) 
     public String welcomeName(@PathVariable String name, ModelMap model) { 

       model.addAttribute("message", "Maven Web Project + Spring 3 MVC - " + name); 
       return "index"; 

     } 

} 

由代码return "index";和您的视图解析器任何提示

+1

那是你的应用程序,因为通过'http://本地主机:8080/assignment2_farooqab/WEB-INF /页/ index.jsp'未映射到您的控制器中。尝试去'http:// localhost:8080/assignment2_farooqab /'。可用页面由您的控制器中的注释指定,​​而不是您将jsp文件放在WEB-INF文件夹中的位置 –

+0

哦谢谢它的工作原理 – Farooq

回答