The download method must be provided with a URL that matches the mapping to one of your controller methods.
controller
@Controller @RequestMapping("/site") public class MyController{ @RequestMapping("/search") public String getFragment(){ return "fragment"; } }
Javascript
$(document).ready(function() { var html = "/contextRoot/site/search";
Config
Please note that in this example, it is assumed that you have the ViewResolver setting in the manager configuration file, and in the root of the WEB-INF directory there is a fragment.jsp file:
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/" /> <property name="suffix" value=".jsp" /> </bean>
The basic concept of request processing in Spring MVC is that the request is "somehow" mapped to a controller method. Spring MVC provides various ways to execute this URL, such as request, availability of parameters, parameter values, etc. But basically it comes down to which controller / method should handle this request. This is most often done using @RequestMapping .
After the method is detected, data is bound, which means that the request parameters are passed to the method as arguments. Once again, there are various ways to map parameters to arguments, including path variables, modelattributes, etc.
Next, the body of the method is executed, this is pretty much the custom, and you provide an implementation.
The next part is where you seem to be stuck. The following controller method tells Spring which view should be displayed. Once again, there are many ways to do this, but one of the most common is to return a String at the end of your method that matches the view (.jsp). Typically, a resolver is registered to avoid hard-coding the view file name in the returned String . The returned String resolved by the ViewResolver , and the associated view is returned.
To answer your next question, if you want to serve displaySearch.jsp after processing the request for search/systems , you simply return that view name.
@RequestMapping(value = "systems", method = RequestMethod.POST) public String displaySystems(Model model, @RequestParam String searchStr) { List<RSServicedSystemViewDTO> systems = systemService.getSystemsByName(searchStr); model.addAttribute("systems", systems); return "displaySearch"; }