Announcement Announcement Module
Collapse
No announcement yet.
Spring 4 Form Submission Not Working Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring 4 Form Submission Not Working

    Hello,

    I'm unable to get form POST submission working in Spring 4 with Thymeleaf. The page loads, I input the values, and the results page comes up. However, the results page is empty and when I checked the values in JAVA, it looks like after I hit submit on the form the value th:object is not getting populated.

    To try and figure this out, I tried to execute the following Spring tutorial - http://spring.io/guides/gs/handling-form-submission/ but I get the same problems when I try and package as a WAR. So the tutorial works if I make it into a JAR with the embedded Tomcat JARs, but when I make it a WAR (well it gives me an error first about a missing Spring-Batch-Core JAR, but then I unpackaged the WAR and added that JAR and repackaged to get past this hurdle), the form POST doesn't carry the values back to the Controller class.

    I took every dependent JAR from the tutorial using gradle and placed it into my Eclipse and am trying to deploy to Glassfish. Worst part is no exceptions whatsoever! So I've narrowed it to a few things, (1) Glassfish issue (2) I'm missing a JAR (3) It doesn't work

    Please help me with this if you can. Below is my Controller, JSP, and Classpath

    This is my Controller Class===================

    package hello;

    import org.springframework.stereotype.Controller;
    import org.springframework.ui.Model;
    import org.springframework.web.bind.annotation.ModelAttri bute;
    import org.springframework.web.bind.annotation.RequestMap ping;
    import org.springframework.web.bind.annotation.RequestMet hod;
    import org.springframework.web.bind.annotation.RequestPar am;

    @Controller
    public class GreetingController {

    @RequestMapping(value="/greeting", method=RequestMethod.GET)
    public String greetingForm(Model model) {
    model.addAttribute("greeting", new Greeting());
    return "greeting";
    }

    @RequestMapping(value="/greeting", method=RequestMethod.POST)
    public String greetingSubmit(@ModelAttribute Greeting greeting, Model model) {
    model.addAttribute("greeting", greeting);

    System.out.println("AAAAA = " + greeting.getId());

    return "result";
    }

    }


    This is my JSP===========================
    <%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html xmlns:th="http://www.thymeleaf.org">
    <head>
    <title>Getting Started: Handing Form Submission</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    </head>
    <body>
    <h1>Form</h1>
    <form action="#" th:action="@{/greeting1}" th:object="${greeting}" method="post">
    <p>Id: <input type="text" th:field="*{id}" /></p>
    <p>Message: <input type="text" th:field="*{content}" /></p>
    <p><input type="submit" value="Submit" /> <input type="reset" value="Reset" /></p>
    </form>
    </body>
    </html>


    These are my JARS=========================

    aopalliance-1.0.jar
    log4j-over-slf4j-1.7.7.jar
    spring-beans-4.0.4.RELEASE.jar
    spring-context-4.0.4.RELEASE.jar
    commons-logging-4.0.6.jar
    logback-classic-1.1.2.jar
    spring-boot-1.0.2.RELEASE.jar
    spring-core-4.0.4.RELEASE.jar
    jackson-annotations-2.3.0.jar
    logback-core-1.1.2.jar
    spring-boot-autoconfigure-1.0.2.RELEASE.jar
    spring-expression-4.0.4.RELEASE.jar
    jackson-core-2.3.3.jar
    ognl-3.0.6.jar
    spring-boot-starter-1.0.2.RELEASE.jar
    spring-web-4.0.4.RELEASE.jar
    jackson-databind-2.3.3.jar
    slf4j-api-1.7.7.jar
    spring-boot-starter-logging-1.0.2.RELEASE.jar
    spring-webmvc-4.0.4.RELEASE.jar
    javassist-3.16.1-GA.jar
    snakeyaml-1.13.jar
    spring-boot-starter-thymeleaf-1.0.2.RELEASE.jar
    thymeleaf-2.1.2.RELEASE.jar
    jcl-over-slf4j-1.7.7.jar
    spring-aop-4.0.4.RELEASE.jar
    spring-boot-starter-tomcat-1.0.2.RELEASE.jar
    thymeleaf-layout-dialect-1.2.3.jar
    jul-to-slf4j-1.7.7.jar
    spring-batch-core-2.2.6.RELEASE.jar
    spring-boot-starter-web-1.0.2.RELEASE.jar
    thymeleaf-spring4-2.1.2.RELEASE.jar

  • #2
    This question is probably a better candidate for StackOverflow, perhaps with the "spring" and "spring-mvc" tags.

    Could you post your question there?
    The forums are moving to stackoverflow, a page explaining all this will be available there in a few days: http://spring.io/questions

    Comment

    Working...
    X