I referred to sample spring application on netbeans.org and tried to create a simple login application. When I run I get this error:
javax.servlet.ServletException: javax.servlet.jsp.JspTagException: Neither BindingResult nor plain target object for bean name 'login' available as request attribute
Here is my login.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%@taglib uri="http://www.springframework.org/tags" prefix="spring" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Business SMS Login</title>
</head>
<body>
<div id="mainContainer">
<spring:nestedPath path="login">
<form name="frmBSMSLogin" action="" method="post">
<div id="controls">
<div id="lgnUsername">
<label for="txtUsername">Username</label>
<spring:bind path="login.username">
<input type="text" name="${status.expression}" value="${status.value}" id="txtUsername" maxlength="20" class="textInput"/>
</spring:bind>
</div>
<br/>
<div id="lgnPassword">
<label for="txtPassword">Password:</label>
<spring:bind path="login.password">
<input type="password" id="txtPassword" maxlength="20" name="${status.expression}" value="${status.value}" class="textInput"/>
</spring:bind>
</div>
</div>
<div id="submitSection">
<input type="button" value="Submit" class="buttonInput"/>
<input type="reset" value="Reset" class="buttonInput"/>
</div>
</form>
</spring:nestedPath>
</div>
</body>
Here’s the LoginController.java
package controller;
import org.springframework.web.servlet.mvc.SimpleFormController;
import java.net.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.portlet.ModelAndView;
import service.Login;
public class LoginController extends SimpleFormController {
private Login login;
public LoginController() {
setCommandClass(GetLoginDetails.class);
setCommandName("login");
setSuccessView("dashboard");
setFormView("index");
}
public void setLogin(Login login){
this.login = login;
}
protected ModelAndView onSubmit( HttpServletRequest request, HttpServletResponse response, Object command, BindException errors)throws Exception {
//System.out.println("are we here?");
GetLoginDetails l = (GetLoginDetails) command;
ModelAndView mv = new ModelAndView(getSuccessView());
mv.addObject("helloMessage", login.authenticate(l.getUsername(),l.getPassword()));
return mv;
}
}
This is the applicationContext.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:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
<bean name="login" class="service.Login"/>
</beans>
I have been on this thing since last entire week I think. I am doing this by referring to netbeans’ example. Here’s the link http://netbeans.org/kb/docs/web/quickstart-webapps-spring.html. I haven’t found any solution to this. Begin from PHP background I am already finding spring framework too damn difficult, however I am trying with full efforts. I am using Netbeans as my IDE. Is it a good choice or Eclipse is the standard one? Also please give me some advice on how to debug the application. simple echo or print_r as in php looks too much of a luxury here 🙂
P.s I had posted similar question before, and someone from around here had complained of it being a code dump and downvoted me. There are many question where there is a huge code dump yet people were kind enough to help. So anyone who thinks this a code dump or somewhat in rude language please don’t waste your precious time downvoting this question. I am a genuine learner here to ask for help
Try to remove
after
spring:nestedPath – Sets a nested path to be used by the bind tag’s path.
UPD:
Read about this tag here