i need handle requests following:
www.example.com/show/abcd/efg?name=alex&family=moore (does not work) www.example.com/show/abcdefg?name=alex&family=moore (works) www.example.com/show/abcd-efg?name=alex&family=moore (works) it should accept sort of character value located between www.example.com/show/ , ?. please note value located there single value not name of action.
for example: /show/abcd/efg , /show/lkikf?name=jack in first request should redirect user page abcd/efg (because thats name) , second 1 should redirect user page lkikf along value of parameter name.
i have following controller handle issue when have / in address controller unable handle it.
@requestmapping(value = "/{mystring:.*}", method = requestmethod.get) public string handlereqshow( @pathvariable string mystring, @requestparam(required = false) string name, @requestparam(required = false) string family, model model) { i used following regex did not work.
/^[ a-za-z0-9_@./#&+-]*$/
you have create 2 methods 1 having @requestmapping(value = { "/{string:.+}" }) annotation , other having @requestmapping(value = { "/{string:.+}", "/{string:.+}/{mystring:.+}" }) , act accordingly in each, because can't have optional path variables.
import org.springframework.stereotype.controller; import org.springframework.ui.model; import org.springframework.web.bind.annotation.pathvariable; import org.springframework.web.bind.annotation.requestmapping; import org.springframework.web.bind.annotation.requestparam; @controller @requestmapping("/show") public class hellocontroller { @requestmapping(value = { "/{string:.+}" }) public string handlereqshow(@pathvariable string string, @requestparam(required = false) string name, @requestparam(required = false) string family, model model) { system.out.println(string); model.addattribute("message", "i called!"); return "hello"; } @requestmapping(value = { "/{string:.+}", "/{string:.+}/{mystring:.+}" }) public string whatever(@pathvariable string string, @pathvariable string mystring, @requestparam(required = false) string name, @requestparam(required = false) string family, model model) { system.out.println(string); system.out.println(mystring); model.addattribute("message", "i called!"); return "hello"; } }
Comments
Post a Comment