关于struts2 2.5.2 的入门 遇到的问题 --总结1

来源:互联网 发布:redis存储数据大小 编辑:程序博客网 时间:2024/05/01 19:49

-------废话的分割线----------

第一次自己看视频学struts2  总会遇到麻烦 ,究其原因 ——粗心大意为主  其次,所看视频的局限性为次要原因

----正题的分割线------

1:配置web.xml 文件,

(本人使用最新版struts2  2.5.2,自学视频为2.3)

·

<filter>    <filter-name>struts2</filter-name>    <filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>  </filter>  <filter-mapping>    <filter-name>struts2</filter-name>    <url-pattern>/*</url-pattern>  </filter-mapping>
*:在配置filter-class中需要注意:struts2  2.4版本之前dispatcher.ng   后面需要加ng  ,而2.5版本需要添加。也可以官网文档查看。

有个检验filter—class是否书写的有误的技巧:ctrl+鼠标左键会跳转至一个新的页面----同时会看到

StrutsPrepareAndExecuteFilter.class 文件


关于filter的其他配置无需赘述。

2.在src下配置struts.xml 

<?xml version="1.0" encoding="UTF-8"?>   <!DOCTYPE struts PUBLIC"-//Apache Software Foundation//DTD Struts Configuration 2.5//EN""http://struts.apache.org/dtds/struts-2.5.dtd">   <struts> <!-- <constant name="struts.objectFactory" value=""></constant> --> <!-- 开发者模式,出错后提示更详细    <constant name="struts.devMode" value="false"></constant> <constant name="struts.enable.DynamicMethodInvocation" value="true" /> -->     <!-- <allowed-methods>/*</allowed-methods>  --> <package name="default" namespace="/" extends="struts-default"> <!-- action配置  method="execute" --><global-allowed-methods>result</global-allowed-methods>     <action name="HelloWord" class="com.imooc.action.HelloWordAction" >     <result name="success">/result.jsp</result>     </action>                </package></struts>

关于注释 可忽略,

2.5.2的新特性

<global-allowed-methods>result</global-allowed-methods>
源码中也可以查到相关的语句

这行内容其实我也怎么懂,在其他博客中看到是考虑到安全性添加了allowmethod 这个东东,(可自行百度)

有关package的其他的配置不再赘述 基本都可以百度到 


-----over 的分割线-------

写的比较笼统 仅仅是笔记  多多体谅 不合理之处可以提出 评论留言即可  thanks

0 0
原创粉丝点击