• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2208
  • Last Modified:

Spring MVC 3.0.5 newbie getting java.lang.IllegalStateException

I'm new to Spring MVC, and I'm upgrading a web application to Spring 3.0.5, where I'm converting the Struts 1x integration to Spring MVC. I'm trying to convert one Struts action at a time. The first one is the login action. However, I keep getting a java.lang.IllegalStateException due to a binding issue. Tried tweaking my controller and jsp several times, and still get the issue. The cdde for the controller was a former struts action and is very long. I chopped out most of it which isn't relavant to the issue. Here is the code for the controller and the jsp, and the form. Thanks.


login.jsp
--------------------
<%@page contentType="text/html"%>
<%@ include file="../WEB-INF/includes/taglib.jsp" %>
<c:set var="fullPath" value="${pageContext.request.contextPath}" />

<html>
<head>
<title>Login Screen</title>
<!-- some more stuff in here -->
</head>

<body onload="redirectLogout(findTopWindow(this));setFocus()">
<%@ page import = "java.util.StringTokenizer;" %>

<springForm:form action="${fullPath}/login.do" method="post">
    <input type="hidden" name="errorpage" id="errorpage" value="${fullPath}/login/login.jsp">
    <input type="hidden" name="target" id="target" value="${fullPath}/redirect.npf">

<table>
<tr>
<td>Username:</td>
<td>
<springForm:input path="userName"/>
</td>
</tr>
<tr>
<td>Password:</td>
<td>
<springForm:password path="password"/>
</td>
</tr>
<tr>
<td valign="middle" align="middle">
<input type="submit" value="Sign In" />
<input type="button" value="Clear" onclick="resetForm();"  class="browse" id=button1 name=button1>
</td>
</tr>
</springForm:form>


</body>
</html>

LoginForm.java
----------------
public class LoginForm {
    private String userName;
    private String password;

    public String getUserName(){
        return this.userName;
    }

    public String getPassword(){
        return this.password;
    }

    public void setUserName(String userName){
        this.userName = userName;
    }

    public void setPassword(String password){
        this.password = password;
    }
}


LoginController.java
---------------------------
@Controller
public class LoginController {
private static final Logger logger = Logger.getLogger( LoginController.class );

@RequestMapping(value="login.do", method=RequestMethod.GET)
    public String LoginForm(Model model){
        model.addAttribute("login", new LoginForm());
        return "login";
    }

@RequestMapping(value="login", method=RequestMethod.POST)
public ModelAndView processSubmit(@ModelAttribute("login") LoginForm loginForm, BindingResult result, HttpServletRequest req, MessageSource msgSrc){

ModelAndView mav = new ModelAndView();
String userName = loginForm.getUserName();
String formPassword = loginForm.getPassword();
if(userName == null || formPassword == null)
        {
            mav.setViewName("login");
            return mav;
        }

mav.setViewName("homePage");
return mav;
}

    mav.addObject("userName", req.getParameter("userName"));
    mav.addObject("password", req.getParameter("password"));
    mav.setViewName(target);
    return mav;

    }
}

Open in new window

0
jewel70
Asked:
jewel70
  • 3
  • 3
  • 2
  • +1
3 Solutions
 
mrcoffee365Commented:
It would help if you would post the exception, with the whole stack and note the line number it matches in your code (since you didn't post all your code, which is good for long programs).
0
 
jewel70Author Commented:
Sorry about that. The file login_jsp.java is attached.  Here is the stacktrace. Error occurs when it reaches the userName input in the Spring form.

[ERROR org.springframework.web.servlet.tags.RequestContextAwareTag 86] Neither BindingResult nor plain target object for bean name 'command' available as request attribute
java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'command' 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:174)
      at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getPropertyPath(AbstractDataBoundFormElementTag.java:194)
      at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getName(AbstractDataBoundFormElementTag.java:160)
      at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.autogenerateId(AbstractDataBoundFormElementTag.java:147)
      at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.resolveId(AbstractDataBoundFormElementTag.java:138)
      at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.writeDefaultAttributes(AbstractDataBoundFormElementTag.java:122)
      at org.springframework.web.servlet.tags.form.AbstractHtmlElementTag.writeDefaultAttributes(AbstractHtmlElementTag.java:408)
      at org.springframework.web.servlet.tags.form.InputTag.writeTagContent(InputTag.java:140)
      at org.springframework.web.servlet.tags.form.AbstractFormTag.doStartTagInternal(AbstractFormTag.java:102)
      at org.springframework.web.servlet.tags.RequestContextAwareTag.doStartTag(RequestContextAwareTag.java:79)
      at org.apache.jsp.login.login_jsp._jspx_meth_springForm_005finput_005f0(login_jsp.java:353)
      at org.apache.jsp.login.login_jsp._jspx_meth_springForm_005fform_005f0(login_jsp.java:275)
      at org.apache.jsp.login.login_jsp._jspService(login_jsp.java:190)
      at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
      at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
      at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
      at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      at org.ddpa.npf.utils.admin.AuthenticationFilter.doFilter(AuthenticationFilter.java:87)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
      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:191)
      at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433)
      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:286)
      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
      at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
      at java.lang.Thread.run(Thread.java:619)
