我是Spring MVC的新手。我经历了基础,一切正常。然后,当我尝试将Spring MVC连接到我当前的项目时,Controller没有被调用。
这是我的servlet-context.xml
<annotation-driven />
<!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
<resources mapping="/resources/**" location="/resources/" />
<!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory-->
<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property name="prefix" value="/WEB-INF/views/" />
<beans:property name="suffix" value=".jsp" />
</beans:bean>
<context:component-scan base-package="net.nelnet.quikstage.webapp.controller" />
这是我的控制器
package net.nelnet.quikstage.webapp.controller;
@Controller
public class HomeController {
private static final Logger logger = LoggerFactory.getLogger(HomeController.class);
/**
* Simply selects the home view to render by returning its name.
*/
@RequestMapping(value = "/")
public String home(Locale locale, Model model) {
logger.info("Welcome! you are under Home Section "+ locale.toString());
Date date = new Date();
DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);
String formattedDate = dateFormat.format(date);
model.addAttribute("serverTime", formattedDate );
return "/WEB-INF/views/home.jsp";
}
}
我将我的项目分为一个父项和两个子项目。我试图将Spring MVC实现到其中一个子项目中。我不确定天气项目结构是否会导致问题
答案 0 :(得分:0)
谢谢你们。我的spring配置文件很好,服务器启动时没有错误。其实我发现了这个问题。默认情况下,<resources mapping="/resources/**" location="/resources/" />
,当"**"
删除'**'或放置文件夹下的内容将解决问题时,它不希望资源为空