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 8493971
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T23:10:08+00:00 2026-06-10T23:10:08+00:00

For example, I want to execute the initRegister method in Controller only after a

  • 0

For example, I want to execute the “initRegister” method in Controller only after a user click the “Register” button in the page

@Controller
public class UserController
{

    @RequestMapping(method=RequestMethod.GET, value="/initPage.do")
    public String initPage(Model model)
    {
        return "home.jsp";
    }

    @RequestMapping(method=RequestMethod.GET, value="/initRegister.do")
    @ResponseBody
    public void initRegister(Model model)
    {
        model.addAttribute("reg", new RegisterForm());
    }
}

JQuery AJAX invoked by “Register” button: (show a small popup window for registration)

$.get('initRegister.do', function()
            { 
               $('body').append('<div>'
                   +'<form:form method="POST" modelAttribute="reg" '
                   + 'commandName="reg" action="register.do">'
                   + 'name: <form:input path="name"/>'
                   + '<input type="submit" value="Submit">'
                   + '</form:form>'
                   + '</div>');
            }
      );

However I got the following error in the browser when I access “http://localhost:8080/…/initPage.do&#8221;

Neither BindingResult nor plain target object for bean name 'reg' available as request attribute

The page works only if I move “model.addAttribute(“reg”, new RegisterForm());” to “initPage” method. But I don’t need to create a RegisterForm instance until a uesr click “Register” button.

How to solve it?

  • 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-10T23:10:10+00:00Added an answer on June 10, 2026 at 11:10 pm

    I’m assuming this code is contained within home.jsp

    $.get('initRegister.do', function()
            { 
               $('body').append('<div>'
                   +'<form:form method="POST" modelAttribute="reg" '
                   + 'commandName="reg" action="register.do">'
                   + 'name: <form:input path="name"/>'
                   + '<input type="submit" value="Submit">'
                   + '</form:form>'
                   + '</div>');
            }
      );
    

    You just can’t do this. The form:form tag is processed on the server side when the initPage.do is rendered because it’s a JSP tag and means nothing in javascript or html. I’m amazed you got as meaningful a message as you did.

    When rendering JSP, it doesn’t care if the tags are in HTML, javascript, wherever. If it sees a JSP tag it’s going to perform appropriate processing. Trying to render the JSP code into the html page in response to an AJAX call just isn’t going to work because the processing of the JSP tags must happen on the server.

    Typically you will want to return an object in JSON format (or XML I guess) and use that in the javascript. have a look at the docs for jQuery’s get command. Your function for the success handler has a ‘data’ parameter that will contain the response from your Ajax call. In order for that to work you should change the return type of initRegister from void to something else. You can use Jackson to do the conversion from POJO to JSON.

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

Sidebar

Related Questions

For example I want to execute something when user clicks on a button. Which
I only want to execute a method call when the user clicks on a
I want to execute a static method from certain class in certain namespace, but
I want to execute an asynchronous callback when exit event is emitted. For example:
Suppose I want to execute code, for example value += 5 inside a namespace
I want to execute a semi-complex query in Django. For example I want something
I want to execute with Eclipse the example code provided from this RxTx web
I want to execute script from an editable input field when clicking a button
i want to execute wecutil rs command after each 2 min interval on single
How can I execute SQL statements from a C program. For example I want

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.