IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Spring Java Discussion :

Problème URL état HTTP 404


Sujet :

Spring Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Profil pro
    Inscrit en
    Novembre 2005
    Messages
    136
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Novembre 2005
    Messages : 136
    Par défaut Problème URL état HTTP 404
    bonjour

    je suis entrain réaliser une application spring mvc j ' ai un problème avec le contrôleur . quand j appuie sur list customer il me dirige pas sur bon url le voici (http://localhost:8080/StringTest/%3C...rlist'/%3E) de même avec edit customer
    merci
    voici l'home page
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
     
    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
        pageEncoding="ISO-8859-1"%>
    <!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>Insert title here</title>
    <script type="text/javascript"></script>
    <style type="text/css" >
        span{font-family: sans-serif; font-size: 14px; text-align: center; color: red; }
    </style>
    </head>
    <body>
      <form action="CustomerListController" method="post">
      <div id="header">
     
      </div>
       <table width="100%">
         <tr height="600">
            <td width="20%" valign="top"> 
              <ul>
     
                <li><a  href="<c:url value='/customerlist'/>">List Customer</a></li>
                <li><a  href="<c:url value='/customeredit?id=${customer.id}'/>">Edit Customer</a></li>
                <li><a href="#">Save Customer</a></li>
              </ul>
            </td>
        <tr>      
      </table>
     
    <div id="footer">
     
    </div>
     </form>
    </body>
    </html>
    voici le contrôleur CustomerEditController
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
     
    @Controller
    @RequestMapping("/customerlist")
    public class CustomerEditController {
    	@Autowired CustomerRepository  customerRepository;
    	private Customer customer;
     
    	 private ModelAndView prepareModelAndView(Customer customerlist ) {
    	        ModelAndView mv = new ModelAndView("customeredit");
    	        mv.addObject("id", customerlist.getId());
    	        mv.addObject("customerlist", customerlist); 
    	        return mv; 
    	    }
     
    	@RequestMapping("/customeradd")
    		public ModelAndView playListCreate() {
    			 return prepareModelAndView(new Customer());     
    		}
    	@RequestMapping("/customeredit")
    	public ModelAndView playListEdit (@RequestParam("id")long id) {
    		Customer customerlist =(Customer) customerRepository.findById(id);
     
    		return prepareModelAndView(customerlist);
     
    	}
    	 @RequestMapping(value="/customeronsubmit",method=RequestMethod.POST)
    	public ModelAndView CustomerAddSubmit( @Valid  @ModelAttribute Customer customer, BindingResult bindingResult){
     
    		if (bindingResult.hasErrors()){
     
    			return new ModelAndView ("customeredit", "customer", customer);
    		}
    		if(customer.getId()!=null)
    		   customerRepository.udpate(customer);
    		else
    		   customerRepository.persist(customer);
     
    		return new ModelAndView("redirect:/custormer?id="+customer.getId());
    	}	
     
     
    }
    voici customeredit.jsp
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
     
     
    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    	pageEncoding="ISO-8859-1"%>
    <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
    <%@ taglib uri='http://java.sun.com/jsp/jstl/core' prefix='c'%>
     
     
    <!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">
     
    </head>
    <body>
    	<h1>Edit Customer</h1>
    	<form:form modelAttribute="customer" method="post" action='<%=response.encodeUrl("/customeredit/customeronsubmit")%>'>
    		<form:hidden path="id" />
    		<label>FirstName</label>   <form:input path="firstName" />      <form:errors path="firstName" /><br>
    		<label>LastName</label>   <form:input path="lastName" />       <form:errors path="lastName" /><br>
    		<input type="submit"  value="<c:choose><c:when test="${customer.id==null}">Add Customer</c:when><c:otherwise>Edit Customer</c:otherwise></c:choose>"/>
    	</form:form>
     
    	<a href="./">home page</a><br/>
     
    </body>
    </html>
    voici customerlist.jsp
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
     
    <body>
    	<table cellspacing="10">
    		<tr>
    			<td>FirstName</td>
    			<td>LastName</td>
     
    		</tr>
     
    		<c:forEach items="${customerList}" var="customer">
    			<tr>
    				<td>${customer.firstName}</td> 
    				<td>${customer.lastName}</td>
     
    				<td><a href="<c:url value='customer?id=${customer.id}'/>">display details</a>
    			</tr>
    		</c:forEach>
    	</table>
     
     
    	<br/>
     
    	<a href="./">home page</a><br/>
     
    </body>
    </html>
    voici le contrôleur CustomerListController
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
     
    @Controller
    public class CustomerListController {
     
    	@Autowired CustomerRepository customerRepository;
     
    	@RequestMapping(value="/customerlist")
    	public ModelAndView showBookList(){
    		ModelAndView mv = new ModelAndView("customerlist");   // JSP
    		List<Customer> list = customerRepository.findAll();
    		mv.addObject("customerList", list);  // attached to the request. 
    		return mv;
     
     
    	}
    }

  2. #2
    Rédacteur/Modérateur
    Avatar de andry.aime
    Homme Profil pro
    Inscrit en
    Septembre 2007
    Messages
    8 391
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Ile Maurice

    Informations forums :
    Inscription : Septembre 2007
    Messages : 8 391
    Par défaut
    Bonsoir,

    Il te manque le taglib
    Code jsp : Sélectionner tout - Visualiser dans une fenêtre à part
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

    A+.

  3. #3
    Membre confirmé
    Profil pro
    Inscrit en
    Novembre 2005
    Messages
    136
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Novembre 2005
    Messages : 136
    Par défaut
    Citation Envoyé par andry.aime Voir le message
    Bonsoir,

    Il te manque le taglib
    Code jsp : Sélectionner tout - Visualiser dans une fenêtre à part
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

    A+.
    merci ca marche

Discussions similaires

  1. Problème URL Connexion en HTTPs
    Par lezert dans le forum Langage
    Réponses: 4
    Dernier message: 23/02/2010, 15h54
  2. Tomcat problème à l'affichage de la page axis ://Etat HTTP 404
    Par goofyrocks dans le forum Tomcat et TomEE
    Réponses: 3
    Dernier message: 10/12/2008, 11h58
  3. Problème d'état et de requete
    Par rossy dans le forum Access
    Réponses: 2
    Dernier message: 14/10/2005, 11h52
  4. Problème impression état
    Par soso78 dans le forum Access
    Réponses: 3
    Dernier message: 26/09/2005, 11h13
  5. [Tomcat][Eclipse] erreur http 404 à l'exécution de servlet
    Par mayjo dans le forum Tomcat et TomEE
    Réponses: 6
    Dernier message: 30/07/2004, 18h19

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo