Announcement Announcement Module
Collapse
No announcement yet.
Button submission is not working Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Button submission is not working

    Unable to perform button submissions in my form..I've Followed the post at http://forum.springsource.org/showth...-submit-button. This is not working for me.
    Whenever I click on the Save button, the alert given in the JSP 'before' is popup, but it is not leading to the controller. Pls have a look at my code here:



    The hello.jsp is:



    <script language="JavaScript">
    function save(){
    alert("before");
    document.forms[0].param.value = "SaveMethod";
    alert("After");

    }
    </script>

    <body>

    <form:form action="hello.htm" method="POST">
    <input type="text" class="labelTextClass" name="lblName" value="Name:" />
    <input type="text" maxlength="50" class="textInputClass" name="txtName" value="" />
    <input type="submit" class="button" value="Save" name="btnSave" onclick="save();" />
    <input type="hidden" name="param" />

    </form>
    </body>


    The servlet name is spring. The spring-servlet.xml file is:

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="htthp://www.springframework.org/schema/p"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schem...-beans-3.0.xsd
    http://www.springframework.org/schema/aop http://www.springframework.org/schem...ng-aop-3.0.xsd
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">

    <bean class="org.springframework.web.servlet.mvc.support .ControllerClassNameHandlerMapping"/>
    <bean id="helloId" class="test.web.helloController">
    <property name="methodNameResolver">
    <ref bean="selectMethodResolver"/>
    </property>
    </bean>


    <bean id="selectMethodResolver" class="org.springframework.web.servlet.mvc.multiac tion.ParameterMethodNameResolver">
    <property name="paramName">
    <value>param</value>
    </property>
    </bean>

    <bean id="urlMapping" class="org.springframework.web.servlet.handler.Sim pleUrlHandlerMapping">
    <property name="mappings">
    <props>
    <prop key="index.htm">indexController</prop>
    <prop key="hello.htm">helloId</prop>
    </props>
    </property>
    </bean>

    <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/jsp/"/>
    <property name="suffix" value=".jsp"/>
    </bean>


    <bean name="indexController"
    class="org.springframework.web.servlet.mvc.Paramet erizableViewController"
    p:viewName="index" />

    </beans>

    The helloCOntroller is:


    package test.web;

    import java.io.IOException;
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import org.springframework.web.servlet.ModelAndView;
    import org.springframework.web.servlet.mvc.multiaction.Mu ltiActionController;
    import org.springframework.web.servlet.mvc.multiaction.Pa rameterMethodNameResolver;


    public class helloController extends MultiActionController {

    private ParameterMethodNameResolver methodNameResolver;

    public void setMethodNameResolver(ParameterMethodNameResolver methodNameResolver) {
    this.methodNameResolver = methodNameResolver;
    }
    //

    public ModelAndView handleRequest(HttpServletRequest hsr, HttpServletResponse hsr1) throws ServletException, IOException {

    return new ModelAndView("hello");
    }

    public void saveMethod(HttpServletRequest request,
    HttpServletResponse response) throws Exception {
    System.out.println("Hi");
    }
    }
Working...
X