How do you create a Spring MVC that just prints some text to

I want to create a simple handler that performs a single task and then prints the word “Done” to the screen.Do I need to create a View template or is there an easy way to print text to the screen without writing a template?@RequestMapping(value = “/simple_handler”, method = RequestMethod.GET)public void simpleHandler(HttpServletRequest request, ModelMap model) this….

via Java Application Development Tutorial » Search Results » ajax:

How do you create a Spring MVC that just prints some text to

I want to create a simple handler that performs a single task and then prints the word “Done” to the screen.
Do I need to create a View template or is there an easy way to print text to the screen without writing a template?
@RequestMapping(value = “/simple_handler”, method = RequestMethod.GET)
public void simpleHandler(HttpServletRequest request, ModelMap model)
this.carryOutSomeTask();
// Print “Done” on the screen

……………………………..

See http://static.springsource.org/spring/docs/3.0.x/reference/mvc.html#mvc-ann-responsebody
You just have to use
@RequestMapping(value = “/simple_handler”, method = RequestMethod.GET)
@ResponseBody
public void simpleHandler(HttpServletRequest request, ModelMap model)
this.carryOutSomeTask();
return “Done”;

……………………………..

In controller:
@RequestMapping(value = “/simple_handler”, method = RequestMethod.GET)
public void simpleHandler(HttpServletRequest request, ModelMap model)
model.addAttribute(“msg”,”Hello World”);
In JSP:
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

This is my message: $msg



……………………………..

@RequestMapping(value = “/simple_handler”, method = RequestMethod.GET)
public @ResponseBody String simpleHandler()
this.carryOutSomeTask();
return “Done”;
I have used this with a lot of Ajax related projects, to return a button text for example:
@RequestMapping(“/startMonitor”)
public @ResponseBody String startMonitor()

printService.getMonitor().start();
return MONITOR_STARTED;

For more info: How do you create a Spring MVC that just prints some text to

Java Application Development Tutorial » Search Results » ajax

How do you create a Spring MVC that just prints some text to

Share this post:

Related Posts

Leave a Comment