2

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

      }
}

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

6 Comments

will this controller be a servlet? how can I know?
No, it is not a Servlet. The idea is pretty much the same as a Spring MVC controller. There is no need to drop down to Servlets. Jersey does most of the things you need just like Spring MVC does most of the things you need without having to use Servlets
so its a servlet thread under the hood? Just like a normal servlet? 2) how to deal the id in both, request or path params 3) so this is the only way in pure javaee?
It's not a servlet. It's just a class that is called by the Jersey Servlet (which is com.sun.jersey.spi.container.servlet.ServletContainer) to handle the appropriate requests
one of the reason that I switched from spring to javaee pure was that spring made objects while java ee makes threads of servlets. the later is fast. if thats the same case with jax-rs, its not a optimal choice.?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.