ssh学习:struts2的配置

来源:互联网 发布:react js 项目 编辑:程序博客网 时间:2024/06/05 18:29

 struts2学习:struts2的配置及业务流转

1.struts2的配置:

struts2文件的下载https://struts.apache.org/download.cgi#struts23241

配置的准备工作:

文件配置:

    1.将apps\struts2-blank\WEB-INF\lib路径下的全部jar包拷贝到动态网站的lib文件夹下;

    2.将apps\struts2-blank\WEB-INF\src\java下的struts.xml复制到项目的src文件夹下。

动态配置:

    1.在项目下的WebContent/WEB-INF/web.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>/*</url-pattern></filter-mapping>

   2.在项目下的struts.xml可以进行一下一些非必要配置,但是也是一些很重要的配置

<!-- 设置修改配置时候自动启动 --><constant name="struts.devMode" value="true" /><!-- 动态加载 --><constant name="struts.enable.DynamicMethodInvocation" value="true" /><!-- 配置web访问字符集编码标签 所有配置为UTF-8字符集 --><constant name="struts.i18n.encoding" value="UTF-8"></constant><!-- 配置请求的后缀,默认拦截.action请求 --><constant name="struts.action.extansion" value="do,action"></constant><!-- 设置浏览器是否缓存静态内容 ,开发状态时候设置为false 避免出现无法更新,发布时候可设置为true --><constant name="struts.serve.static.browserCache" value="false"></constant><!-- 当Struts.xml配置文件发生修改是,系统从新加载配置项 --><constant name="struts.configuration.xml.reload" value="true"></constant><!-- 在开发模式下 ,打印出更加详细的错误信息 --><constant name="struts.devMode" value="true"></constant>        <!-- 表单样式 --><constant name="struts.ui.theme" value="simple"></constant><constant name="struts.ui.templateDir" value="template"></constant><constant name="struts.ui.templateSuffix" value="ftl"></constant>

 3.package配置

<package name="default" namespace="/" extends="struts-default"><!--method属性指定是action触发的方法 默认为execute  --><action name="firstAction" class="Action 的路径" method="gaosi"><!-- 结果指向 --><!-- name属性是指定接收的action返回来的字符串数值 默认success --><result name="success">/success.jsp</result><result name="fail">/fail.jsp</result></action></package>

 2.struts的访问流程:



 注释:在有一个web访问服务器是,链接会在web.xml中过滤。当链接是.action或者其他的属性时候,链接会被web.xml中的过滤器拦截;拦截后,链接或被送到struts.xml文件下,进行地址匹配;若是地址匹配成功,服务器会执行相关的action前置拦截器操作:封装数据,上传文件等操作。之后则执行到xxx.java(action类)执行相关的操作。同时会执行到后置拦截器,拦截异常等情况;返回到struts.xml文件当中,将返回的数据匹配并跳转到相应的.jsp文件上

 

 

原创粉丝点击