本文标题中描述的错误正在我的 spring mvc 应用程序的 eclipse 控制台中显示。我尝试在 stackoverflow 中寻找其他类似的示例,但其他示例都没有解决我的问题。下面是我项目中的一些文件:
Controller :
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;
}
}
web.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" />
关于java - 在 DispatcherServlet 中未找到名称为 'HorarioLivre' 的 URI [/HorarioLivre/login.html] 的 HTTP 请求的映射,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22116377/