Announcement Announcement Module
Collapse
No announcement yet.
Problem with the spring bind example Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem with the spring bind example

    Hi,

    I want to understand the how the <spring bind> work. Could someone please suggest me where I am going wrong ?

    web.xml
    Code:
    <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">
    	<servlet>
    		<servlet-name>spring</servlet-name>
    		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    		<load-on-startup>1</load-on-startup>
    	</servlet>
    	<servlet-mapping>
    		<servlet-name>spring</servlet-name>
    		<url-pattern>*.do</url-pattern>
    	</servlet-mapping>
    	<listener>
    		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    	</listener>
    	<context-param>
    	<param-name>contextConfigLocation</param-name>
    	<param-value>/WEB-INF/spring-servlet.xml</param-value>
    	</context-param>
    </web-app>
    My 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"
    	xsi:schemaLocation="http://www.springframework.org/schema/beans 
    	http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
    
    	<bean name="/submit.do" class="com.bansal.controller.MyController">
    		<property name="commandName" value="user" />
    		<property name="commandClass" value="com.bansal.command.User" />
    		<property name="formView" value="DisplayHomePage" />
    		<property name="successView" value="DisplayUserInfo" />
    	</bean>
    	
    
    	<bean id="viewResolver"
    		class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    		<property name="prefix">
    			<value>/WEB-INF/view/</value>
    		</property>
    		<property name="suffix">
    			<value>.jsp</value>
    		</property>
    	</bean>
    </beans>
    Here is my first Jsp
    Code:
    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    	pageEncoding="ISO-8859-1"%>
    <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
    <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Insert title here</title>
    </head>
    <body>
    	<form action="submit.do" method="POST">
    		<spring:bind path="user.fName" >
    			First Name::<input name="${status.expression}" value="${status.value}"/> <br>
    		</spring:bind>
    		<spring:bind path="user.lName" >
    			Last Name::<input name="${status.expression}" value="${status.value}"/> <br>
    		</spring:bind>
    		<spring:bind path="user.date" >
    			DOB::<input name="${status.expression}" value="${status.value}"/> <br>
    		</spring:bind>
    		<spring:bind path="user.password" >
    			Password::<input name="${status.expression}" value="${status.value}"/> <br>
    		</spring:bind>
    		<spring:bind path="user.confPassword" >
    			Confirm Password::<input name="${status.expression}" value="${status.value}"/> <br>
    		</spring:bind>
    		<input type="submit" value="Submit" />
    	</form>
    </body>
    </html>
    When I right click on this jsp and run the app on server I got the below exception
    Code:
    
    Jun 26, 2013 12:22:58 AM org.springframework.web.servlet.tags.BindTag doStartTag
    SEVERE: Neither BindingResult nor plain target object for bean name 'user' available as request attribute
    javax.servlet.jsp.JspTagException: Neither BindingResult nor plain target object for bean name 'user' available as request attribute
    	at org.springframework.web.servlet.tags.BindTag.doStartTagInternal(BindTag.java:121)
    	at org.springframework.web.servlet.tags.RequestContextAwareTag.doStartTag(RequestContextAwareTag.java:77)
    	at org.apache.jsp.DisplaySpringBindHomePage_jsp._jspService(DisplaySpringBindHomePage_jsp.java:86)
    	at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    	at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:433)
    	at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:389)
    If I use one more jsp where we have one "Click Here" link and after clicking on that link if if come to this jsp then it is working fine. I believe it is because, user commond is created and that is available to above jsp.

    but what if I want to show the Login form(above jsp) as the main home page ? While doing this I am getting above exception.

    Could someone please help me

  • #2
    Could someone please help me

    Comment

    Working...
    X