Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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

      }
}
share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

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 integration with Spring, there for enabled the calling of Spring services from Jersey controllers. Check out this for more details

share|improve this answer
    
will this controller be a servlet? how can I know? –  Masood Ahmad Jun 23 at 7:57
    
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 –  geoand Jun 23 at 7:58
    
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? –  Masood Ahmad Jun 23 at 8:02
    
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 –  geoand Jun 23 at 8:03
    
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.? –  Masood Ahmad Jun 23 at 8:05
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.