首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

自个儿学习Struts2学习的心得体会(一)

2012-11-01 
自己学习Struts2学习的心得体会(一)????? 今天准备把自己这两天学习Struts2的基本东西写下来,也把自己的感

自己学习Struts2学习的心得体会(一)

????? 今天准备把自己这两天学习Struts2的基本东西写下来,也把自己的感悟写下来。我会一步一步把struts2中的细节介绍给大家,和大家一起学习。呵呵。(注:我会一直写下去,struts2只是一个框架,一个工具,不是万能的。)

??? ?其实现在网上关于这方面的文章也是很多的,可这是我的学习结果。所以写下来,也是对自己更加加深理解。
首先我自己运行一个简单的例子来说明Struts2的一个开发流程。

???? 1。下载Struts2的开发组件,地址为:http://struts.apache.org/。请下载all版本的,因为这里有很多对开发有帮助的东西。

???? 2。下载xwork的版本为2.0.4的源代码。地址为:http://repo1.maven.org/maven2/com/opensymphony/xwork/2.0.4/;


???? 3。下载ognl的版本为2.6.11的源代码,地址为:http://mirrors.ibiblio.org/pub/mirrors/maven2/opensymphony/ognl/2.6.11/;
(注:做这些工作,是让我们在工作的时候清楚的对Struts2是怎么工作有一个清晰的认识,打破它的神话。呵呵,开个玩笑啦。)


???? 4。把如下的jar文件复制到你的WEB-INF/lib下
????????? freemarker-2.3.8.jar,ognl-2.6.11.jar,struts2-core-2.0.11.1.jar,xwork-2.0.4.jar


