struts2入门day 1

今天开始学习struts2框架的学习,其实原理啥的都看不懂啦,好多程序照着书上敲,最后运行都会出现各种各样莫名奇妙的问题大哭写写一天的收获,希望自己能一直坚持下去。

编写Struts2项目的一般步骤:

1.将Struts2的支持类型库添加到web-inf下的lib文件夹中:

2.配置web.xml文件,只需在在默认的xml中中添加这些就行

<filter>
  <filter-name>struts2</filter-name>
  <filter-class>
  org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
  </filter-class>
  </filter>
  <filter-mapping>
  <filter-name>struts2</filter-name>
  <url-pattern>*.action</url-pattern>
  </filter-mapping>

3.在项目的源文件(src)下配置Struts.xml,如下:

<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.1//EN"
"http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<constant name="struts.devMode" value="true"/>
<!-- 声明包 -->
<package name="myPackage" extends="struts-default">
<!-- 定义action -->
<action name="testAction" class="com.lq.action.TestAction" >
<result name="success">success.jsp</result>
</action>
</package>
</struts>照葫芦画瓢啦,其实不知道action中的name属性是怎样命名的

4.然后写你的action类,注意action类必须继承于ActionSupport,不然你的return SUCCESS,return ERROR就会报错,action类中要复制粘贴的一行代码public static final long serialVersionUID = 1L;action类中一般要写execute方法

5.然后写你的index.jsp,success.jsp等等

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值