0

I want to perform multiple operation Like DELETE and UPDATE to do so I Need to send Data to Controller, where I Am doing Mistake??

Following is my JSP page

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@taglib  uri="http://www.springframework.org/tags/form" prefix="form" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<jsp:useBean id="TimeDetailBean" class="com.logic.bean.userBean"   scope="application" />
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Manage Results</title>

</head>
<body>
<center>
<h1>The Employee_Info Results </h1>

<table>
<tr><th>Name</th><th>Last name</th><th>Password</th></tr>
<c:forEach items="${rows}" var="row">
<tr>
<td><input type="text" name="name" value=${row.NAME}></td>
<td><input type="text" name="lastname" value=${row.LASTNAME}></td>
<td><input type="text" name="password" value=${row.PASSWORD}></td>
<td><a href="update.do">UPDATE</a></td>
<td><a href="delete.do">DELETE</a></td>
</tr>

</c:forEach>
</table>

</center>
</body>
</html>

and below is the controller where I want The value of name ,lastname and password

@RequestMapping("/delete")
    public ModelAndView Delete(HttpServletRequest request, HttpServletResponse response)
    {
        System.out.println("Delete Controller Executed");
        userBean ub= new userBean();
        Dao d= new Dao();
        String name=request.getParameter("name");
        String lastname=request.getParameter("lastname");

        System.out.println("Name catch"+name);
        System.out.println("Lastname catch"+lastname);



        return new ModelAndView("deleteSuccess");

    }//delete ends

Thanks in advance. .

Anand Deshmukh
  • 169
  • 3
  • 20
  • 1
    You aren't sending anything. You need either a form or some sort of adding parameters to your URL or javascript to send a request. You are just clicking a link which doesn't send anything – M. Deinum Jun 02 '16 at 06:54
  • 1
    Unless you are using Ajax or passing a url query string it will not work – Scary Wombat Jun 02 '16 at 06:54
  • try to surround your html inputs with a from and define the form's action: as written in your request mapping ("/delete"). Define the form's method as "get" while your java function does not specify the method, as default it will be get. Put a submit button in form offcourse – Ismail Sahin Jun 02 '16 at 07:11
  • User form action to send the data to controller via JSP or JS or Jquery , Ajax etc.... – Pavan Jun 02 '16 at 07:34

1 Answers1

0

In order to send the Data from JSP to Controller

  1. Create a form with action (/delete) and method=POST
  2. Create a Controller with the @RequestMapping("/delete") that point to form action
  3. Use Request.getParameter("name") in Controller.

Now on submit button in the JSP Spring Servlet Dispatcher will the mapping form in the Controller class and send the data to the controller from JSP.

Let us know if more inforamtion needed I will share the sample example

Regards, Pavan

Pavan
  • 1,219
  • 13
  • 15
  • Thanks for the suggestion. In my case i want to perform both UPDATE and DELETE Operation simultaneously as a reason i dont want to use form tag. . – Anand Deshmukh Jun 02 '16 at 08:50