Then what should I need to give.
If my application hv this code.
1)contactList.jsp
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>
<head>
<title>All Contacts</title>
</head>
<body>
<h3>Contacts</h3>
<c:if test="${!empty contactList}">
<table class="data">
<tr>
<th>Name</th>
<th>Email</th>
<th>Telephone</th>
<th> </th>
</tr>
<c:forEach items="${contactList}" var="contact">
<tr>
<td>${contact.lastname}, ${contact.firstname} </td>
<td>${contact.email}</td>
<td>${contact.telephone}</td>
<!-- <td><a href="delete.html">delete</a></td> -->
<td><a href="delete.html/${contact.id}">delete</a></td>
</tr>
</c:forEach>
</table>
</c:if>
</body>
</html>
2) ContactController.java
package com.lnt.infotech.web.controller;
import java.util.Map;
import javax.validation.Valid;
import javax.validation.Validator;
import org.springframework.beans.factory.annotation.Autow ired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttri bute;
import org.springframework.web.bind.annotation.PathVariab le;
import org.springframework.web.bind.annotation.RequestMap ping;
import org.springframework.web.bind.annotation.RequestMet hod;
import org.springframework.web.servlet.ModelAndView;
import com.lnt.infotech.model.Contact;
import com.lnt.infotech.service.ContactService;
@Controller
public class ContactController {
@Autowired
private ContactService contactService;
@RequestMapping("/index")
public String listContacts(Map<String, Object> map) {
map.put("contact", new Contact());
map.put("contactList", contactService.listContact());
System.out.println("Method->listContacts");
return "contact";
}
@RequestMapping(value = "/addContactData", method = RequestMethod.POST)
public ModelAndView addContact(@Valid Contact contact,BindingResult result,Map<String,Contact> model) {
contactService.addContact(contact);
System.out.println("Method->addContact");
if (result.hasErrors()) {
return new ModelAndView("contact");
}
model.put("contact", contact);
//return "redirect:/contactList";
return new ModelAndView("contactList","contactList",contactSe rvice.listContact());
}
@RequestMapping("/contactList")
public ModelAndView contactList(Map<String, Object> map) {
//map.put("contact", new Contact());
//map.put("contactList", contactService.listContact());
System.out.println("Method->contactList.");
return new ModelAndView("contactList","contactList",contactSe rvice.listContact());
}
@RequestMapping("/delete/{contactId}")
public String deleteContact(@PathVariable int contactId,Map<String, Object> map) {
contactService.removeContact(contactId);
map.put("contactList", contactService.listContact());
System.out.println("Method->deleteContact");
return "contactList";
}
}
Thanks & Regards,
Bishwa Ranjan Sarkar