Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8016067
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T20:26:16+00:00 2026-06-04T20:26:16+00:00

I’m using Spring (3.1), Spring MVC (3.1) and Spring Security (3.0) in combination and

  • 0

I’m using Spring (3.1), Spring MVC (3.1) and Spring Security (3.0) in combination and I’ve put together a single JSP page that has two forms on it; One is a form to login and the other is a form to register (i.e. create a new user).

For the register form, I use the Spring form tags, backed up by a controller to handle the request but for the login form I don’t bother with the Spring form tags as I don’t believe they’re needed. There is also no controller that I need to write to handle the form submission as Spring Security takes care of authenticating so long as the request is submitted to j_spring_security_check.

The register form is working fine but the login form is a problem. It seems that when I click the submit button on the login form, the registration form is also submitted, or at least Spring thinks I’m trying to submit that form. Here is the JSP:

    <form id="loginform" method="POST" action="<c:url value='j_spring_security_check'/>">
        <label for="existing_email">Email:</label> 
        <input name="j_username" id="existing_email" type="text" value="${SPRING_SECURITY_LAST_USERNAME}" /> 

        <label for="existing_password">Password:</label> 
        <input name="j_password" id="existing_password" type="password" /> 

        <input id="login-form-submit" type="submit" value="Sign in" />
    </form>

    <form:form id="registrationform" modelAttribute="user" method="POST" action="register">
        <form:label path="username" for="email">Email:</form:label> 
        <form:input path="username" name="username" id="email" type="text" /> 
        <form:errors path="username" cssClass="formError" />

        <form:label path="password" for="password">Password:</form:label>
        <form:input path="password" name="password" id="password" type="password" />
        <form:errors path="password" cssClass="formError" />

        <input id="registration-form-submit" type="submit" value="Sign up" />
    </form:form>

Notice that form tags for the input of type submit are not present and this seems to be a normal thing to do in the examples I’ve seen. Adding form tags to the submit button I guess doesn’t make sense as it doesn’t map to anything on the target object (user in this case).

When I click the “Sign in” button I get the following exception:

SEVERE: Servlet.service() for servlet [appServlet] in context with path [/project1] threw exception [An exception occurred processing JSP page /WEB-INF/views/registration.jsp at line 29
28:         <form:form id="registrationform" modelAttribute="user" method="POST" action="register">
29:             <form:label path="username" for="username">Username:</form:label> 
30:             <form:input path="username" name="username" id="username" type="text" />
31:             <form:errors path="username" cssClass="formError" />
32:              


Stacktrace:] with root cause
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)

This I recognise from cases where you forget to include the modelAttribute attribute in form:form, but of course I don’t want to submit this form to my controller.

I have a feeling there is a mistake I’m making or a simple solution. Can anyone recommend a way around this or perhaps a different approach?

Here is the controller method that handles requests to register in case that’s needed:

    @RequestMapping(value = "**/register", method = RequestMethod.POST)
    public String registerUser(@ModelAttribute("user") @Validated User user, BindingResult errors, ModelMap model) {
        if (errors.hasErrors()) {
            return "registration";
        }
        // Other stuff then...
        return "profile"
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T20:26:18+00:00Added an answer on June 4, 2026 at 8:26 pm

    If you are using “user” modelAttribute in form tag then a non-null request attribute must be present with name “user”.

    One way to add that in request attribute is what you did in your answer above. Other ways are:

    (1) Add in ModelMap:

        @RequestMapping(value = "/loginfailed", method = RequestMethod.GET)
    public String loginFailed(ModelMap model) {
        model.addAttribute("user", new User());
        model.addAttribute("error", "true");
        return "registration";
    }  
    

    (2) Add in request scope (Using WebRequest or HttpServletRequest):

        @RequestMapping(value = "/loginfailed", method = RequestMethod.GET)
    public String loginFailed(ModelMap model, WebRequest webRequest) {
       webRequest.setAttribute("user", new User(), WebRequest.SCOPE_REQUEST);
        model.addAttribute("error", "true");
        return "registration";
    }  
    

    (3) Use @ModelAttribute on method:

        @ModelAttribute("user")
    public User user() {
        return new User();
    }  
    

    Please also see Using @ModelAttribute on a method and Using @ModelAttribute on a method argument

    Also note that you don’t have to use type attribute. See form:input and form:password.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I've got a string that has curly quotes in it. I'd like to replace
I'm trying to create an if statement in PHP that prevents a single post
I'm making a simple page using Google Maps API 3. My first. One marker
I want to count how many characters a certain string has in PHP, but
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.