Domanda

I have the following code which works fine with http://localhost:8080/HelloWorldSpring3/forms/helloworld

but i want to have url have some thing like this

http://localhost:8080/HelloWorldSpring3/forms/helloworld/locname_here/locid_here

I found that adding this @RequestMapping("/helloworld/**") will work but when i try to access

http://localhost:8080/HelloWorldSpring3/forms/helloworld/locname_here/locid_here

it is not found.

Web.xml entry as follows

<servlet-mapping>
      <servlet-name>dispatcher</servlet-name>
      <url-pattern>/forms/*</url-pattern>
    </servlet-mapping>

Mapping bean entry

@RequestMapping("/helloworld/**")
       public ModelAndView helloWord(){
              String message = "Hello World, Spring 3.0!";
              return new ModelAndView("helloworld", "message",message);
       }
È stato utile?

Soluzione

@Controller
@RequestMapping(value="/helloworld")
public class HelloWorldController{

    @RequestMapping(value = "/{locname_here}/{locid_here}")
    public ModelAndView helloWorld(@PathVariable String locname_here, @PathVariable long locid_here) {
        //Logic
    }

}

The above code works for your requirement.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top