package org.apache.jsp.login;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;
import java.util.StringTokenizer;;

public final class login_jsp extends org.apache.jasper.runtime.HttpJspBase
    implements org.apache.jasper.runtime.JspSourceDependent {

  private static final JspFactory _jspxFactory = JspFactory.getDefaultFactory();

  private static java.util.List _jspx_dependants;

  static {
    _jspx_dependants = new java.util.ArrayList(9);
    _jspx_dependants.add("/login/../WEB-INF/includes/taglib.jsp");
    _jspx_dependants.add("/WEB-INF/tld/struts-logic.tld");
    _jspx_dependants.add("/WEB-INF/tld/struts-html.tld");
    _jspx_dependants.add("/WEB-INF/tld/struts-bean.tld");
    _jspx_dependants.add("/WEB-INF/tld/struts-nested.tld");
    _jspx_dependants.add("/WEB-INF/tld/struts-tiles.tld");
    _jspx_dependants.add("/WEB-INF/tld/displaytag.tld");
    _jspx_dependants.add("/WEB-INF/tld/npf-custom.tld");
    _jspx_dependants.add("/WEB-INF/tld/npf-authorisation.tld");
  }

  private org.apache.jasper.runtime.TagHandlerPool _005fjspx_005ftagPool_005fc_005fset_0026_005fvar_005fvalue_005fnobody;
  private org.apache.jasper.runtime.TagHandlerPool _005fjspx_005ftagPool_005fspringForm_005fform_0026_005fmethod_005faction;
  private org.apache.jasper.runtime.TagHandlerPool _005fjspx_005ftagPool_005fspringForm_005finput_0026_005fpath_005fnobody;
  private org.apache.jasper.runtime.TagHandlerPool _005fjspx_005ftagPool_005fspringForm_005fpassword_0026_005fpath_005fnobody;

  private javax.el.ExpressionFactory _el_expressionfactory;
  private org.apache.AnnotationProcessor _jsp_annotationprocessor;

  public Object getDependants() {
    return _jspx_dependants;
  }

  public void _jspInit() {
    _005fjspx_005ftagPool_005fc_005fset_0026_005fvar_005fvalue_005fnobody = org.apache.jasper.runtime.TagHandlerPool.getTagHandlerPool(getServletConfig());
    _005fjspx_005ftagPool_005fspringForm_005fform_0026_005fmethod_005faction = org.apache.jasper.runtime.TagHandlerPool.getTagHandlerPool(getServletConfig());
    _005fjspx_005ftagPool_005fspringForm_005finput_0026_005fpath_005fnobody = org.apache.jasper.runtime.TagHandlerPool.getTagHandlerPool(getServletConfig());
    _005fjspx_005ftagPool_005fspringForm_005fpassword_0026_005fpath_005fnobody = org.apache.jasper.runtime.TagHandlerPool.getTagHandlerPool(getServletConfig());
    _el_expressionfactory = _jspxFactory.getJspApplicationContext(getServletConfig().getServletContext()).getExpressionFactory();
    _jsp_annotationprocessor = (org.apache.AnnotationProcessor) getServletConfig().getServletContext().getAttribute(org.apache.AnnotationProcessor.class.getName());
  }

  public void _jspDestroy() {
    _005fjspx_005ftagPool_005fc_005fset_0026_005fvar_005fvalue_005fnobody.release();
    _005fjspx_005ftagPool_005fspringForm_005fform_0026_005fmethod_005faction.release();
    _005fjspx_005ftagPool_005fspringForm_005finput_0026_005fpath_005fnobody.release();
    _005fjspx_005ftagPool_005fspringForm_005fpassword_0026_005fpath_005fnobody.release();
  }

  public void _jspService(HttpServletRequest request, HttpServletResponse response)
        throws java.io.IOException, ServletException {

    PageContext pageContext = null;
    HttpSession session = null;
    ServletContext application = null;
    ServletConfig config = null;
    JspWriter out = null;
    Object page = this;
    JspWriter _jspx_out = null;
    PageContext _jspx_page_context = null;


    try {
      response.setContentType("text/html");
      pageContext = _jspxFactory.getPageContext(this, request, response,
      			null, true, 8192, true);
      _jspx_page_context = pageContext;
      application = pageContext.getServletContext();
      config = pageContext.getServletConfig();
      session = pageContext.getSession();
      out = pageContext.getOut();
      _jspx_out = out;

      out.write('\n');
      out.write("\n");
      out.write("\n");
      out.write("\n");
      out.write("\n");
      out.write("\n");
      out.write("\n");
      out.write("\n");
      out.write("\n");
      out.write("\n");
      out.write("\n");
      out.write("\n");
      out.write("\n");
      out.write("\n");
      out.write("\n");
      out.write("\n");
      out.write("\n");
      out.write('\n');
      if (_jspx_meth_c_005fset_005f0(_jspx_page_context))
        return;
      out.write("\n");
      out.write("\n");
      out.write("<html>\n");
      out.write("<head>\n");
      out.write("<title>Login Screen</title>\n");
      out.write("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">\n");
      out.write("\n");
      out.write("<!-- General Stylesheet -->\n");
      out.write("<link rel=\"stylesheet\" href=\"");
      out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${fullPath}", java.lang.String.class, (PageContext)_jspx_page_context, null, false));
      out.write("/css/npfstyle.css\" type=\"text/css\">\n");
      out.write("<link rel=\"stylesheet\" type=\"text/css\" media=\"screen\" href=\"");
      out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${fullPath}", java.lang.String.class, (PageContext)_jspx_page_context, null, false));
      out.write("/css/npfstyle.css\" /> \n");
      out.write("\n");
      out.write("<!-- CRM Landing Stylesheet -->\n");
      out.write("<link rel=\"stylesheet\" href=\"");
      out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${fullPath}", java.lang.String.class, (PageContext)_jspx_page_context, null, false));
      out.write("/css/npf_queryArea.css\" type=\"text/css\">\n");
      out.write("\n");
      out.write("<!-- JS -->\n");
      out.write("<script>\n");
      out.write("\n");
      out.write("function loadIframe(iframeName, url) {\n");
      out.write("  if ( window.frames[iframeName] ) {\n");
      out.write("    window.frames[iframeName].location = url;   \n");
      out.write("    return false;\n");
      out.write("  }\n");
      out.write("  else return true;\n");
      out.write("}\n");
      out.write("\n");
      out.write("//clear the form\n");
      out.write("function resetForm(){\n");
      out.write("        document.getElementById(\"userName\").value=\"\";\n");
      out.write("        document.getElementById(\"password\").value=\"\";\n");
      out.write("        //reset form focus\n");
      out.write("        document.getElementById(\"userName\").focus();\n");
      out.write("  return true\n");
      out.write("}\n");
      out.write("\n");
      out.write("function setFocus() {\n");
      out.write("    document.getElementById(\"userName\").focus();\n");
      out.write("}\n");
      out.write("\n");
      out.write("\n");
      out.write("/*\n");
      out.write("\tGo up the dom to find the top most window.\n");
      out.write("\tThe top most window is the application desktop.\n");
      out.write("*/\n");
      out.write("function findTopWindow(childWindow){\n");
      out.write("\tif(childWindow.top==childWindow){\n");
      out.write("\t\treturn childWindow;\n");
      out.write("\t}else{\n");
      out.write("\t\treturn findTopWindow(childWindow.top);\n");
      out.write("\t}\n");
      out.write("}\n");
      out.write("\n");
      out.write("  /*\n");
      out.write("    If a forced logout occurs, for example session timeout,\n");
      out.write("    make sure that the loging page appears in the top level window.\n");
      out.write("  */\n");
      out.write("  function redirectLogout(iframe){      \n");
      out.write("    if(iframe != window){\n");
      out.write("      iframe.document.location.href=document.location.href; //frame.document.URL;\n");
      out.write("      }  \n");
      out.write("  }\n");
      out.write("\n");
      out.write("</script>\n");
      out.write("\n");
      out.write("</head>\n");
      out.write("\n");
      out.write("\n");
      out.write("<body onload=\"redirectLogout(findTopWindow(this));setFocus()\">\n");
      out.write("\n");
      out.write("\n");
      out.write("<!-- Top Application Buttons -->\n");
      out.write("<div id=\"topButtons\">\n");
      out.write("  <table cellpadding=\"0\" cellspacing=\"0\" border=\"0\">\n");
      out.write("    <tr>\n");
      out.write("     <td>&nbsp;</td>\n");
      out.write("    </tr></table>\n");
      out.write(" </div>\n");
      out.write("</br>\n");
      out.write("</br>\n");
      out.write("\n");
      out.write("\n");
      out.write("\n");
      out.write("\n");
      out.write("<!-- *********************************** NAVIGATION *********************************** -->\n");
      out.write('\n');
      if (_jspx_meth_springForm_005fform_005f0(_jspx_page_context))
        return;
      out.write("\n");
      out.write("\n");
      out.write("\n");
      out.write("</body>\n");
      out.write("</html>\n");
      out.write("\n");
      out.write("\n");
      out.write("\n");
    } catch (Throwable t) {
      if (!(t instanceof SkipPageException)){
        out = _jspx_out;
        if (out != null && out.getBufferSize() != 0)
          try { out.clearBuffer(); } catch (java.io.IOException e) {}
        if (_jspx_page_context != null) _jspx_page_context.handlePageException(t);
      }
    } finally {
      _jspxFactory.releasePageContext(_jspx_page_context);
    }
  }

  private boolean _jspx_meth_c_005fset_005f0(PageContext _jspx_page_context)
          throws Throwable {
    PageContext pageContext = _jspx_page_context;
    JspWriter out = _jspx_page_context.getOut();
    //  c:set
    org.apache.taglibs.standard.tag.rt.core.SetTag _jspx_th_c_005fset_005f0 = (org.apache.taglibs.standard.tag.rt.core.SetTag) _005fjspx_005ftagPool_005fc_005fset_0026_005fvar_005fvalue_005fnobody.get(org.apache.taglibs.standard.tag.rt.core.SetTag.class);
    _jspx_th_c_005fset_005f0.setPageContext(_jspx_page_context);
    _jspx_th_c_005fset_005f0.setParent(null);
    // /login/login.jsp(3,0) name = var type = java.lang.String reqTime = false required = false fragment = false deferredValue = false expectedTypeName = null deferredMethod = false methodSignature = null
    _jspx_th_c_005fset_005f0.setVar("fullPath");
    // /login/login.jsp(3,0) name = value type = null reqTime = true required = false fragment = false deferredValue = false expectedTypeName = null deferredMethod = false methodSignature = null
    _jspx_th_c_005fset_005f0.setValue((java.lang.Object) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${pageContext.request.contextPath}", java.lang.Object.class, (PageContext)_jspx_page_context, null, false));
    int _jspx_eval_c_005fset_005f0 = _jspx_th_c_005fset_005f0.doStartTag();
    if (_jspx_th_c_005fset_005f0.doEndTag() == javax.servlet.jsp.tagext.Tag.SKIP_PAGE) {
      _005fjspx_005ftagPool_005fc_005fset_0026_005fvar_005fvalue_005fnobody.reuse(_jspx_th_c_005fset_005f0);
      return true;
    }
    _005fjspx_005ftagPool_005fc_005fset_0026_005fvar_005fvalue_005fnobody.reuse(_jspx_th_c_005fset_005f0);
    return false;
  }

  private boolean _jspx_meth_springForm_005fform_005f0(PageContext _jspx_page_context)
          throws Throwable {
    PageContext pageContext = _jspx_page_context;
    JspWriter out = _jspx_page_context.getOut();
    //  springForm:form
    org.springframework.web.servlet.tags.form.FormTag _jspx_th_springForm_005fform_005f0 = (org.springframework.web.servlet.tags.form.FormTag) _005fjspx_005ftagPool_005fspringForm_005fform_0026_005fmethod_005faction.get(org.springframework.web.servlet.tags.form.FormTag.class);
    _jspx_th_springForm_005fform_005f0.setPageContext(_jspx_page_context);
    _jspx_th_springForm_005fform_005f0.setParent(null);
    // /login/login.jsp(87,0) name = action type = null reqTime = true required = false fragment = false deferredValue = false expectedTypeName = null deferredMethod = false methodSignature = null
    _jspx_th_springForm_005fform_005f0.setAction((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${fullPath}/login.do", java.lang.String.class, (PageContext)_jspx_page_context, null, false));
    // /login/login.jsp(87,0) name = method type = null reqTime = true required = false fragment = false deferredValue = false expectedTypeName = null deferredMethod = false methodSignature = null
    _jspx_th_springForm_005fform_005f0.setMethod("post");
    int[] _jspx_push_body_count_springForm_005fform_005f0 = new int[] { 0 };
    try {
      int _jspx_eval_springForm_005fform_005f0 = _jspx_th_springForm_005fform_005f0.doStartTag();
      if (_jspx_eval_springForm_005fform_005f0 != javax.servlet.jsp.tagext.Tag.SKIP_BODY) {
        do {
          out.write("\n");
          out.write("    <input type=\"hidden\" name=\"errorpage\" id=\"errorpage\" value=\"");
          out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${fullPath}", java.lang.String.class, (PageContext)_jspx_page_context, null, false));
          out.write("/login/login.jsp\">\n");
          out.write("    <input type=\"hidden\" name=\"target\" id=\"target\" value=\"");
          out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${fullPath}", java.lang.String.class, (PageContext)_jspx_page_context, null, false));
          out.write("/redirect.npf\">\n");
          out.write("\n");
          out.write("    <table width=\"487\" border=\"1\" cellspacing=\"0\" cellpadding=\"5\" align=\"center\" bordercolor=\"#B9CBCD\" height=\"219\" class = \"login\">\n");
          out.write("        <tr valign=\"top\">\n");
          out.write("            <td width=\"267\" height=\"357\"><img src=\"");
          out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${fullPath}", java.lang.String.class, (PageContext)_jspx_page_context, null, false));
          out.write("/images/login/npf-login-image.jpg\" width=\"267\" height=\"357\"></td>\n");
          out.write("            <td width=\"388\" height=\"287\" valign=\"middle\">\n");
          out.write("            <table width=\"188\" border=\"0\" cellspacing=\"5\" cellpadding=\"5\">\n");
          out.write("                <tr>\n");
          out.write("                    <td class = \"loginheader\" align=\"center\" valign=\"middle\">Welcome to the National Provider File</td>\n");
          out.write("                </tr>\n");
          out.write("                <tr>\n");
          out.write("                    <td valign=\"middle\">\n");
          out.write("                        <table width=\"0%\" border=\"0\" cellspacing=\"5\" cellpadding=\"5\">\n");
          out.write("                            <tr>\n");
          out.write("                                <td width=\"98\" class=\"logintext\">Username:</td>\n");
          out.write("                                <td width=\"173\">\n");
          out.write("                                    ");
          if (_jspx_meth_springForm_005finput_005f0(_jspx_th_springForm_005fform_005f0, _jspx_page_context, _jspx_push_body_count_springForm_005fform_005f0))
            return true;
          out.write("\n");
          out.write("                                </td>\n");
          out.write("                            </tr>\n");
          out.write("                            <tr>\n");
          out.write("                                <td class = \"logintext\">Password:</td>\n");
          out.write("                                <td>\n");
          out.write("                                    ");
          if (_jspx_meth_springForm_005fpassword_005f0(_jspx_th_springForm_005fform_005f0, _jspx_page_context, _jspx_push_body_count_springForm_005fform_005f0))
            return true;
          out.write("\n");
          out.write("                                </td>\n");
          out.write("                            </tr>\n");
          out.write("                        </table>\n");
          out.write("                    </td>\n");
          out.write("                </tr>\n");
          out.write("                <tr>\n");
          out.write("                    <td valign=\"middle\" align=\"middle\">\n");
          out.write("                        <input type=\"submit\" value=\"Sign In\" />\n");
          out.write("                        <input type=\"button\" value=\"Clear\" onclick=\"resetForm();\"  class=\"browse\" id=button1 name=button1>\n");
          out.write("                        <br>\n");
          out.write("                        <br>\n");
          out.write("                    </td>\n");
          out.write("                </tr>\n");
          out.write("            \n");
          out.write("                <tr>\n");
          out.write("                    <td class=\"loginInstructions\" align=\"center\" valign=\"middle\">\n");
          out.write("           \t \t\t    ");
          out.write("\n");
          out.write("                        ");
          out.write("\n");
          out.write("                        ");
          out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${message}", java.lang.String.class, (PageContext)_jspx_page_context, null, false));
          out.write("\n");
          out.write("                    </td>\n");
          out.write("                </tr>\n");
          out.write("\n");
          out.write("                <tr>\n");
          out.write("                    <td valign=\"middle\">&nbsp;</td>\n");
          out.write("                </tr>\n");
          out.write("        \n");
          out.write("            </table>\n");
          out.write("            </td>\n");
          out.write("        </tr>\n");
          out.write("\n");
          out.write("    </table>\n");
          int evalDoAfterBody = _jspx_th_springForm_005fform_005f0.doAfterBody();
          if (evalDoAfterBody != javax.servlet.jsp.tagext.BodyTag.EVAL_BODY_AGAIN)
            break;
        } while (true);
      }
      if (_jspx_th_springForm_005fform_005f0.doEndTag() == javax.servlet.jsp.tagext.Tag.SKIP_PAGE) {
        return true;
      }
    } catch (Throwable _jspx_exception) {
      while (_jspx_push_body_count_springForm_005fform_005f0[0]-- > 0)
        out = _jspx_page_context.popBody();
      _jspx_th_springForm_005fform_005f0.doCatch(_jspx_exception);
    } finally {
      _jspx_th_springForm_005fform_005f0.doFinally();
      _005fjspx_005ftagPool_005fspringForm_005fform_0026_005fmethod_005faction.reuse(_jspx_th_springForm_005fform_005f0);
    }
    return false;
  }

  private boolean _jspx_meth_springForm_005finput_005f0(javax.servlet.jsp.tagext.JspTag _jspx_th_springForm_005fform_005f0, PageContext _jspx_page_context, int[] _jspx_push_body_count_springForm_005fform_005f0)
          throws Throwable {
    PageContext pageContext = _jspx_page_context;
    JspWriter out = _jspx_page_context.getOut();
    //  springForm:input
    org.springframework.web.servlet.tags.form.InputTag _jspx_th_springForm_005finput_005f0 = (org.springframework.web.servlet.tags.form.InputTag) _005fjspx_005ftagPool_005fspringForm_005finput_0026_005fpath_005fnobody.get(org.springframework.web.servlet.tags.form.InputTag.class);
    _jspx_th_springForm_005finput_005f0.setPageContext(_jspx_page_context);
    _jspx_th_springForm_005finput_005f0.setParent((javax.servlet.jsp.tagext.Tag) _jspx_th_springForm_005fform_005f0);
    // /login/login.jsp(105,36) name = path type = null reqTime = true required = true fragment = false deferredValue = false expectedTypeName = null deferredMethod = false methodSignature = null
    _jspx_th_springForm_005finput_005f0.setPath("userName");
    int[] _jspx_push_body_count_springForm_005finput_005f0 = new int[] { 0 };
    try {
      int _jspx_eval_springForm_005finput_005f0 = _jspx_th_springForm_005finput_005f0.doStartTag();
      if (_jspx_th_springForm_005finput_005f0.doEndTag() == javax.servlet.jsp.tagext.Tag.SKIP_PAGE) {
        return true;
      }
    } catch (Throwable _jspx_exception) {
      while (_jspx_push_body_count_springForm_005finput_005f0[0]-- > 0)
        out = _jspx_page_context.popBody();
      _jspx_th_springForm_005finput_005f0.doCatch(_jspx_exception);
    } finally {
      _jspx_th_springForm_005finput_005f0.doFinally();
      _005fjspx_005ftagPool_005fspringForm_005finput_0026_005fpath_005fnobody.reuse(_jspx_th_springForm_005finput_005f0);
    }
    return false;
  }

  private boolean _jspx_meth_springForm_005fpassword_005f0(javax.servlet.jsp.tagext.JspTag _jspx_th_springForm_005fform_005f0, PageContext _jspx_page_context, int[] _jspx_push_body_count_springForm_005fform_005f0)
          throws Throwable {
    PageContext pageContext = _jspx_page_context;
    JspWriter out = _jspx_page_context.getOut();
    //  springForm:password
    org.springframework.web.servlet.tags.form.PasswordInputTag _jspx_th_springForm_005fpassword_005f0 = (org.springframework.web.servlet.tags.form.PasswordInputTag) _005fjspx_005ftagPool_005fspringForm_005fpassword_0026_005fpath_005fnobody.get(org.springframework.web.servlet.tags.form.PasswordInputTag.class);
    _jspx_th_springForm_005fpassword_005f0.setPageContext(_jspx_page_context);
    _jspx_th_springForm_005fpassword_005f0.setParent((javax.servlet.jsp.tagext.Tag) _jspx_th_springForm_005fform_005f0);
    // /login/login.jsp(111,36) name = path type = null reqTime = true required = true fragment = false deferredValue = false expectedTypeName = null deferredMethod = false methodSignature = null
    _jspx_th_springForm_005fpassword_005f0.setPath("password");
    int[] _jspx_push_body_count_springForm_005fpassword_005f0 = new int[] { 0 };
    try {
      int _jspx_eval_springForm_005fpassword_005f0 = _jspx_th_springForm_005fpassword_005f0.doStartTag();
      if (_jspx_th_springForm_005fpassword_005f0.doEndTag() == javax.servlet.jsp.tagext.Tag.SKIP_PAGE) {
        return true;
      }
    } catch (Throwable _jspx_exception) {
      while (_jspx_push_body_count_springForm_005fpassword_005f0[0]-- > 0)
        out = _jspx_page_context.popBody();
      _jspx_th_springForm_005fpassword_005f0.doCatch(_jspx_exception);
    } finally {
      _jspx_th_springForm_005fpassword_005f0.doFinally();
      _005fjspx_005ftagPool_005fspringForm_005fpassword_0026_005fpath_005fnobody.reuse(_jspx_th_springForm_005fpassword_005f0);
    }
    return false;
  }
}

Open in new window

0
 
mrcoffee365Commented:
Thanks -- that helped.

I think you're hitting a problem with how you have tried to manage the results.  I found this discussion which says that if you take over the behavior of the Spring model of submit -- putting extra fields in and handling errors -- then you'll get an error like this.  I expected to see something called "command" though and couldn't find it in the code you posted.

Discussion of similar problem:
http://forum.springsource.org/showthread.php?37068-Neither-BindingResult-nor-plain-target-object-for-bean-name-command-available

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
objectsCommented:
looks like the form expects a bean of name 'command' to contain the values for the forms but you have named it 'login'


public ModelAndView processSubmit(@ModelAttribute("login") LoginForm loginForm, BindingResult result, HttpServletRequest req, MessageSource msgSrc){

try changing that to:


public ModelAndView processSubmit(@ModelAttribute("command") LoginForm loginForm, BindingResult result, HttpServletRequest req, MessageSource msgSrc){
0
 
mrcoffee365Commented:
Right -- I just don't see where the bean is named "command" -- it seems to be "login" in everything posted.

If the poster changes the ModelAndView line, then I think a few of the other config files and code have to be changed, too.
0
 
jewel70Author Commented:
I've seen examples using modelAttribute and command. In the process of research I read somewhere that using modelAttribute is preferred to using command when working with forms in Spring MVC as of version 3x. I'm starting a class tomorrow for Spring web apps. I'll ask the trainer about it. I was able to replicate my same issue with a much smaller Hello World type application, by the way. This would be easier to work with. Attached is the whole thing: controller, form bean, web.xml, spring config xml, and the jsp. The stack follows after the code. It's the same error.  
web.xml
---------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<web-app 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"
           version="2.5">


    <display-name>Spring3MVC</display-name>

    <welcome-file-list>
        <welcome-file>enterName.jsp</welcome-file>
    </welcome-file-list>

    <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>

    <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>/</url-pattern>
    </servlet-mapping>


spring-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"
           xmlns:p="http://www.springframework.org/schema/p"
           xmlns:mvc="http://www.springframework.org/schema/mvc"
           xmlns:context="http://www.springframework.org/schema/context"
           xsi:schemaLocation="http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
           http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
           http://www.springframework.org/schema/context
           http://www.springframework.org/schema/context/spring-context-3.0.xsd">

        <mvc:annotation-driven />

        <context:component-scan  base-package="org.ddpa.npf.controllers" />

        <bean id="viewResolver"
            class="org.springframework.web.servlet.view.UrlBasedViewResolver">
            <property name="viewClass"
                      value="org.springframework.web.servlet.view.JstlView" />
            <property name="prefix" value="/WEB-INF/jsp/" />
            <property name="suffix" value=".jsp" />
        </bean>
    </beans>


enterName.jsp
----------------------------------------------------------
<%@ taglib prefix="sf" uri="http://www.springframework.org/tags/form" %>

<html>
    <head>
        <title>Enter Name</title>

        <style>
            .error {
    	        color: red;
            }
        </style>
    </head>

    <body>
    <center>
        <h1>Enter your Name</h1>

        <sf:form action="/hello.html" modelAttribute="user" method="post">
            <sf:label path="userName">Name:</sf:label>
            <sf:input path="userName"/>
            

            <input type="submit" value="Submit Name" />
        </sf:form>

    </center>
    </body>
</html>

user.java
--------------------------------------------------

public class User {
    private String userName;

    public String getUserName(){
        return this.userName;
    }

    public void setUserName(String name){
        this.userName = name;
    }
}


EnterNameController.java
--------------------------------------------------

@Controller
@RequestMapping("/hello.html")
public class EnterNameController {

    @RequestMapping(method=RequestMethod.GET)
    public User form() {return new User();}


    @RequestMapping(method=RequestMethod.POST)
    public String processFormData(@ModelAttribute("user") User user, Model model) {
              model.addAttribute("user", user);
        return "hello";
    }
}


hello.jsp
---------------------------------------------------
<html>
    <head>
        <title>Spring 3.0 MVC: Hello World</title>
    </head>
    <body>
        <center>
            <h1>Hello, ${user.userName}</h1>
        </center>
    </body>
</html>


Finally the stacktrace
----------------------------------------------------------

May 9, 2011 10:56:01 PM org.springframework.web.servlet.tags.RequestContextAwareTag doStartTag
SEVERE: Neither BindingResult nor plain target object for bean name 'user' available as request attribute
java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'user' 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:174)
	at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getPropertyPath(AbstractDataBoundFormElementTag.java:194)
	at org.springframework.web.servlet.tags.form.LabelTag.autogenerateFor(LabelTag.java:129)
	at org.springframework.web.servlet.tags.form.LabelTag.resolveFor(LabelTag.java:119)
	at org.springframework.web.servlet.tags.form.LabelTag.writeTagContent(LabelTag.java:89)
	at org.springframework.web.servlet.tags.form.AbstractFormTag.doStartTagInternal(AbstractFormTag.java:102)
	at org.springframework.web.servlet.tags.RequestContextAwareTag.doStartTag(RequestContextAwareTag.java:79)
	at org.apache.jsp.enterName_jsp._jspx_meth_sf_005flabel_005f0(enterName_jsp.java:163)
	at org.apache.jsp.enterName_jsp._jspx_meth_sf_005fform_005f0(enterName_jsp.java:121)
	at org.apache.jsp.enterName_jsp._jspService(enterName_jsp.java:81)
	at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
	at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
	at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
	at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
	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:191)
	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:286)
	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
	at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
	at java.lang.Thread.run(Thread.java:619)

Open in new window

0
 
objectsCommented:
you can name it whatever you want but if you don't specify it the default is 'command'
0
 
Kevin CrossChief Technology OfficerCommented:
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0
 
jewel70Author Commented:
Sorry, resolved the issue myself. Part of the issue was due to a filter.
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 3
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now