java - Passing parameter with JSP to Controller in Spring -


hello im having strugle jsp , spring,

<html> <head>title  </head>   <body>        welcome in view        <h1>animal's database</h1>        <br>        <strong>${message}</strong><br>give me:<br>        <a href="writecat" >cat's list</a><br>        <a href="writedog">dog's list</a><br>        <a href="writesnake">snake's list</a>    </body> 

, controller

public string getanimallist(model model){     model.addattribute("animallist", animaldao.getanimallist("cat"));     return "list"; } @requestmapping("/writedog") public string getanimallist1(model model){     model.addattribute("animallist", animaldao.getanimallist("dog"));     return "list"; } @requestmapping("/writesnake") public string getanimallist2(model model){     model.addattribute("animallist", animaldao.getanimallist("snake"));     return "list"; } 

what i'm trying rid of 3x getanimallist method, cant figure out, how pass string jsp controller eg. "cat", "snake", "dog".
know in body of controller should go request.getparameter(xxx). problem me making jsp send string value of corresponding animal controller.

you can pass animal name string in path variable , url access rest service become basepath/write/animalname,

@requestmapping("/write/{animal}") public string getanimallist1(model model, @pathvariable("animal") string animal){     model.addattribute("animallist", animaldao.getanimallist(animal));     return "list"; } 

with path variable can add name of animal in href,

<a href="/write/cat" >cat's list</a><br> <a href="/write/dog">dog's list</a><br> <a href="/write/snake">snake's list</a> 

Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -