Announcement Announcement Module
Collapse
No announcement yet.
While clicking on submit button controller is not handling the command Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • While clicking on submit button controller is not handling the command

    Hello all,

    I am new to springframework. I am doing few R&D over this from last one month. I am facing a very stupid problem now a days. The problem is not so big, it is only with simple SimpleFormController. Before describing the problem, i want that please have a look on to the following code.

    Web.xml

    Code:
    <servlet>
    		<servlet-name>retailmart</servlet-name>
    		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    		<load-on-startup>1</load-on-startup>
    	</servlet>
    	
    	<servlet-mapping>
    		<servlet-name>retailmart</servlet-name>
    		<url-pattern>*.htm</url-pattern>
    	</servlet-mapping>
    retailmart-servlet.xml


    Code:
      <bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
    		<property name="mappings">
    			<props>
    				<prop key="/welcome.htm">welcomeController</prop>
    				<prop key="/measurementmaster.htm">measurementMasterController</prop>
    			</props>
    		</property>
    	</bean>
    
    	<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    		<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
    		<property name="prefix" value="/WEB-INF/jsp/"/>
    		<property name="suffix" value=".jsp"/>
    	</bean>
    	
    	<bean id="welcomeController" class="com.deepak.controllers.WelcomeController"></bean>
    	<bean id="measurementMasterValidator" class="com.deepak.validator.MeasurementMasterValidator"></bean>
    	<bean id="measurementMasterController" class="com.deepak.controllers.MeasurementMasterController">
    		<property name="sessionForm">
    			<value>true</value>
    		</property>
    		<property name="commandClass">
    			<value>com.deepak.beans.MeasurementMasterBean</value>
    		</property>
    		<property name="commandName">
    			<value>measurementMaster</value>
    		</property>
    		<property name="formView">
    			<value>measurementmaster</value>
    		</property>
    		<property name="successView">
    			<value>welcome.htm</value>
    		</property>
    		<property name="validator">
    			<ref bean="measurementMasterValidator"/>
    		</property>
    	</bean>
    MeasurementMasterBean.java
    Code:
      package com.deepak.beans;
    
    public class MeasurementMasterBean {
    
    	private int measurementMasterId;
    	private String measurementMasterCode;
    	private String measurementMasterName;
    	
    	public String getMeasurementMasterCode() {
    		return measurementMasterCode;
    	}
    	public void setMeasurementMasterCode(String measurementMasterCode) {
    		this.measurementMasterCode = measurementMasterCode;
    	}
    	
    	public int getMeasurementMasterId() {
    		return measurementMasterId;
    	}
    	
    	public void setMeasurementMasterId(int measurementMasterId) {
    		this.measurementMasterId = measurementMasterId;
    	}
    	
    	public String getMeasurementMasterName() {
    		return measurementMasterName;
    	}
    	
    	public void setMeasurementMasterName(String measurementMasterName) {
    		this.measurementMasterName = measurementMasterName;
    	}
    }

    MeasurementMasterController.java
    Code:
      package com.deepak.controllers;
    
    import org.springframework.web.servlet.ModelAndView;
    import org.springframework.web.servlet.mvc.SimpleFormController;
    import org.springframework.web.servlet.view.RedirectView;
    
    public class MeasurementMasterController extends SimpleFormController{
    
    	public ModelAndView onSubmit(Object command) throws Exception {
    		return new ModelAndView(new RedirectView(getSuccessView()));
    	}
    
    }
    WelcomeController.java

    Code:
      package com.deepak.controllers;
    
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    import org.springframework.web.servlet.ModelAndView;
    import org.springframework.web.servlet.mvc.Controller;
    
    public class WelcomeController implements Controller{
    
    	public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
    		// TODO Auto-generated method stub
    		return new ModelAndView("welcome");
    	}
    }
    welcome.jsp

    Code:
      <html>
    	<head>
    		<title>Welcome</title>
    	</head>
    	<body>
    		<h1>WELCOME
    	</body>
    </html>
    measurementmaster.jsp

    Code:
      <%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
    <html>
    	<head>
    		<title>
    			Measurement Master
    		</title>
    	</head>
    	<body>
    		<form method="post">
    			<table width="372" height="211">
    				<tr>
    					<td>
    						ID
    					</td>
    					<spring:bind path="measurementMaster.measurementMasterId">
    					<td>
    						<input type="text" name="measurementMasterId" value=""/>
    					</td>
    					</spring:bind>
    				</tr>
    				<tr>
    					<td>
    						ID
    					</td>
    					<spring:bind path="measurementMaster.measurementMasterCode">
    					<td>
    						<input type="text" name="measurementMasterCode" value=""/>
    					</td>
    					</spring:bind>
    				</tr>
    				<tr>
    					<td>
    						ID
    					</td>
    					<spring:bind path="measurementMaster.measurementMasterName">
    					<td>
    						<input type="text" name="measurementMasterName" value=""/>
    					</td>
    					</spring:bind>
    				</tr>
    			</table>
    			<input type="submit" value="Insert"/>
    		</form>
    	</body>
    </html>

    As I think and I have seen in many examples, this code is absultely correct and should work properly, but it is not working fine.
    As per my requirement when i click on "Insert" button in "easurementmaster.jsp"page, it should redirect me to the "welcome.jsp". But it not redirecting me there.
    Please help me sort out this problem.

  • #2
    there's no action in your form...

    ...in measurementmaster.jsp so it won't post to where you want it to go.

    Comment


    • #3
      In made change in JSP according to your guidance, but still in vien.
      Code:
      <%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
      <html>
      	<head>
      		<title>Measurement Master</title>
      	</head>
      	<body>
      		<form action="measurementmaster.htm" method="post">
      			<table>
      				<tr>
      					<td>
      						Id
      					</td>
      					<spring:bind path="measurementMaster.measurementMasterId">
      						<td>
      							<input type="text" name="measurementMasterId" value="${status.value}"/>	
      						</td>
      					</spring:bind>
      				</tr>
      				<tr>
      					<td>
      						Code
      					</td>
      					<spring:bind path="measurementMaster.measurementMasterCode">
      						<td>
      							<input type="text" name="measurementMasterCode" value="${status.value}"/>	
      						</td>
      					</spring:bind>
      				</tr>
      				<tr>
      					<td>
      						Code
      					</td>
      					<spring:bind path="measurementMaster.measurementMasterName">
      						<td>
      							<input type="text" name="measurementMasterName" value="${status.value}"/>	
      						</td>
      					</spring:bind>
      				</tr>
      			</table>
      			<input type="submit" value="Execute"/>
      		</form>
      	</body>
      </html>
      this code is also not working. Please seniors help me.

      Comment


      • #4
        Difference between processFormSubmission and onSubmit Function

        I used processFormSubmission function instead of onSubmit function. Now I am able to redirect from measurementmaster.jsp to welcome.jsp. onSubmit and doSubmitAction functions are not working at all.

        Comment

        Working...
        X