title: Passing parameter from controller to jsp in spring
body: <p>I have a controller method as follow.</p>
  
  <pre><code>@RequestMapping("/edit/{jobId}")
  public String editJob(@PathVariable("jobId") Integer jobId,Model model){
      model.addAttribute("id",jobId);
      return "edit";
  }
  </code></pre>
  
  <p>in which i am passing the jobId to get the instance of the job by id and returning "edit" string so that it maps to edit.jsp as per the InternalResourceViewResolver. But when i click on the link it goes to /edit/44 in which case 44 would be the id of the job for which the edit link belongs to. Finally i got the error stating no resource found.</p>
  
  <p>home.jsp</p>
  
  <pre><code>&lt;%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%&gt;
  &lt;%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%&gt;
  &lt;%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%&gt;
  
  &lt;%@ page session="false"%&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;link rel="stylesheet" type="text/css"
  href="&lt;c:url value="/resources/css/style.css"/&gt;" /&gt;
  &lt;link rel="stylesheet"
  href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" /&gt;
  &lt;title&gt;Home&lt;/title&gt;
  &lt;/head&gt;
  &lt;body id="main"&gt;
  &lt;div class="container"&gt;
      &lt;h2 style="color:white"&gt;All posted jobs&lt;/h2&gt;
      &lt;c:if test="${empty jobList}"&gt;
          &lt;h6&gt;No Job Post Yet&lt;/h6&gt;
      &lt;/c:if&gt;
      &lt;c:if test="${!empty jobList}"&gt;
          &lt;c:forEach items="${jobList}" var="job"&gt;
              &lt;div class="panel panel-info"&gt;
                  &lt;div class="panel-heading"&gt;
                      &lt;h3 class="panel-title"&gt;${job.title }&lt;/h3&gt;
                  &lt;/div&gt;
                  &lt;div class="panel-body"&gt;${job.description }&lt;/div&gt;
                  &lt;div class="panel-footer"&gt;
                      &lt;a id="link" href="delete/${job.id }"&gt;Delete&lt;/a&gt; 
                      &lt;a id="link" href="edit/${job.id}"&gt;Edit&lt;/a&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/c:forEach&gt;
      &lt;/c:if&gt;
      &lt;section&gt;
          &lt;form:form method="post" action="add" modelAttribute="job"
              class="form-horizontal"&gt;
              &lt;div class="form-group" id="addForm"&gt;
  
                  &lt;form:label class="control-label" path="title"&gt;Title:&lt;/form:label&gt;
                  &lt;form:input class="form-control" path="title"/&gt;
  
  
  
                  &lt;form:label class="control-label" path="description"&gt;Description&lt;/form:label&gt;
                  &lt;form:textarea class="form-control" rows="5" path="description" /&gt;
  
  
  
                  &lt;button class="btn btn-success"&gt;
                      &lt;span class="glyphicon glyphicon-plus-sign"&gt;&lt;/span&gt; Add a Job
                  &lt;/button&gt;
              &lt;/div&gt;
              &lt;a id="addJob" href="add"&gt;+&lt;/a&gt;
          &lt;/form:form&gt;
      &lt;/section&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>
  </p>
  
  <p>JobController.java</p>
  
  <pre><code>package com.job.src;
  
  import java.util.Map;
  
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.stereotype.Controller;
  import org.springframework.ui.Model;
  import org.springframework.web.bind.annotation.PathVariable;
  import org.springframework.web.bind.annotation.RequestMapping;
  import org.springframework.web.bind.annotation.RequestMethod;
  
  import com.job.src.model.Job;
  import com.job.src.services.JobService;
  
  @Controller
  public class JobController {
  
  @Autowired
  private JobService jobService;
  
  @RequestMapping(value= "/")
  public String listJobs(Map&lt;String,Object&gt; map){
      map.put("job", new Job());
      map.put("jobList", jobService.listJobs());
      return "home";
  }
  
  @RequestMapping(value= "/add", method=RequestMethod.POST)
  public String addJob(Job job){
      jobService.addJob(job);
      return "redirect:/";
  }
  
  @RequestMapping("/delete/{jobId}")
  public String deleteJob(@PathVariable("jobId") Integer jobId){
      jobService.removeJob(jobId);
      return "redirect:/";
  }
  
  
  @RequestMapping("/edit/{jobId}")
  public String editJob(@PathVariable("jobId") Integer jobId,Model model){
      model.addAttribute("id",jobId);  
      return "edit";
  }
  }
  </code></pre>
  
  <p>edit.jsp</p>
  
  <pre><code>&lt;%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%&gt;
  &lt;%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%&gt;
  &lt;%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%&gt;
  &lt;%@ page language="java" contentType="text/html; charset=ISO-8859-1"
  
  pageEncoding="ISO-8859-1"%&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;link rel="stylesheet" type="text/css"
  href="&lt;c:url value="/resources/css/style.css"/&gt;" /&gt;
  &lt;link rel="stylesheet"
  href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" /&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"&gt;
  &lt;title&gt;Insert title here&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;form:form method="post" action="editSuccess" modelAttribute="job"
      class="form-horizontal"&gt;
      &lt;div class="form-group" id="addForm"&gt;
  
          &lt;form:label class="control-label" path="title"&gt;Title:    &lt;/form:label&gt;
          &lt;form:input class="form-control" path="title" /&gt;
  
  
  
          &lt;form:label class="control-label" path="description"&gt;Description&lt;/form:label&gt;
          &lt;form:textarea class="form-control" rows="5" path="description" /&gt;
  
          &lt;button class="btn btn-success"&gt;
              &lt;span class="glyphicon glyphicon-plus-sign"&gt;&lt;/span&gt; Add a Job
          &lt;/button&gt;
      &lt;/div&gt;
  &lt;/form:form&gt;
  </code></pre>
  
  <p>
  </p>