title: Passing String from jsp to Controller in Spring
body: <p>I created a project with Spring + JPA + Hibernate. I want to pass a string from jsp to controller(removeUtente method). If I click on the link I delete the row from the database .. Where am I doing wrong? Excuse me for my english..The controller receives the string from jsp and calls the method to remove it.
  Thanks </p>
  
  <pre><code>&lt;%@ page language="java" contentType="text/html; charset=ISO-8859-1"
  pageEncoding="ISO-8859-1"%&gt;
  &lt;%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%&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;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;h2&gt;Lista utenti&lt;/h2&gt;
  &lt;table border="1"&gt;
  &lt;c:forEach var="utente" items="${lista }"&gt;
      &lt;tr&gt;
          &lt;td&gt;
              &lt;c:out value="${utente.id}"/&gt;
          &lt;/td&gt;
          &lt;td&gt;
              &lt;c:out value="${utente.cognome}"/&gt;
          &lt;/td&gt;
          &lt;td&gt;
              &lt;c:out value="${utente.nome}"/&gt;
          &lt;/td&gt;
          &lt;td&gt;
              &lt;c:out value="${utente.eta}"/&gt;
          &lt;/td&gt;
          &lt;td&gt;
              &lt;c:url var="url" value="/remove"&gt;
                  &lt;c:param name="id" value="${utente.id }"/&gt;
              &lt;/c:url&gt;
              &lt;a href="${url}"&gt;click to delete&lt;/a&gt;
          &lt;/td&gt;
      &lt;/tr&gt;
   &lt;/c:forEach&gt;
  &lt;/table&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>UtenteController.java</p>
  
  <pre><code>package controller;
  
  import java.util.List;
  
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.stereotype.Controller;
  import org.springframework.ui.ModelMap;
  import org.springframework.web.bind.annotation.ModelAttribute;
  import org.springframework.web.bind.annotation.RequestMapping;
  import org.springframework.web.bind.annotation.RequestMethod;
  import org.springframework.web.bind.annotation.RequestParam;
  
  import persistence.UtenteDAO;
  import bean.Utente;
  
  @Controller
  public class UtenteController {
  
  @Autowired
  UtenteDAO utenteDAO;
  
  @RequestMapping(value="/add",method=RequestMethod.POST)
  public String addUtente(@ModelAttribute Utente u){
      utenteDAO.inserisciUtente(u);
      return "index";
  }//addUtente
  
  @RequestMapping(value="/show",method=RequestMethod.GET)
  public String getUtenti(ModelMap model){
      List&lt;Utente&gt; lista=utenteDAO.listaUtenti();
      model.addAttribute("lista", lista);
      return "showlista";
  }//getUtenti
  
  @RequestMapping(value="/remove",method=RequestMethod.GET)
  public String removeUtente(@RequestParam String id){
      utenteDAO.rimuovi(id);
      return "showlista";
  }//removeUtente
  }//UtenteController
  </code></pre>
  
  <p>Utente.java</p>
  
  <pre><code>package bean;
  
  import javax.persistence.Column;
  import javax.persistence.Entity;
  import javax.persistence.GeneratedValue;
  import javax.persistence.Id;
  import javax.persistence.Table;
  
  @Entity
  @Table(name="utente")
  public class Utente {
  
  @Id
  @GeneratedValue
  @Column(name="id")
  private Integer id;
  
  @Column(name="cognome")
  private String cognome;
  
  @Column(name="nome")
  private String nome;
  
  @Column(name="eta")
  private Integer eta;
  
  public Integer getId(){return id;}//getId
  
  public void setId(Integer id){this.id=id;}//setId
  
  public String getCognome(){return cognome;}//getCognome
  
  public void setCognome(String cognome){this.cognome=cognome;}//setCognome
  
  public String getNome(){return nome;}//getNome
  
  public void setNome(String nome){this.nome=nome;}//setNome
  
  public Integer getEta(){return eta;}//getEta
  
  public void setEta(Integer eta){this.eta=eta;}//setEta
  
  @Override
  public String toString(){
      return "id:"+id+" cogn:"+cognome+" nome:"+nome+" eta:"+eta;
  }//toString
  
  }//Utente
  </code></pre>
  
  <p>UtenteDAOImpl.java </p>
  
  <pre><code>package persistence;
  
  import java.util.List;
  
  import javax.persistence.EntityManager;
  import javax.persistence.PersistenceContext;
  import javax.persistence.Query;
  
  import org.springframework.transaction.annotation.Transactional;
  
  import bean.Utente;
  
  @Transactional
  public class UtenteDAOImpl implements UtenteDAO {
  
  @PersistenceContext
  EntityManager em;
  
  public void inserisciUtente(Utente u){
      em.persist(u);
  }//inserisciUtente
  
  @SuppressWarnings("unchecked")
  public List&lt;Utente&gt; listaUtenti(){
      Query q=em.createQuery("SELECT u FROM Utente u");   
      List&lt;Utente&gt; ris=q.getResultList();
      return ris;
  }//listaUtenti
  
  public void rimuovi(String idUtente){
      Query q=em.createQuery("DELETE FROM Utente AS u WHERE u.id =:id");
      q.setParameter("id", idUtente);
      q.executeUpdate();
  }//rimuovi
  
  }//inserisciUtente
  </code></pre>