Announcement Announcement Module
Collapse
No announcement yet.
@PathVariable Problem Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • @PathVariable Problem

    Hi All,

    I am making POC on spring 3.0.4. Regarding that I am getting simple prblem.
    Below is the application description.


    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>&nbsp;</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";
    }


    }


    My Problem:-> In contactList.jsp page there is a link "delete". When I press the delete link ,in controller "deleteContact" must be call with URL(http://localhost:8080/Spring3.0MVC/delete.html/4) this. 4 is my contact id which is passing through the URL. but I am getting 404 error, page not found. I am unable to send the contact Id from URL . Please help me. If u want any more information regarding application plz let me kn.
    Last edited by bishu24june; Jul 13th, 2011, 11:32 PM.

  • #2
    Wrong forum and duplicate

    Comment

    Working...
    X