???? 5。修改我们的web.xml加入:
???????? ?<filter>
????????? <filter-name>struts2</filter-name>
???????? <filter-class>
???????????????? org.apache.struts2.dispatcher.FilterDispatcher
???????? </filter-class>
???????? </filter>
???????? <filter-mapping>
?????????<filter-name>struts2</filter-name>
???????? <url-pattern>/*</url-pattern>
?????????</filter-mapping>
??????? ?/*表示所有的请求都经过这里。

???? 6。在WEB-INF/classes/下建立一个struts.xml文件。struts2不同于struts1有struts-config.xml文件,它
就是用struts.xml来取代的。当然你可以建立多个这样的文件。说到这里还要说一点就是struts2是请求
一次就产生一个实例,这样线程是安全的,而struts1却是就产生一个实例。struts.xml的格式,你可以去
你下载的.zip文件中apps目录下,随便找一个.war文件找一个struts.xml,复制它的格式就好了。如下:
???? <?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE struts PUBLIC
??? "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
??? "http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
???????? <constant name="struts.i18n.encoding" value="GBK" />
?<constant name="objectFactory" value="spring"></constant>??
?<package name="struts2" extends="struts-default">
?<interceptors>
??<interceptor name="LoginInterceptor" class="cn.com.homevv.action.login.LoginInterceptor"></interceptor>
??<interceptor-stack name="mygaoran">?
???<interceptor-ref name="LoginInterceptor"></interceptor-ref>
???<interceptor-ref name="defaultStack"></interceptor-ref>
??</interceptor-stack>
?</interceptors>
??<action name="login"
???class="loginID">
???<result name="failed">/login.jsp</result>
???<result name="success">/MyJsp.jsp</result>
??? <interceptor-ref name="mygaoran"></interceptor-ref>
?? </action>
?? </package>
? </struts>

?? 7。建立你的action,你的action随便怎么都可以建立,我的是继承了com.opensymphony.xwork2.ActionSupport
???? 这个文件,因为这样我大量的使用struts2的东西或者是特性啊。
???? public String execute() throws Exception { return SUCCESS;}
???? 实现这个方法。

?? 8。关联你的JSP文件,写好了,配置好你的struts.xml文件。

?? ?9。把项目加载到Tomcat中去,我用的是5.5版本,跑起来。用http://127.0.0.1:8080/项目名称,访问,没问题
就好了。
???? 这是一个简单的实例,是为了让我们的脑中有一个概念,其它的细节我会一步一步的写下来。

?

1 楼 jlt1986501 2008-05-04   谢谢   正在学习STRUTS   理解一下你的思路 2 楼 yuxianghong 2008-05-04   LZ有不有这方面比较好的资料。
如果有的,能否给看看。(注:不要HelloWorld那样的). 3 楼 myoldman 2008-05-04   <div class='quote_title'>yuxianghong 写道</div>
<div class='quote_div'>LZ有不有这方面比较好的资料。
如果有的,能否给看看。(注:不要HelloWorld那样的).</div>
<p><br/>直接看struts2的core develope guide看完基本上对struts2有一个很清晰的认识了。</p> 4 楼 antonyup_2006 2008-05-04   最近也想看看struts2 ,以前struts1.2很多都还没用在项目中,现在看struts不知道有没影响 呵呵 5 楼 gaoran2008 2008-05-09   antonyup_2006 2008-05-04
最近也想看看struts2 ,以前struts1.2很多都还没用在项目中,现在看struts不知道有没影响 呵呵


----------------不同的框架设计理念,所以没有影响,就怕自己的思想固化。 6 楼 yuan 2008-05-09   http://www.iteye.com/post/475030
com.opensymphony.xwork2.util.OgnlValueStack
这个类的源代码,愣是找不着。 7 楼 gmizr 2008-05-09   深秋小雨 写道http://www.iteye.com/post/475030
com.opensymphony.xwork2.util.OgnlValueStack
这个类的源代码,愣是找不着。
我这xwork-2.0.4-sources.jar里面有 8 楼 yuan 2008-05-10   gmizr 写道深秋小雨 写道http://www.iteye.com/post/475030
com.opensymphony.xwork2.util.OgnlValueStack
这个类的源代码,愣是找不着。
我这xwork-2.0.4-sources.jar里面有
确定?那我得去下个2.0.4,好像2.1.0的源代码漏了。
=============================================
果然有!多谢了!
我连2.1.1的一起下载了,里面也没有,就2.0.4有,不知道为什么…… 9 楼 wujiekangyun 2008-05-18   <div class='quote_title'>myoldman 写道</div>
<div class='quote_div'>
<div class='quote_title'>yuxianghong 写道</div>
<div class='quote_div'>LZ有不有这方面比较好的资料。如果有的,能否给看看。(注:不要HelloWorld那样的).</div>
<p><br/>直接看struts2的core develope guide看完基本上对struts2有一个很清晰的认识了。</p>
</div>
<p>我是看着李刚的struts2权威指南学的,说是权威指南,可能深层次的东西没有什么,但是内容绝对丰富。</p> 10 楼 laiseeme 2008-05-18   现在一直使用springMVC看看其实原理都差不多  等有时间了把MVC迁移到struts看看 11 楼 qamer 2008-05-21   <div class='quote_title'>wujiekangyun 写道</div>
<div class='quote_div'>
<div class='quote_title'>myoldman 写道</div>
<div class='quote_div'>
<div class='quote_title'>yuxianghong 写道</div>
<div class='quote_div'>LZ有不有这方面比较好的资料。如果有的,能否给看看。(注:不要HelloWorld那样的).</div>
<p><br/>直接看struts2的core develope guide看完基本上对struts2有一个很清晰的认识了。</p>
</div>
<p>我是看着李刚的struts2权威指南学的,说是权威指南,可能深层次的东西没有什么,但是内容绝对丰富。</p>
</div>
<p>简直就是什么都有,讲的很浅,但是目前市面上就只有这么一本</p> 12 楼 andyjames 2008-05-22   <div class='quote_title'>yuxianghong 写道</div>
<div class='quote_div'>LZ有不有这方面比较好的资料。如果有的,能否给看看。(注:不要HelloWorld那样的).</div>
<p>LZ写的不错,在我的博客里面有一些Struts2的入门文章,可以去看看,写的不是很好,希望可以给大家带来参考,共同研究。</p> 13 楼 yujianqiu 2008-05-22   深秋小雨 写道http://www.iteye.com/post/475030
com.opensymphony.xwork2.util.OgnlValueStack
这个类的源代码,愣是找不着。

这个类很有用,用它实现了一个类似Apache Commong BeanUtils的东西工具类,这样项目里面就可以用一种统一的el了。 14 楼 sinykk 2008-11-19   struts2 群QQ 26346176   现在里面仅几人..我不在乎人多.但我只在乎里面是否能真正帮助自己技术的提高... 

热点排行