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

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -