Announcement Announcement Module
No announcement yet.
why I never reach successView? Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • why I never reach successView?

    Hi, all

    I am doing a test on SimpleFormController but never reach defined successView. After submit the form, I was directed to formView immediately.
    Here is what I do:

    --- dispatcher-servlet.xml ---

    <bean name="/signonForm.form" class="signonFormController">
    <property name="sessionForm" value="true"/>
    <property name="commandClass" value="hashCommand"/>
    <property name="formView" value="signonForm"/>
    <property name="successView" value="welcome"/>

    <bean id="viewResolver" class="org.springframework.web.servlet.view.Intern alResourceViewResolver">
    <property name="viewClass" value="org.springframework.web.servlet.view.JstlVi ew"/>
    <property name="prefix" value="/WEB-INF/view/"/>
    <property name="suffix" value=".jsp"/>

    --- signonForm.jsp ---

    <%@ taglib prefix="c" uri="" %>
    <%@ taglib prefix="spring" uri="/spring" %>

    <title>Sign on</title>
    <h2>Spring Framework (SimpleFormController)</h2>
    <form method=get>
    <spring:bind path="command.formData['username']">
    <tr><td>ID:</td><td><input type=text name=username size=15 value="<c:out value="${status.value}"/>"</td></tr>
    <tr><td>Password:</td><td><input type=password name=password size=15></td></tr>
    <tr><td colspan=2 align=center><input type=submit value=SingOn></td></tr>
    <spring:hasBindErrors name="command">
    <b>Binding error!</b>

    --- ---

    import org.springframework.validation.*;
    import org.springframework.web.servlet.*;
    import org.springframework.web.servlet.mvc.*;

    import javax.servlet.*;
    import javax.servlet.http.*;

    import org.apache.log4j.*;

    import java.util.*;

    public class signonFormController extends SimpleFormController {

    Logger log;
    String logfile="logs/myspring.log";

    public signonFormController() throws Exception {

    log.addAppender(new FileAppender(new PatternLayout("%d %p: %m"),logfile));


    protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) throws Exception {

    log.debug(" onSubmit()");

    return new ModelAndView("signonForm");


    protected Object formBackingObject(HttpServletRequest request) {

    HashMap prevInput=new HashMap();

    if ( request.getParameter("username") != "" ) {
    prevInput.put("username",request.getParameter("use rname"));
    if ( request.getParameter("password") != "" ) {
    prevInput.put("password",request.getParameter("pas sword"));

    hashCommand prevCommand=new hashCommand();

    return prevCommand;



    Any idea? Do I need a validator class? It takes me several days and still no progress.


    Vincent Chen

  • #2
    form action attribute

    You forgot to tell your HTML page where to submit :
    your HTML code :
    <form method=get action=>
    should look like this :
    <form method=get action=signonForm.form>


    • #3

      Thanks for your reply. Is 'action=xxx' in form tag necessary? I saw several examples including 'Developing a Spring Framework MVC application step-by-step', they don't have action attribute in form tag. I thought SimpleFormController will take care this.


      • #4
        Finally solved!

        Quote from isFormSubmission method:

        Determine if the given request represents a form submission.

        Default implementation treats a POST request as form submission. Note: If the form session attribute doesn't exist when using session form mode, the request is always treated as new form by handleRequestInternal.

        I am using get method in html form and not override this method. My bad, still a lot to learn.


        Vincent Chen