4

I used spring MVC in the following manner:

@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

      }
}

@Service
class MyServiceClass{
      @Transactional
      SomeServiceMethod(){ 
        DaoMethod(); 
      }

}


@Repository
class MyDaoClass{
   DaoMethdon(){...}

}

/view/myjsps.jsp  path to view directory set in spring.xml

Question:

Can any body explain to me (preferably with actual real world code example(s)), that what alternatives do I have, for the above mentioned MVC pattern, in Java EE 6/7. ie. controller, service, dao, view layers.

Further more, how to redirect pages, (I believe plain requestDispatcher is an old way of doing things, there got to be some automated ways. Same goes with modelAndView.

I have googled a lot but all I find is spring mvc examples.

Talha
  • 699
  • 2
  • 12
  • 33
  • I do not understand your question. Spring MVC is a framework that goes on top of JavaEE 6 (I use it) or 7 (I believe). Ok Spring application contextes duplicates the functionalities of JEE CDI, but with IMHO it is more feature rich, comes with extensive helpers for unit testing, and saves you from writing a lot of boiler plate code. What do you want to use exactly and why do you want to get rid of Spring MVC ? – Serge Ballesta Jun 23 '14 at 08:04
  • I agree with you, but what you are saying is about 5 to 7 years old when java ee did not had CDI or llight weight EJBs etc. Spring saw that deficiency and became popular at that time. Now that Javaee had overcomed all that AND IT IS A specifications that all web containers bow to. Spring is not a specification. if often have problems with some containers. (well that is my personal experience. you may ignore that). well, further readings may help: https://blogs.oracle.com/arungupta/entry/why_java_ee_6_is – Talha Jun 23 '14 at 09:23
  • You might want to have a look at [jsf](http://stackoverflow.com/q/5104094/1113392) – A4L Jun 23 '14 at 09:24
  • Now, Java ee plain has many things, Aspect oriented programming AOP, security (like spiring security), CDI context dependancy injection (alternative to spring CDI), EJBs are light, so better than spring plain DAOs. In short I am trying to research that can I do all that I used to do with spring? Because I choose javaee plain over spring. many reasons. 1. specification vs framework. 2. faster. much faster. see benchmarks on google. 3. native support and backed by oracle itself. (spring is great but still a band of opensource group. not a corporate). My app is heavily scale rexpected – Talha Jun 23 '14 at 09:27
  • Thanks. JSF is nice idea. but due to architecture of my app, I cant use / dont want to use JSF as it is component based. I need a request / response based architecture. – Talha Jun 23 '14 at 09:27
  • @SergeBallesta spring works independently of java ee. I use it with tomcat, not an ee container. – NimChimpsky Jun 23 '14 at 09:33
  • http://www.javacodegeeks.com/2011/11/from-spring-to-java-ee-6.html – NimChimpsky Jun 23 '14 at 09:35
  • http://www.oracle.com/technetwork/articles/java/springtojavaee-522240.html – win_wave Jun 24 '14 at 11:46
  • ca you give a link for benchmarks? – win_wave Jun 24 '14 at 11:47
  • see at blogs.oracle.com/arungupta/entry/why_java_ee_6_is – Talha Jun 24 '14 at 12:35
  • To use MVC, you have to use a MVC framework. I argue that Spring MVC is the best choice. Java EE doesn't have a standard MVC framework implementation. It has JSF, which you already know is component based. Other than that you're just using Servlets, Portlets, and JSPs – int21h Jul 26 '14 at 03:36
  • And you're aware that Spring Boot makes separate container management unnecessary and that Pivotal certainly qualifies as corporate support with a lot better responsiveness than you'll ever see from Oracle? – chrylis -cautiouslyoptimistic- Jul 26 '14 at 03:50

1 Answers1

1

Java EE doesn't have a 'standard' MVC package. If you go straight Java EE you'll be dealing directly with HttpServletRequests, PortletRequests etc. Putting objects in the 'model' in plain Java EE is basically HttpServletRequest.setAttribute(), or HttpSession.setAttribute() (if @SessionAttributes)

int21h
  • 819
  • 7
  • 15
  • ... is this for real? I've been getting into Spring MVC and often hear all this stuff about Java EE vs Spring MVC blah blah, but I could never tell what Spiring MVC was actually being compared to in Java EE. Is the closest coherent equivalent to Spring MVC, from Java EE, just working with the base Java HTTP API's? If so, it sounds like there is no real equivalent to Spring MVC from Java EE (JSF is component based)... is that right? ---EDIT --- looks like Java EE acknowledges it's lack of MVC and may work toward an MVC standard http://www.infoq.com/news/2014/09/mvc-1.0-jsr – Don Cheadle Nov 12 '14 at 21:00
  • That's correct. That's why Struts became so popular in the mid 2000's. There was never a standard Java EE MVC framework. Nowadays, I either see Spring MVC or Struts2. I'd much rather prefer Spring MVC though. – int21h Nov 12 '14 at 22:27