Buenas amigos do Fórum,
Recentemente comecei a estudar este framework e não consigo resolver um problema que parece relativamente fácil. Procurei na documentação, em tutoriais, enfim… Tentei achar a solução deste erro, mas não acho de jeito nenhum. :shock:
Conferi uma, duas, três vezes mas não vejo onde possa estar errado na configuração para que este erro continue ocorrendo: java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name ‘credential’ available as request attribute.
Aqui vão meus arquivos:
- web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee web-app_2_4.xsd"
version="2.4">
<display-name>WebCif</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/webcif-beans.xml
/WEB-INF/webcif-jdbc.xml
/WEB-INF/webcif-services.xml
/WEB-INF/webcif-dao.xml
</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>webcif</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>webcif</servlet-name>
<url-pattern>*.htm</url-pattern>
</servlet-mapping>
<taglib>
<taglib-uri>http://java.sun.com/jstl/core</taglib-uri>
<taglib-location>/WEB-INF/tld/c.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>http://java.sun.com/jstl/fmt</taglib-uri>
<taglib-location>/WEB-INF/tld/fmt.tld</taglib-location>
</taglib>
<jsp-config>
<taglib>
<taglib-uri>/spring</taglib-uri>
<taglib-location>/WEB-INF/tld/spring-form.tld</taglib-location>
</taglib>
</jsp-config>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>
- LoginController.java
package br.com.cif.web;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import br.com.cif.core.LoginService;
import br.com.cif.web.vo.LoginCredentialsVO;
@Controller
@RequestMapping(value = "/login")
public class LoginFormController {
@Autowired
private LoginService loginService;
@RequestMapping(method = RequestMethod.POST)
public String onSubmit(
@ModelAttribute("credential") LoginCredentialsVO credentials,
BindingResult result) throws Exception {
if (result.hasErrors())
return "login";
loginService.login(credentials.getUsername(),
credentials.getPassword());
System.out.println("Username: " + credentials.getUsername());
System.out.println("Password: " + credentials.getPassword());
return "home";
}
}
- login.jsp
<div id="mainContent">
<c:url var="logintUrl" value="/login" />
<form:form modelAttribute="credential" method="POST" action="${logintUrl}">
<table border="0" width="100%">
<tr>
<td width="35%"></td>
<td width="10%">Usuário</td>
<td width="20%"><form:input path="username"/><form:errors path="username"/></td>
<td width="35%"></td>
</tr>
<tr>
<td width="35%"></td>
<td width="10%">Senha</td>
<td width="20%"><form:input path="password"/><form:errors path="password" /></td>
<td width="35%"></td>
</tr>
<tr>
<td colspan="4"> </td>
</tr>
<tr>
<td width="35%"></td>
<td colspan="2" align="center">
<input type="submit" name="Entrar" value="Entrar"/>
</td>
<td width="35%"></td>
</tr>
<tr>
<td colspan="4"> </td>
</tr>
<tr>
<td colspan="4" class="login_error_text">
<!-- aqui apresentamos a mensagem de erro, se necessario -->
</td>
</tr>
</table>
</form:form>
</div>
Tomara que alguém me ajude encontrar este erro…
Valeu!