Announcement Announcement Module
Collapse
No announcement yet.
JasperException and IllegalStateException Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • JasperException and IllegalStateException

    Dear all,

    Excuse me for being new to Spring MVC, but I am trying to learn it.

    I am getting a

    org.apache.jasper.JasperException: An exception occurred processing JSP page /jsp/registration/registration.jsp at line 44 ERROR

    And

    java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'registrationBean' available as request attribute


    I know there have been tons of posts but I still could not figure out what the issue is. Your help would be greatly appreciated!!

    I think it could be how I return the ModelAndView object, but I am not sure....

    here are the other components of my application:

    dispatcher-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"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
    <!-- YOUR ENTRIES HERE -->

    <bean id="viewResolver" class="org.springframework.web.servlet.view.Intern alResourceViewResolver">
    <property name="viewClass">
    <value>org.springframework.web.servlet.view.JstlVi ew</value>
    </property>
    <property name="prefix" value="/jsp/"/>
    <property name="suffix" value=".jsp"/>
    </bean>

    <bean id="simpleUrlMapping" class="org.springframework.web.servlet.handler.Sim pleUrlHandlerMapping">
    <property name="mappings">
    <props>
    <prop key="/registration.htm">registration</prop>
    <!-- <prop key="/profile.htm">profile</prop>-->
    </props>
    </property>
    </bean>

    <bean id="registration" class="com.logixplayer.fantastic.registration.cont roller.RegistrationController">
    <property name="formView" value="registration"/>
    <property name="successView" value="form"/>
    <property name="commandName" value="registrationBean"/>
    <property name="commandClass" value="com.logixplayer.fantastic.registration.bean .RegistrationBean"/>
    <property name="validator">
    <bean class="com.logixplayer.fantastic.registration.vali dator.RegistrationValidator"/>
    </property>
    </bean>

    </beans>

    Web.xml:

    <?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">
    <welcome-file-list>
    <welcome-file>/jsp/index.jsp</welcome-file>
    </welcome-file-list>

    <!-- Spring MVC Configuration -->
    <servlet>
    <servlet-name>dispatcher</servlet-name>
    <servlet-class>
    org.springframework.web.servlet.DispatcherServlet
    </servlet-class>
    <load-on-startup>2</load-on-startup>
    </servlet>
    <servlet-mapping>
    <servlet-name>dispatcher</servlet-name>
    <url-pattern>*.htm</url-pattern>
    </servlet-mapping>

    <listener>
    <listener-class>org.springframework.web.context.ContextLoade rListener</listener-class>
    </listener>
    <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:applicationContext.xml</param-value>
    </context-param>

    <jsp-config>
    <taglib>
    <taglib-uri>/spring</taglib-uri>
    <taglib-location>/WEB-INF/spring-form.tld</taglib-location>
    </taglib>
    </jsp-config>

    </web-app>

    RegistrationController:

    package com.logixplayer.fantastic.registration.controller;

    import javax.servlet.ServletException;

    import org.springframework.web.servlet.ModelAndView;
    import org.springframework.web.servlet.mvc.SimpleFormCont roller;
    import org.springframework.web.servlet.view.RedirectView;

    public class RegistrationController extends SimpleFormController {

    public ModelAndView onSubmit(Object command) throws ServletException {
    //new ModelAndView(new RedirectView(getSuccessView()));
    return new ModelAndView("form","profile1","profile2");
    // Map model = errors.getModel();
    // model.put("returnValues", returnValuesTotal);
    // return new ModelAndView("ExtendedSuche",model);
    }

    /**
    * @param args
    */
    public static void main(String[] args) {
    // TODO Auto-generated method stub
    }
    }

    registration.jsp:

    <%--@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"--%>
    <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
    <%@ page contentType="text/html;charset=UTF-8" language="java" %>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
    <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
    <%@ taglib uri="http://www.springframework.org/tags" prefix="spring" %>

    <%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPor t()+path+"/";
    %>

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <base href="<%=basePath%>">

    <title>My JSP 'registration.jsp' starting page</title>

    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->

    </head>

    <body>
    This is my JSP page. <br>
    <spring:hasBindErrors name="registrationBean">
    <h3>You have errors in your input!</h3>
    <font color="red">
    <c:forEach items="${errors.allErrors}" var="error">
    <spring:message code="${error.code}" text="${error.defaultMessage}"/>
    </c:forEach>
    </font>
    </spring:hasBindErrors>

    <!-- note second way of displaying error messages by field -->
    <form:form commandName="registrationBean" method="POST" action="registration.htm">
    User Name: <form:input path="userName" /><form:errors path="userName" />
    Full Name: <form:input path="fullName" /><form:errors path="fullName" />
    Email: <form:input path="email" /><form:errors path="email" />
    Password: <form:input path="password" /><form:errors path="password" />
    <input type="submit" title="Register!" />
    </form:form>
    </body>
    </html>

    This is the stackTrace:
    exception

    org.apache.jasper.JasperException: An exception occurred processing JSP page /jsp/registration/registration.jsp at line 44

    41:
    42: <!-- note second way of displaying error messages – by field -->
    43: <form:form commandName="registrationBean" method="POST" action="registration.htm">
    44: User Name: <form:input path="userName" /><form:errors path="userName" />
    45: Full Name: <form:input path="fullName" /><form:errors path="fullName" />
    46: Email: <form:input path="email" /><form:errors path="email" />
    47: Password: <form:input path="password" /><form:errors path="password" />


    Stacktrace:
    org.apache.jasper.servlet.JspServletWrapper.handle JspException(JspServletWrapper.java:524)
    org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:429)
    org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:320)
    org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:266)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:803)

    root cause

    java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'registrationBean' available as request attribute
    org.springframework.web.servlet.support.BindStatus .<init>(BindStatus.java:141)
    org.springframework.web.servlet.tags.form.Abstract DataBoundFormElementTag.getBindStatus(AbstractData BoundFormElementTag.java:172)
    org.springframework.web.servlet.tags.form.Abstract DataBoundFormElementTag.getPropertyPath(AbstractDa taBoundFormElementTag.java:192)
    org.springframework.web.servlet.tags.form.Abstract DataBoundFormElementTag.getName(AbstractDataBoundF ormElementTag.java:158)
    org.springframework.web.servlet.tags.form.Abstract DataBoundFormElementTag.autogenerateId(AbstractDat aBoundFormElementTag.java:145)
    org.springframework.web.servlet.tags.form.Abstract DataBoundFormElementTag.resolveId(AbstractDataBoun dFormElementTag.java:136)
    org.springframework.web.servlet.tags.form.Abstract DataBoundFormElementTag.writeDefaultAttributes(Abs tractDataBoundFormElementTag.java:120)
    org.springframework.web.servlet.tags.form.Abstract HtmlElementTag.writeDefaultAttributes(AbstractHtml ElementTag.java:379)
    org.springframework.web.servlet.tags.form.InputTag .writeTagContent(InputTag.java:139)
    org.springframework.web.servlet.tags.form.Abstract FormTag.doStartTagInternal(AbstractFormTag.java:90 )
    org.springframework.web.servlet.tags.RequestContex tAwareTag.doStartTag(RequestContextAwareTag.java:7 7)
    org.apache.jsp.jsp.registration.registration_jsp._ jspx_meth_form_005finput_005f0(registration_jsp.ja va:380)
    org.apache.jsp.jsp.registration.registration_jsp._ jspService(registration_jsp.java:169)
    org.apache.jasper.runtime.HttpJspBase.service(Http JspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:803)
    org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:393)
    org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:320)
    org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:266)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:803)

  • #2
    Can someone please give me a hand, I really need to get this going, thank you!!

    Can someone please give me a hand, I really need to get this going, thank you!!

    any help will be greatly appreciated, I am new to Spring MVC and I am totally stuck...

    from what I am initially reading, I need to override some methods? But not sure...as this is a registration form....

    help!!!!!!!!!

    Comment


    • #3
      logixplayer,

      You'll probably get a much better response if you place your code in the [ CODE ] ... [ /CODE ] tags. Without it, it's just a blob of incoherent text...

      That said, does your RegistrationBean class have a default constructor?

      Comment


      • #4
        jpreston, thank you for your reply.

        I did not have a constructor so I added one:

        Code:
        package com.logixplayer.fantastic.registration.controller;
        
        import javax.servlet.ServletException;
        
        import org.springframework.web.servlet.ModelAndView;
        import org.springframework.web.servlet.mvc.SimpleFormController;
        import org.springframework.web.servlet.view.RedirectView;
        
        import com.logixplayer.fantastic.registration.bean.RegistrationBean;
        
        public class RegistrationController extends SimpleFormController {
        
        	public ModelAndView onSubmit(Object command) throws ServletException {
        		//new ModelAndView(new RedirectView(getSuccessView())); 
        		return new ModelAndView("form","profile1","profile2");
        //		 Map model = errors.getModel();
        //		  model.put("returnValues", returnValuesTotal);
        //		  return new ModelAndView("ExtendedSuche",model);
        	}
        	
        	  public RegistrationController(){
        	        //setCommandClass(RegistrationBean.class);
        	    }
        
        	
        	/**
        	 * @param args
        	 */
        	public static void main(String[] args) {
        		// TODO Auto-generated method stub
        	}
        }
        but it is still not working...couple of questions,

        my JSP directory structure is embedded,

        Code:
        WebRoot
                    jsp
                        profile
                               form.jsp
                               login.jsp
                        registration
                               registration.jsp
                        index.jsp
        since my dispatcher-servlet.xml looks like this:
        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.0.xsd">  
                 <!-- YOUR ENTRIES HERE -->  
        
        	<bean id="viewResolver"  class="org.springframework.web.servlet.view.InternalResourceViewResolver">  
        		 <property name="viewClass">
        			<value>org.springframework.web.servlet.view.JstlView</value>
        		</property> 
        		 <property name="prefix" value="/jsp/"/>
        		 <property name="suffix" value=".jsp"/>  
        	</bean>
        	
        	<bean id="simpleUrlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">  
        		<property name="mappings">  
           			<props>  
           				<prop key="/registration.htm">registration</prop>
           				<!-- <prop key="/profile.htm">profile</prop>-->
           			</props>  
           		</property>  
           </bean>
           
        	<bean id="registration" class="com.logixplayer.fantastic.registration.controller.RegistrationController">  
        	   <property name="formView" value="registration"/>  
        	   <property name="successView" value="form"/>  
        	   <property name="commandName" value="registrationBean"/>  
        	   <property name="commandClass" value="com.logixplayer.fantastic.registration.bean.RegistrationBean"/>  
        	   <property name="validator">  
        	   		<bean class="com.logixplayer.fantastic.registration.validator.RegistrationValidator"/>  
        	   </property>
        	</bean>  
           
        </beans>
        I am wondering if this mapping is correct:
        Code:
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">  
        		 <property name="viewClass">
        			<value>org.springframework.web.servlet.view.JstlView</value>
        		</property> 
        		 <property name="prefix" value="/jsp/"/>
        		 <property name="suffix" value=".jsp"/>  
        	</bean>
        How will InternalResourceViewResolver know that I want to go to jsp/profile/form.jsp?

        Is it that I have to specify the directory "profile" in the SimpleFormController class?

        i.e. return new ModelAndView("profile/form","profile1","profile2");

        as opposed to

        return new ModelAndView("form","profile1","profile2");

        at any rate, this is stil what I am getting:

        Code:
        SEVERE: Servlet.service() for servlet jsp threw exception
        java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'registrationBean' available as request attribute
        	at org.springframework.web.servlet.support.BindStatus.<init>(BindStatus.java:141)
        	at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getBindStatus(AbstractDataBoundFormElementTag.java:172)
        	at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getPropertyPath(AbstractDataBoundFormElementTag.java:192)
        	at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getName(AbstractDataBoundFormElementTag.java:158)
        	at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.autogenerateId(AbstractDataBoundFormElementTag.java:145)
        	at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.resolveId(AbstractDataBoundFormElementTag.java:136)
        	at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.writeDefaultAttributes(AbstractDataBoundFormElementTag.java:120)
        	at org.springframework.web.servlet.tags.form.AbstractHtmlElementTag.writeDefaultAttributes(AbstractHtmlElementTag.java:379)
        	at org.springframework.web.servlet.tags.form.InputTag.writeTagContent(InputTag.java:139)
        	at org.springframework.web.servlet.tags.form.AbstractFormTag.doStartTagInternal(AbstractFormTag.java:90)
        	at org.springframework.web.servlet.tags.RequestContextAwareTag.doStartTag(RequestContextAwareTag.java:77)
        	at org.apache.jsp.jsp.registration.registration_jsp._jspx_meth_form_005finput_005f0(registration_jsp.java:383)
        	at org.apache.jsp.jsp.registration.registration_jsp._jspService(registration_jsp.java:172)
        	at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
        	at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
        	at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
        	at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
        	at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
        	at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
        	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
        	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
        	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
        	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
        	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
        	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
        	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:263)
        	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
        	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:584)
        	at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
        	at java.lang.Thread.run(Unknown Source)
        any clues??
        thanks!!!

        Comment


        • #5
          logixplayer,

          I did not have a constructor so I added one:
          ...
          Did you add that constructor to your com.logixplayer.fantastic.registration.controller. RegistrationController form controller class or to your com.logixplayer.fantastic.registration.bean.Regist rationBean command class? It should have been added (if not already) to the command class, RegistrationBean; although for the most part, it's almost always a good idea to write a default constructor for all classes you use with Spring.

          In the short term, you can add/override the formBackingObject method in your controller. Be sure to read the javadoc and reference docs for a better idea of what this method does. Try something like:

          Code:
              @Override
              protected Object formBackingObject(HttpServletRequest request)
                      throws Exception {
                  return new RegistrationBean();
              }
          If you get a lot of NullPointerExceptions instead, you might need to set the values of the initial object to sane, not null defaults; even new String() works.

          How will InternalResourceViewResolver know that I want to go to jsp/profile/form.jsp?
          Your view resolver is setup to automatically prefix all view names with /jsp/ and suffix them with .jsp which effectively makes the view name resolve to a file located in the /jsp/ directory ending in .jsp. For example, if you want to serve the registration page (according to your directory/file structure), the view's name would be registration/registration. The view resolver you have configured turns that into /jsp/registration/registration.jsp; that also applies to the profile form. Your view profile/form would be resolved as /jsp/profile/form.jsp by the InternalResourceViewResolver. Please be aware that this is relative to the context root path of your application.

          Is it that I have to specify the directory "profile" in the SimpleFormController class?
          Yes, if your view is supposed to serve a file located in the profile directory; the same applies to any and all subdirectories inside the /jsp/ folder.

          Be sure to update your XML to reflect the correct successView and formView views.

          As a side note, it's almost always best to secure your JSPs inside the /WEB-INF folder unless you intend them to be served directly, which in your case does not appear to be the case.

          Hope that helps,
          Last edited by jpreston; Jun 21st, 2009, 11:51 PM.

          Comment


          • #6
            jsp 404 errors now...

            hey, thanks for the reply...

            I am getting 404 errors now that my jsp's are in the WEB-INF. I realize this is a good thing as the jsp's cannot be accessed as such:

            Code:
            <%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
            <%
            String path = request.getContextPath();
            String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
            %>
            <%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
            
            <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
            <html>
              <head>
                <base href="<%=basePath%>">
                
                <title>My JSP 'index.jsp' starting page</title>
            	<meta http-equiv="pragma" content="no-cache">
            	<meta http-equiv="cache-control" content="no-cache">
            	<meta http-equiv="expires" content="0">    
            	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
            	<meta http-equiv="description" content="This is my page">
            	<!--
            	<link rel="stylesheet" type="text/css" href="styles.css">
            	-->
              </head>
              
              <body>
                This is my JSP page. <br>
                
                <!-- add some links! -->
                <a href="jsp/about/how.jsp">How</a> <br>
                <a href="jsp/about/efg.jsp">efg!</a> <br>
                <a href="jsp/about/abc.jsp">abc</a> <br>
                <a href="jsp/about/why.jsp">Why</a> <br>
                <a href="jsp/registration/registration.jsp">Registration</a> <br>
                <a href="jsp/profile/login.jsp">Login</a> <br>
                <a href='<c:url value="jsp/registration/registration.jsp"/>'>Registration!</a>
              </body>
            </html>
            I simply cannot use : <a href="jsp/profile/login.jsp"> anymore...I am on index.jsp, now I want to link to other JSP's, but I do not want to go though a controller at this point because it is not needed...
            I tried jstl:
            <a href='<c:url value="jsp/registration/registration.jsp"/>'>Registration!</a>
            but that did not work...

            how can I link to any jsp inside the web-inf dir??
            Sorry, I am not a web guy, after banging my head for over 2 hours....I realize this could be a trivial question..
            thanks!!

            Comment


            • #7
              still not working...

              I have added constructors now in RegistrationController and RegistrationBean...
              I added this method in my controller as well:
              Code:
              	  @Override
              	    protected Object formBackingObject(HttpServletRequest request)
              	            throws Exception {
              	        return new RegistrationBean();
              	    }
              But I am still getting the same error!!! it can't resolve registrationBean inside my registration.jsp

              Please tell me what I am missing, thank you...
              Controller:
              Code:
              package com.logixplayer.fantastic.registration.controller;
              
              //all import statements
              
              public class RegistrationController extends SimpleFormController {
              
              	public ModelAndView onSubmit(Object command) throws ServletException {
              		//new ModelAndView(new RedirectView(getSuccessView())); 
              		return new ModelAndView("profile/form","profile1","profile2");
              
              	}
              	
              	  public RegistrationController(){
              	        //setCommandClass(RegistrationBean.class);
              	    }
              	  
              	  @Override
              	    protected Object formBackingObject(HttpServletRequest request)
              	            throws Exception {
              	        return new RegistrationBean();
              	    }
              
              	
              
              }
              Bean:

              Code:
              package com.logixplayer.fantastic.registration.bean;
              
              import java.io.Serializable;
              
              public class RegistrationBean implements Serializable {
              	
              	public RegistrationBean() {
              		
              	}
              	private static final long serialVersionUID = -1619779528415908892L;
              
              	private String userName;
              	private String fullName;
              	private String email;
              	private String password;
              	
              	public String getUserName() {
              		return userName;
              	}
              	public void setUserName(String userName) {
              		this.userName = userName;
              	}
              	public String getFullName() {
              		return fullName;
              	}
              	public void setFullName(String fullName) {
              		this.fullName = fullName;
              	}
              	public String getEmail() {
              		return email;
              	}
              	public void setEmail(String email) {
              		this.email = email;
              	}
              	public String getPassword() {
              		return password;
              	}
              	public void setPassword(String password) {
              		this.password = password;
              	}
              	
              }
              dispatcher-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.0.xsd">  
                       <!-- YOUR ENTRIES HERE -->  
              
              	<bean id="viewResolver"  class="org.springframework.web.servlet.view.InternalResourceViewResolver">  
              		 <property name="viewClass">
              			<value>org.springframework.web.servlet.view.JstlView</value>
              		</property> 
              		 <property name="prefix" value="/jsp/"/>
              		 <property name="suffix" value=".jsp"/>  
              	</bean>
              	
              	<bean id="simpleUrlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">  
              		<property name="mappings">  
                 			<props>  
                 				<prop key="/registration.htm">registration</prop>
                 				<!-- <prop key="/profile.htm">profile</prop>-->
                 			</props>  
                 		</property>  
                 </bean>
                 
              	<bean id="registration" class="com.logixplayer.fantastic.registration.controller.RegistrationController">  
              	   <property name="formView" value="registration"/>  
              	   <property name="successView" value="profile/form"/>  
              	   <property name="commandName" value="registrationBean"/>  
              	   <property name="commandClass" value="com.logixplayer.fantastic.registration.bean.RegistrationBean"/>  
              	   <property name="validator">  
              	   		<bean class="com.logixplayer.fantastic.registration.validator.RegistrationValidator"/>  
              	   </property>
              	</bean>  
                 
              </beans>
              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">
                <welcome-file-list>
                  <welcome-file>/jsp/index.jsp</welcome-file>
                </welcome-file-list>
              
                  <!-- Spring MVC Configuration -->
                  <servlet>
                      <servlet-name>dispatcher</servlet-name>
                      <servlet-class>
                          org.springframework.web.servlet.DispatcherServlet
                      </servlet-class>
                      <load-on-startup>2</load-on-startup>
                  </servlet>
                  <servlet-mapping>
                      <servlet-name>dispatcher</servlet-name>
                      <url-pattern>*.htm</url-pattern>
                  </servlet-mapping>
              
              	<listener>
              		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
              	</listener>
              	<context-param>
              		<param-name>contextConfigLocation</param-name>
              		<param-value>classpath:applicationContext.xml</param-value>
              	</context-param>
              	
              	<jsp-config>
              	    <taglib>
              	      <taglib-uri>/spring</taglib-uri>
              	      <taglib-location>/WEB-INF/spring-form.tld</taglib-location>
              	    </taglib>
              	</jsp-config>
              	
              </web-app>
              index.jsp
              Code:
              <%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
              <%
              String path = request.getContextPath();
              String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
              %>
              <%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
              
              <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
              <html>
                <head>
                  <base href="<%=basePath%>">
                  
                  <title>My JSP 'index.jsp' starting page</title>
              	<meta http-equiv="pragma" content="no-cache">
              	<meta http-equiv="cache-control" content="no-cache">
              	<meta http-equiv="expires" content="0">    
              	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
              	<meta http-equiv="description" content="This is my page">
              
                </head>
                
                <body>
                  This is my JSP page. <br>
                  
                  <!-- add some links! -->
              
               
                  <a href="jsp/registration/registration.jsp">Registration</a> <br>
                  <a href="jsp/profile/login.jsp">Login</a> <br>
                  <a href='<c:url value="jsp/registration/registration.jsp"/>'>Registration!</a>
                </body>
              </html>
              and finally registration.jsp (where the PROBLEM is happening!!!)

              Code:
              <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
              <%@ page contentType="text/html;charset=UTF-8" language="java" %>  
              <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>  
              <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
              <%@ taglib uri="http://www.springframework.org/tags" prefix="spring" %>  
              
              <%
              String path = request.getContextPath();
              String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
              %>
              
              <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
              <html>
                <head>
                  <base href="<%=basePath%>">
                  
                  <title>My JSP 'registration.jsp' starting page</title>
                  
              	<meta http-equiv="pragma" content="no-cache">
              	<meta http-equiv="cache-control" content="no-cache">
              	<meta http-equiv="expires" content="0">    
              	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
              	<meta http-equiv="description" content="This is my page">
              
                </head>
                
                <body>
                  		This is my JSP page. <br>
                  		 <spring:hasBindErrors name="registrationBean">
                  		 <h3>You have errors in your input!</h3>  
              			<font color="red">  
              	             <c:forEach items="${errors.allErrors}" var="error">  
              	                 <spring:message code="${error.code}" text="${error.defaultMessage}"/>  
              	             </c:forEach>  
                       	</font>  
                   		</spring:hasBindErrors>
                   		  
                           <!-- note second way of displaying error messages by field -->  
                          <form:form commandName="registrationBean" method="POST" action="registration.htm">  
                               User Name: <form:input path="userName" /><form:errors path="userName" />  
                               Full Name: <form:input path="fullName" /><form:errors path="fullName" />  
                               Email: <form:input path="email" /><form:errors path="email" />  
                               Password: <form:password path="password" /><form:errors path="password" />  
                               <input type="submit" title="Register!" />  
              			</form:form>  
                </body>
              </html>
              PROBLEM:

              Code:
              type Exception report
              
              message
              
              description The server encountered an internal error () that prevented it from fulfilling this request.
              
              exception
              
              org.apache.jasper.JasperException: An exception occurred processing JSP page /jsp/registration/registration.jsp at line 44
              
              41:      		  
              42:              <!-- note second way of displaying error messages – by field -->  
              43:             <form:form commandName="registrationBean" method="POST" action="registration.htm">  
              44:                  User Name: <form:input path="userName" /><form:errors path="userName" />  
              45:                  Full Name: <form:input path="fullName" /><form:errors path="fullName" />  
              46:                  Email: <form:input path="email" /><form:errors path="email" />  
              47:                  Password: <form:password path="password" /><form:errors path="password" />  
              
              
              Stacktrace:
              	org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:524)
              	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:429)
              	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
              	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
              	javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
              
              root cause
              
              java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'registrationBean' available as request attribute
              	org.springframework.web.servlet.support.BindStatus.<init>(BindStatus.java:141)

              Comment


              • #8
                jsp not rendering...

                Essentially registration.jsp is not rendering...I go from index.jsp to registration.jsp, and then it just crashes with the IllegalState Exception, what gives? Does it need to go through a controller first? Thanks

                Comment


                • #9
                  Originally posted by logixplayer View Post
                  Essentially registration.jsp is not rendering...I go from index.jsp to registration.jsp, and then it just crashes with the IllegalState Exception, what gives? Does it need to go through a controller first? Thanks
                  Essentially what the issue is is this:
                  Code:
                       		<form:form commandName="registrationBean" method="POST" action="/registration.htm">
                       		User Name: <form:input path="userName" />
                       		
                       		</form:form>
                  <form:input path="userName" /> crashes....this is where the problem is happening.....*sigh*

                  I am totally stuck....

                  Comment


                  • #10
                    logixplayer,

                    You're not using your url handling mappings... you're specifying the urls to the JSP, not the controllers.

                    Look at your bean declarations:

                    Code:
                    <bean id="simpleUrlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
                        <property name="mappings">
                            <props>
                                <prop key="/registration.htm">registration</prop>
                                <!-- <prop key="/profile.htm">profile</prop>-->
                            </props>
                        </property>
                    </bean>
                       
                    <bean id="registration" class="com.logixplayer.fantastic.registration.controller.RegistrationController">
                        <property name="formView" value="registration"/>
                        <property name="successView" value="profile/form"/>
                        <property name="commandName" value="registrationBean"/>
                        <property name="commandClass" value="com.logixplayer.fantastic.registration.bean.RegistrationBean"/>
                        <property name="validator">
                            <bean class="com.logixplayer.fantastic.registration.validator.RegistrationValidator"/>
                        </property>
                    </bean>
                    and your JSP

                    Code:
                    <a href="jsp/registration/registration.jsp">Registration</a> <br>
                    <a href="jsp/profile/login.jsp">Login</a> <br>
                    That should look like:

                    Code:
                    <a href="<c:url value="/registration.htm" />">Registration</a><br/>
                    <a href="<c:url value="/login.htm" />">Login</a><br/>
                    The code for your URL should be /registration.htm not /jsp/registration/registration.jsp. All of your controllers are handled by those simpleUrlMapping handler URL mappings. Basically what you're doing is serving a regular JSP page without any of the Spring goodness because you're not linking to the controller's URL. That means your command object isn't getting populated because none of the controller code is being called. That registration formView probably isn't correct either...

                    You're going to need controllers to serve those JSP pages if you want to use the Spring dispatcher servlet to serve them as opposed to just the serving the JSP.

                    You might want to review the Reference documentation and the MVC step by step guide. Go over the petstore example as well :-) You'll probably want to use a MultiActionController to serve all the pages that aren't form controllers...

                    Hope that helps,

                    Comment


                    • #11
                      original configuration vs annotations for spring mvc

                      JPreston, thanks a lot for the guidance! I finally got that first form to get working...
                      The JPetStore tip was huge! It is a must to reference for all that are new to Spring MVC.

                      Quick questions for you or anyone else, I noticed in some cases JPetStore is using annotations like @Controller while in other places they are just using the original Spring MVC style configuration of a bean, for <successview>, <formview> etc, which one is "better" to use...or is there a benefit in using annotations?

                      thanks a lot once again!!

                      Comment


                      • #12
                        logixplayer,

                        The main reason you see the annotations in the JPetStore example is that it also supports annotation style configurations. This is not to say the it uses both at the same time, but rather as a guide to both ways. That said, I believe you can switch between the traditional and annotated styles.

                        In terms of the benefits / pros / cons, annotations will only work with Java 1.5 or newer, which means that if you're deploying to an older application server, or using Java 1.4, you'll need to avoid annotations.

                        The biggest benefit to using annotations is a simpler setup, and less XML configuration.

                        I would highly suggest that you stick with the traditional methods until you have an understanding on how things function as the annotated style behaves similarly.

                        Regards,

                        Comment

                        Working...
                        X