复习:
1、什么是struts2
2、怎么搭建struts2开发环境
1>> 下载struts2所需要的jar文件
首页上就可以直接点击下载需要的最新版本。
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.jar的org.apache.strut2.default.properties
文件中找到后缀为.action的配置常量struts.action.extension=action,,
能不能修改?在哪里修改?
struts.xml
struts.properties
细说常量:
常量可以在struts.xml或struts.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
注意:struts2与spring进行集成 struts2与hibernate集成
<!–与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/
使用通配符 :
在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个名称”>