Results 1 to 2 of 2

Thread: Annotated Controller/JSP Unable To Submit Simple Form

  1. #1
    Join Date
    Oct 2009
    Posts
    8

    Default Annotated Controller/JSP Unable To Submit Simple Form

    All, this the relevant code from my login page:

    Code:
    <form:form target="login.do" method="post">
                            <span style="font-size:77%;">
                                <label>email:</label>
                                <form:input path="userName" cssClass="textfield" cssStyle="width:160px;" title="user name" name="userName" type="text" />
                                &nbsp;
                                <label>password:</label>
                                <form:input path="password" cssClass="textfield" cssStyle="width:160px;" name="password" type="password" />
                                &nbsp;
                                <input value="Login" class="button" type="submit" style="margin-bottom:4px" />
                            </span>
                        </form:form>
    and the controller:

    Code:
    @Controller
    public class LoginController {
    
        @RequestMapping(value = "/login")
        public String login() {
            System.out.println("login");
            return "login";
        }
    
        @RequestMapping(value="/login.do", method=RequestMethod.POST)
        public String doLogin(@RequestParam String userName, @RequestParam String password) {
            System.out.println(userName);
            System.out.println(password);
            System.out.println("doLogin");
            return "login";
        }
    }
    now, I'm obviously not done with the implementation here, but I can't even get the simple code included to work (just printing out parameter), it throws an exception: "java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'command' available as request attribute" when I navigate to the page by going to the /login URL, which is odd, because I'm not even using the form at that point, I'm just going to the page with the form on it

    so I have several questions:
    1. how do I get my specific example to work
    2. for my simple uses do I even need to use <form:form> tags, or can I just use a regular form?
    3. this page will have another form on it as well, is there further considerations that I need to have because of that?
    4. does anyone have a good spring 3 book to recommend?

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,625

    Default

    I suggest the reference guide.

    Short answer the spring form tags expect and require that you use a form object, if you don't use a simple html form instead of the form tags.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •