Utilizing Angularjs for sending a GET HTTP request to the server, which is then responded to by the Spring MVC framework. Below is a snippet of code depicting how the URL is built in Angular:
var name = "myname";
var query= "wo?d";
var url = "/search/"+query+"/"+name;
Here's the Spring MVC Controller implementation:
@RequestMapping( value = "/search/{query}/{name}" , method = RequestMethod.GET , produces = MediaType.APPLICATION_JSON_VALUE )
@ResponseBody
public List<Data> search() {
// search logic
return data;
}
An issue arises when the query string contains a question mark character (?), causing the URL to be split and leading to a warning from Spring:
WARN o.s.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/my-server/web/search/wo in DispatcherServlet with name 'mvc'
This occurs because the question mark introduces the beginning of request parameters. Attempts to use encodeURI(query)
in JavaScript have been unsuccessful as the question mark is not encoded. How can we properly encode a question mark in the URL?