Announcement Announcement Module
Collapse
No announcement yet.
information get inserted repeatedly into database while refreshing the jsp page Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • information get inserted repeatedly into database while refreshing the jsp page

    Empregistration.jsp


    <html>
    <head>
    <title>Employee Registration Form</title>
    </head>
    <body>

    <form action="reg.htm" method="POST">
    <table>
    <tr>
    <td>First Name</td>
    <td>
    <spring:bind path="employeeForm.firstName">
    <INPUT type="text" name="firstName" maxlength="35" value="<c:out value="${status.value}"/>" style="font-size:10pt;width: 210px;">
    </spring:bind>
    </td>
    </tr>
    <tr>
    <td>LastName</td>
    <td>
    <spring:bind path="employeeForm.lastName">
    <INPUT type="text" name="lastName" maxlength="35" value="<c:out value="${status.value}"/>" style="font-size:10pt;width: 210px;">
    </spring:bind>
    </td>
    </tr>
    <tr>
    <td>Age</td>
    <td>
    <spring:bind path="employeeForm.age">
    <INPUT type="text" name="age" maxlength="35" value="<c:out value="${status.value}"/>" style="font-size:10pt;width: 210px;" >
    </spring:bind>
    </td>
    </tr>
    <tr>
    <td>
    <input type="submit" value='submit'>
    </td>
    </tr>

    </table>
    </form>

    </body>
    </html>


    Dispatcher-servlet.xml

    <beans>


    <bean id="employeeHomeController"
    class="com.sumo.lims.module1.controller.EmployeeHo meController" />

    <bean id="employeeController"
    class="com.sumo.lims.module1.controller.EmployeeCo ntroller" >
    <property name="empService">
    <ref bean="empService"/>
    </property>
    <property name="sessionForm">
    <value>false</value>
    </property>
    <property name="commandName">
    <value>employeeForm</value>
    </property>
    <property name="commandClass">
    <value>com.sumo.lims.module1.form.EmployeeForm</value>
    </property>
    <property name="formView">
    <value>empregistration</value>
    </property>
    <property name="successView">
    <value>emplist</value>
    </property>
    </bean>

    <!-- URL Mapping definition -->
    <bean id="simpleUrlMapping"
    class="org.springframework.web.servlet.handler.Sim pleUrlHandlerMapping">
    <property name="mappings">
    <props>
    <prop key="/home.htm">employeeHomeController</prop>
    <prop key="/reg.htm">employeeController</prop>
    </props>
    </property>
    </bean>





    </beans>

    EmployeeController.java



    public class EmployeeController extends SimpleFormController {

    private IEmployeeService empService;

    public EmployeeController(){
    setCommandClass(EmployeeForm.class);
    }

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

    EmployeeForm empForm = null;
    Employee emp = new Employee();
    List<Employee> empList = new ArrayList<Employee>();
    empForm = (EmployeeForm) command;
    System.out.println("EmpForm::" + empForm.getFirstName());

    emp.setFirstName(empForm.getFirstName());
    emp.setLastName(empForm.getLastName());
    emp.setAge(empForm.getAge());

    empService.insertEmployee(emp);

    System.out.println("EmpForm::saved to db" );
    empList = empService.getAllEmployees(Employee.class);

    System.out.println("EmpForm::no of emp objects::::: " + empList.size());
    WebUtils.setSessionAttribute(request, "empList", empList);
    return new ModelAndView(IEmployeeConstants.EMPLOYEE_LIST_PAGE ,"employeeForm", empForm);

    }

    public void setEmpService(IEmployeeService empService) {
    this.empService = empService;
    }

    }

    Hi,
    I am using spring2.5.6 and hibernate3.The problem is that object values are inserted into the database properly but while refreshing the page, action is called and automatically controller is calling the previous values already stored inside the object ,that same value again it is inserting into the database,how to stop this.Can any one please look into this.
Working...
X