struts2(二)

复习:

1、什么是struts2

2、怎么搭建struts2开发环境

  1>> 下载struts2所需要的jar文件

       http://struts.apache.org

      首页上就可以直接点击下载需要的最新版本。

 

Tomcat 删除掉。

 

 

 2>>添加struts2的配置文件   struts.xml ---dtd-->核心的jar文件中 可以找到 dtd文件

 <!DOCTYPE struts PUBLIC

    "-//Apache Software Foundation//DTD StrutsConfiguration 2.3//EN"

    "http://struts.apache.org/dtds/struts-2.3.dtd">

 

3>>web.xml文件中添加启动struts2 MVC框架的过滤器

       加载struts2的配置文件   面试题

         struts-default.xml

         struts-plugin.xml

         struts.xml

         struts.properties

         web.xml

 

注意:如果在多个文件中配置了同一个常量,则后一个文件中配置的常量值会覆盖前面文件中配置的常量值.

 

 

struts2的常量

    常见的struts常量

        http://localhost:8080/struts_action/login.action

    为什么是.action  并且.action能不能修改? 面试题

 

struts2-core-2.3.8.jarorg.apache.strut2.default.properties
    

文件中找到后缀为.action的配置常量struts.action.extension=action,,

 

能不能修改?在哪里修改?

 struts.xml

 struts.properties

细说常量:

    常量可以在struts.xmlstruts.properties中配置,建议在struts.xml中配置,两种配置方式如下:

struts.xml文件中配置常量

<struts>

   <constant name="struts.action.extension"value="do"/>

</struts>

 

struts.properties中配置常量

struts.action.extension=do

 

因为常量可以在下面多个配置文件中进行定义,所以我们需要了解struts2加载常量的搜索顺序:

struts-default.xml

struts-plugin.xml

struts.xml

struts.properties

web.xml

如果在多个文件中配置了同一个常量,则后一个文件中配置的常量值会覆盖前面文件中配置的常量值.

 

 

Struts2 UI主题xthml simpleajax   默认的时xthml

 

 

 

注意:struts2spring进行集成  struts2hibernate集成

      <!spring集成时,指定由spring负责action对象的创建 -->

<constantname="struts.objectFactory" value="spring" />

 

 

Struts2 默认支持动态方法调用

动态方法调用的常量配置:

   <!–该属性设置Struts 2是否支持动态方法调用,该属性的默认值是true。如果需要关闭动态方法调用,则可设置该属性为false -->

<constant

name="struts.enable.DynamicMethodInvocation"value="false"/>

 

 

文件上传:

   <!--上传文件的大小限制-->  1kb

<constant name="struts.multipart.maxSize"value=1024"/>

 

 

 

动态方法的调用呢?

   

   http://localhost:8080/struts_dynamic/csdn/delete!adds.action

 

 

   action中有一个

            

   struts.xml文件中

          

 http://localhost:8080/struts_dynamic/

  csdn/action名称!方法名称.action

 

 

 

 

 

 

使用通配符 :

 

  在struts.xml文中

  

 

地址栏: http://localhost:8080/struts_dynamic/csdn/user

 

 

http://localhost:8080/struts_dynamic/csdn/user_add

 

 

 找这个Action  UserAction 中的

 

 

 

 

 

 

必须理解:

 

 

 

第一个*代表的是类名

第二个*代表的是方法名

 

意思:用这样的一个配置 就可以搞定 www.csdn.struts_dynamic.action这个包中所有的action处理

 

这样会导致  

<resultname=”会有n个名称”>

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值