java - how to create two actions on the same Controller for the same jsp page in spring-mvc -


the problem want create 2 actions in controller same jsp page(main.jsp) first action executed in moment of redirection main.jsp page, display details of product , , second associated button. how indicate spring wish method call ??

controller :

 @requestmapping(value = "pages/main", method = requestmethod.get)  public string detailproduct(final model model, @requestparam string id) {      productdto product = productservice.getproduct(long.parselong(id));     productmodel productbean = mapperdozerbean.map(product, productmodel.class);      model.addattribute("detailproduct", productbean);      return detailview; }  @requestmapping(value = "pages/main", method = requestmethod.get) public string addtocaddy(final model model, @requestparam string id,string action) {      productdto product = productservice.getproduct(long.parselong(id));      ...      return caddyview; } 

jsp : main.jsp

...     <div id="description">             <h1>${detailproduct.name}</h1>             <strong id="price">                 <span>previously &pound;299.00</span> ${detailproduct.price}dhs             </strong>                 <p>${detailproduct.description}</p>              <p>                 <button type="submit" name="addtocaddy" onclick="location.href='/main.do?id=${detailproduct.id}?'" class="continue" value="addtocaddy" >ajouter au panier</button> ... 

it's not necessary use same url when issuing requests given page.

for example define controllers this:

@requestmapping(value = "pages/main/detail", method = requestmethod.get) public string detailproduct(final model model, @requestparam string id) {     ... }  @requestmapping(value = "pages/main/addtocaddy", method = requestmethod.get) public string addtocaddy(final model model, @requestparam string id,string action) {    ... } 

and on jsp pass in correct url in request.


Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -