Struts2学习资料
陆续添加中….
struts2文档http://www.vaannila.com/struts-2/struts-2-tutorial/struts-2-tutorial.html
http://struts.apache.org/2.1.8/docs/guides.html
struts2 和 spring 整合 http://www.vaannila.com/struts-2/struts-2-example/struts-2-spring-plugin-integration-1.html
struts.xml
<struts> <package name="default" extends="struts-default"> <action name="helloWorld" class="helloWorldClass"> <result name="SUCCESS">/success.jsp</result> </action> </package> </struts>
web.xml
<listener> <listener-class>org.springframework.web.context.ContextLoaderListener </listener-class> </listener>
集成hibernate
applicationContext.xml
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="configLocation" value="classpath:hibernate.cfg.xml"> </property> </bean>
——————-临时记录—-以后整理
<action name="*"> <result>/WEB-INF/jsps/{1}.jsp</result> </action>
The {1} refers to the first (in this case only) wildcard in the action’s name attribute.
In this case, visiting /foo.action would return the /WEB-INF/jsps/foo.jsp file.
<action name="*/*"> <result>/WEB-INF/jsps/{1}/{2}.jsp</result> </action>
Here, we use the first wildcard as a directory (like /WEB-INF/jsps/recipe). The second defines the page (JSP) to be shown, such as list.jsp, new.jsp, and so on. Now the cleaner /recipe/list.action URL would return /WEB-INF/jsps/recipe/list.jsp.
注意:::::
Using this method means that we have a slash (/) in our action name. To do this, we must set the struts.enable.SlashesInActionNames in our struts.xml file (shown next), our web.xml, or (not preferred) our struts.properties file.
<constant name="struts.enable.SlashesInActionNames" value="true"/>通配符更多使用技巧
We can also use wildcards to define action methods and/or action classes. Class names, of course, must still be legal Java class names. If we’re using a wildcard to create a Java class name, we’ll have mixed-case URLs, and they are case-sensitive. The following definition demonstrates a possible configuration that differentiates between class names and methods within those classes:
<action name="*/*" class="com.packt.s2wad.ch02.examples.{1}Action" method="{2}"> <result>/WEB-INF/jsps/{1}/{2}.jsp</result> </action>
Assume UserAction and GroupAction classes, both with list() and create() methods. Visiting /User/list.action would call the UserAction.list() method then dispatch to /WEB-INF/jsps/User/list.jsp as the result.
使用通配符的优点和缺点
Using wildcards is a flexible way to break up our application. However, for large and complex applications, it can lead to a brittle configuration, bizarre URLs, and more trouble than they’re worth. Naturally, there’s another way, which can be used alone or in combination with wildcards.
包及命令空间
Packages and namespaces help group and classify various configuration elements, delineate areas of responsibility, provide package-specific resources, and so on. In our recipe application, we do not yet have much functionality. However, we can still draw a “line in the sand” between our two obvious sections, recipes and shopping, and intuit that each of these might deserve their own package.
Packages can declare a namespace, which is effectively a portion of the URL.
Adding to our original default package, our first look at defining some packages looks like this:
/home.action leads us to our default package.
检查配置
将此包struts2-config-browser-plugin-2.1.8.jar放到类路径下就可了,不需要做其他设置
We can use the Configuration Browser Plug-in to examine what Struts 2 believes our configuration is. (Struts 2 doesn’t always agree with us, but is nice enough to tell us when we’re wrong.) We just add the library to our classpath.
To browse our configuration, we visit /config-browser/index.action
访问地址:http://localhost:8080/test2/config-browser/index.action
struts 机制分析
http://www.duduwolf.com/wiki/2008/775.html
可参考如下链接
A reader can refer to the following:
XML-based configuration elements:
http://struts.apache.org/2.x/docs/configuration-elements.html
Struts 2 and XWork API Javadocs:
http://struts.apache.org/2.x/struts2-core/apidocs/index.html
Convention Plug-in (and its annotations):
http://struts.apache.org/2.1.6/docs/convention-Plug-in.html
Struts 2 tags (link to
http://struts.apache.org/2.x/docs/tag-reference.html
User Stories:
http://en.wikipedia.org/wiki/User_story
Java Web Application Basics:
http://www.onjava.com/lpt/a/671 (oldie but a goodie)
http://java.sun.com/javaee/technologies/webapps/
(all the best from Sun)
最近评论