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
retailmart-servlet.xmlCode:<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>
MeasurementMasterBean.javaCode:<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>
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
WelcomeController.javaCode: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())); } }
welcome.jspCode: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"); } }
measurementmaster.jspCode:<html> <head> <title>Welcome</title> </head> <body> <h1>WELCOME </body> </html>
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.


Reply With Quote