mvc pattern in java ee and migrating from spring to java ee 7

一世执手 提交于 2019-12-10 17:19:04

问题


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.


回答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)



来源:https://stackoverflow.com/questions/24360391/mvc-pattern-in-java-ee-and-migrating-from-spring-to-java-ee-7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!