Search code examples
springformsspring-mvcgetaction

SpringMVC: URL parameter after query parameters


I have an HTML form in which I'd like to have additional URL parameters after the form query. For example, the URI I'd like to end up with may look like this:

/publications?pub_type=article&year=2016/titles

However, I don't know how to write the action of the HTML form for this. Is it possible?

<form method="get" action="/publications [?] /titles ">
...
</form>

Solution

  • You can do like this:

    In form action

    action="/publications/pubTypeVal/yearVal/titles"
    

    And server-side

    @RequestMapping(value = "publications/{pubTypeVal}/{yearVal}/titles", method=RequestMethod.GET)
    
    public String hello(@PathVariable("pubTypeVal") String pubTypeVal, @PathVariable("yearVal") String yearVal) {
    // your implementation
    }