struts-blank
来源:互联网 发布:sftp 登录命令 端口 编辑:程序博客网 时间:2024/05/02 04:56
我真是菜鸟啊,研究struts2一个星期多了现在还没有入门,拿着apache给的源码,先研究一下吧。下面记录研究过程中的发现。
配置文件
<struts> <constant name="struts.enable.DynamicMethodInvocation" value="false" /> <constant name="struts.devMode" value="true" /> <package name="default" namespace="/" extends="struts-default"> <default-action-ref name="index" /> <global-results> <result name="error">/error.jsp</result> </global-results> <global-exception-mappings> <exception-mapping exception="java.lang.Exception" result="error"/> </global-exception-mappings> <action name="index"> <result type="redirectAction"> <param name="actionName">HelloWorld</param> <param name="namespace">/example</param> </result> </action> </package> <include file="example.xml"/> <!-- Add packages here --></struts>
配置文件像上图这样struts.xml,和struts1.x不同,在struts2里面采用这个配置文件代替struts-config.xml.于是没有了ActionForm来做中介。
注意到下面这一段代码:
<action name="index"> <result type="redirectAction"> <param name="actionName">HelloWorld</param> <param name="namespace">/example</param> </result> </action>
这里的意思是重定向到example.xml里面定义的HelloWorld动作。如果想要跳转到其他动作,比如我在example.xml中加入了一个
<action name = "test"><result >Menu.jsp</result></action>
这样就可以在上面index的actionname换成test,然后最后执行是跳转到Menu.jsp里面。注意这里没有指明Menu.jsp的位置,是因为example.xml已经指定了namespace=/example,即已经进入到了文件目录中example文件夹中,所以可以直接调用,否则应该加上/example/Menu.jsp.
注意测试之前应该先把example里面的
<action name="*" class="example.ExampleSupport"> <result>/example/{1}.jsp</result></action>
这个给注释掉,否则会无论如何都跳到HelloWorld的,这就是通配符的作用了,无论如何会匹配到*这个万金油动作。
第二个发现是,example.xml是专属于example这个包的,namespace应该指向之,如果namespace=/的话,index会报错的,说pacekagewith namespace /example cannot be found.
第三个发现是在WebRoot/WEB-INF/src/java下面的struts.xml和example.xml都没有用,即使删掉也可以正常运行。具体是为什么我也不造。求高手告诉我。
这里贴一下我的包结构。由于我是直接用Myeclipse 10.0里的import WAR包,于是就直接变成这样了,我个人觉得这个映射结构相当的复杂。还没有弄懂。第四个发现在是,Myeclipse真的很傲娇。我的src目录现在是这样的,可是之前example中是没有那三个java文件的,也可以正常调试,可今天打开开始调试的时候竟然告诉我说HelloWorld2.action找不到了,又耗费了一上午来调试T^T。最后不得不将WEB-INF中的java文件夹的三个文件复制过来才可以。
启动顺序
在这个例子里面,struts2启动,如果输入http://localhost:8080/struts2-blank首先从web.xml的welcome-list中找到欢迎页面,这里的welcome-list不能为空。然后默认会跳转到index.html中。注意到index.html里面有这样一句,<META HTTP-EQUIV="Refresh" CONTENT="0;URL=example/HelloWorld.action">。因此会自动跳转到HelloWorld.action,这个action在example.xml中注册。如果将HelloWorld改成Login就会跳转到登陆界面,注意这时候的登陆界面是下面这样的。意思就是需要提供登录验证,即会先经过validation拦截器。
如果输入的是http://localhost:8080/struts2-blank/xx,这里xx表示任意字符,这样一个动作在struts.xml和example.xml中都是没有定义的,因此就会触发下面这一个语句,
<default-action-ref name="index" />会自动执行index.action。因为这时候index没有制定方法和动作类,因此默认结果为success,自动跳转到result,即redirect,因此就会直接跳转到HelloWorld.action。这里的HelloWorld.action是在example中有定义的。如果把result的actionname改成Login就会报错,因为这时候在example中是没有定义index.action的。
通配符
<action name="Login_*" method="{1}" class="example.Login"><result name="input">/example/Login.jsp</result></action>
在example.xml中有这一段,意思就是当请求为Login_Test,Login_Have之类的方法时,可以直接匹配,实现Login.class中的相应Test和Have方法。可是我尝试的时候不知道为什么总是说NoSuchMethodException,可我明明已经在类文件里面定义了,而且大小写区分了,还是不行。后来不知道为什么又行了。。。。这个留着以后在测试的过程中有待解答。
- struts-blank
- http://localhost:8080/struts-blank/的流程
- blank
- 通过实例学习Struts2 - 从struts-blank开始 (1)
- 通过实例学习Struts2 - 从struts-blank开始 (2)
- 通过实例学习Struts2 - 从struts-blank开始 (3)
- 通过实例学习Struts2 - 从struts-blank开始 (1)
- 初学STRUTS —— 从struts-blank的简单流转开始学习(1)
- 初学STRUTS —— 从struts-blank的简单流转开始学习(2)
- struts2-blank
- ebs blank
- struts2 demo之blank
- about:blank about:internets
- tab与blank
- android webview https blank
- sturts-blank(2)
- target="-blank"安全漏洞
- The blank in SHELL
- Libevent示例程序7 bufferevent使用
- Android漫游记(4)---.so文件动态调试一例
- maven创建webapp项目碰到的问题
- Codeforces 343D Water Tree dfs序+线段树
- 忙的不可开交的没有任何
- struts-blank
- 用观查者模式传递线程状态
- ZigZag Conversion-锯齿形数组 查找数学规律
- ASP.NET底层的初步认识与理解
- hibernate 将一列添加为辅助主键的方法
- HttpRuntime的认识与加深理解
- Finance and Good Society
- 【Linux编程】存储映射I/O
- 2.3 列表和数据框