这篇文章标题中描述的错误显示在我的Spring MVC应用程序的eclipse控制台中。我尝试在堆栈溢出中寻找其他类似的示例,但其他示例都没有解决我的问题。关注我项目中的一些文件:
控制器:
package com.HorarioLivre.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
import com.HorarioLivre.core.Sessao;
import com.HorarioLivre.data.UsuarioDAO;
@Controller
public class HorarioLivreController {
private Sessao sessao;
@RequestMapping(value="/login", method=RequestMethod.POST)
public ModelAndView usuario_login(@RequestParam("username") String username, @RequestParam("password") String password) {
UsuarioDAO usuario = new UsuarioDAO(username, password);
if(usuario.getUsuario() != null) {
this.setSessao(new Sessao(usuario.getUsuario()));
}
ModelAndView mav = new ModelAndView();
mav.setViewName("usuario_start");
mav.addObject("usuario", usuario.getUsuario());
return mav;
}
public Sessao getSessao() {
return sessao;
}
public void setSessao(Sessao sessao) {
this.sessao = sessao;
}
}
网络.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>HorarioLivre</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>HorarioLivre</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>HorarioLivre</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
HorarioLivre-servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:component-scan base-package="com.horariolivre.controller" />
<bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>
有人可以看到这段代码有什么问题吗?我非常努力,但不知道发生了什么。
你有没有告诉Spring MVC扫描,以及扫描哪些软件包来扫描你的Spring配置文件中的@Controller
和@RequestMapping
注释? 它不在您发布的配置中。 像这样:
<mvc:annotation-driven />
<context:component-scan base-package="com.HorarioLivre.controller" />