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

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

第一次自己看视频学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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值