Search code examples
jakarta-eespring-mvcmodel-view-controllerjava-ee-6java-ee-7

spring mvc controller equivallent javaee controller


I used spring.

Is there an equivalent controller strategy for pure plain java-ee 6/7? Like there is spring controllers which take care of path params, request params, return types, redirecting, redirecting to views with a modelAndView object to carry data?

@Controller
class MyControllerClass {

      @RequestMapping...
      method(){
         ServiceCall()...
      //put something to modelAndView object here and redirect to jsp page.
      return "home"; // this will redirect data to home.jsp

      }
}

Solution

  • One idea would be to use the Jersey implementation of JAX-RS.

    The controller would look like:

    @Path("same_as_the_class_request_mapping")
    public class MyControllerClass{
    
        @Path("pretty_much_same_as_the_method_request_mapping")
        @GET //or whatever you need
        public Viewable roaster(){
            //do whatever
            return new Viewable("home", some_model_object);
        }
    }
    

    You can see more information here and a good tutorial here.

    Jersey also gives you the ability to integrate with Spring, thus enabling one to call Spring services from Jersey controllers. Check out this for more details