Announcement Announcement Module
Collapse
No announcement yet.
Unable get Bind status information for command bean's field in jsp file Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Unable get Bind status information for command bean's field in jsp file

    First of all I just want to mention that I am new for spring framework.
    When I am trying to run jsp file on browser It throws an error like this
    javax.servlet.jsp.JspTagException: Neither BindingResult nor plain target object for bean name 'urcb' available as request attribute
    here is my code

    web.xml
    Code:
    ?xml version="1.0" encoding="UTF-8"?>
    <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee   http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
     <context-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>/WEB-INF/applicationContext.xml</param-value>
     </context-param>
     <listener>
      <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
     </listener>
     <servlet>
      <servlet-name>spring</servlet-name>
      <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
     </servlet>
     <servlet-mapping>
      <servlet-name>spring</servlet-name>
      <url-pattern>*.htm</url-pattern>
    </servlet-mapping>
    
    </web-app>
    Child spring configuration file
    spring-servlet.xml
    Code:
    <?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"
    	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
    
    	<bean id="jspView" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    		<property name="prefix" value="/pages/" />
    		<property name="suffix" value=".jsp" />
    	</bean>
    	
    	<bean name="/test.htm" class="formPack.TempCtrl" >
    		<property name="commandClass" value="formPack.UserCmdBean" />
    		<property name="commandName" value="urcb" />
    	</bean>
    	
    </beans>
    Controller class (here I am using AbstractCommandController)
    TempCtrl.java
    Code:
    package formPack;
    
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    import org.springframework.validation.BindException;
    import org.springframework.web.servlet.ModelAndView;
    import org.springframework.web.servlet.mvc.AbstractCommandController;
    
    public class TempCtrl extends AbstractCommandController {
    
    	@Override
    	protected ModelAndView handle(HttpServletRequest request,
    			HttpServletResponse response, Object cmdo, BindException be)
    			throws Exception {
    		
    			ModelAndView mav = new ModelAndView();
    			mav.setViewName("test");
    			System.out.println("Binding exception object "+be);
    		return mav;
    		
    	}
    	
    	
    }
    In jsp file I am trying to get error message for command field by status object.

    Here jsp file

    user_login.jsp

    Code:
    <form action="test.htm" > 
    <spring:bind path="urcb.uid">
    	${status:errorMessages}
    </spring:bind>
    
    Uid :&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; <input type="text" name="uid" /><br><br> 
    Name : &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; <input type="text" name="uname" /><br><br> 
    Password :&nbsp;&nbsp; <input type="password" name="pwd" /> <br><br>
    <input type="submit" value="login" />
     
    </form>
    I don't understand why this is occurring. why this is not set in request attribute.

    I am really messed up with this error. so please reply soon
    thanks in advance.

    Any little help would be appreciated.
    Last edited by rkrahu; Mar 23rd, 2013, 04:06 AM.
Working...
X