好久没碰Web啦,感觉陌生了很多,要做个简单的Demo,拿到SSH却不知道从何下手!真是三天不练手生啊!

下了个MyEclipse8.0,700多M,真吓人!安装后又1G多,比6.X大一倍!不过新增了很多东西,最主要的是还新增了我比较看好的struts2!在官方网上找到个链接,有些简单的Demo,大概看了下,入门还不错,拿出来跟大家分享下。http://www.vaannila.com 有struts、struts2、Spring、Hibernate的简单示例,E文的,有兴趣的不妨去看看。

简单看了下这个Annotations,真的不错,很简单,感觉很智能!连配置文件struts.xml都不需要配置,就像这文章结尾说的:

 

The Convention plug-in is the one which does everything in the background. The Convention plug-in does the following things.

  • By default the Convention plug-in looks for the action classes inside the following packages strut, struts2, action or actions. Here our package name is com.vaannila.action. Any package that matches these names will be considered as the root package for the Convention plug-in.
  • The action class should either implement com.opensymphony.xwork2.Action interface or the name of the action class should end with Action. Here we extend our WelcomeUser class from com.opensymphony.xwork2.ActionSupport which inturn implements com.opensymphony.xwork2.Action.
  • The Convention plug-in uses the action class name to map the action URL. Here our action class name is WelcomeUser and the URL is welcome-user. The plug-in converts the camel case class name to dashes to get the request URL.
  • Now the Convention plug-in knows which Action class to call for a particular request. The next step is to find which result to forward based on the return value of the execute method. By default the Convention plug-in will look for result pages in WEB-INF/content directory.
  • Now the Convention plug-in knows where to look for results, but it doesn't know which file to display inside the content directory. The Convention plug-in finds this with the help of the result code returned by the Action class. If "success" is returned then the Convention plug-in will look for a file name welcome-user-success.jsp or welcome-user.jsp . It need not be a jsp file it can be even a velocity or freemaker files. If the result value is "input" it will look for a file name welcome-user-input.jsp or welcome-user-input.vm or welcome-user-input.ftl.
  • For more Struts 2 annotations example refer here ( Struts 2 Annotations - Part 2 ).

You can download the Struts 2 annotation example by clicking the download link below.

Source :Download Source + Lib :Download

 

原文:

 

http://www.vaannila.com/struts-2/struts-2-example/struts-2-annotation-example-1.html