Struts2(一)知识点—Java基础篇

Struts项目
下载struts2的文件作为参考
1.导入lib目录下的jar包到WEB-INF
2.拷贝struts.xml到项目src下 及相关配置

3.在web.xml文件中加入过滤器代码


项目运行错误
解决办法
错误一:struts放错了位置,放在了WEB-INF下面,应该放在src下
错误二:LoginAction写错了包名
错误三:将多余的jar包删除


配置
1.struts.xml提示不显示,在Preferences下搜索xml,选择Xml Catalog


Struts2知识点

1.执行流程 多实例多线程

因为多实例,每次请求,会产生不同的Action和ActionContext对象,因此线程是安全的,同时因为Action是多实例的,所以Action中可以定义成员变量,因为多实例不会公用。

2.OGNL标签
3.通配符


第1种最直接的,指定method
<a href="<%=path%>/userAction.action">添加</a>


<action name="userAction" class="com.jike.struts.action.UserAction" method="add">
<result name="success">index.jsp</result>
</action>
第2种使用通配符实现在新版本中需要在result后添加 allowed-method标签
<a href="<%=path%>/UserAction_add.action">添加</a>


<action name="*_*" class="com.jike.struts.action.{1}"
method="{2}">
<result name="success">index.jsp</result>
<allowed-methods>add,show,update,delete</allowed-methods>

</action>

第3种动态访问
<a href="<%=path%>/userAction!add.action">添加</a>


<!-- 是否开启动态方法调用 -->
<constant name="struts.enable.DynamicMethodInvocation" value="true" />
<action name="userAction" class="com.jike.struts.action.UserAction"
method="*">
<result name="success">index.jsp</result>

</action>

因为 struts2.5 为了提升安全性,添加了 allomethod,会报错

Method add for action UserAction is not allowed!

解决办法,

1.在配置package下添加(支持正则和直接匹配方法)

<global-allowed-methods>regex:.*</global-allowed-methods>

2.在action块中添加

<allowed-methods>regex:.*</allowed-methods>


4.拦截器
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值