亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

第三種方式沒起作用

你好,老師。 我根據視頻中的書寫,采用第三種方式為何沒有跳轉到指定頁面呢!非常奇怪。

<struts>

? ?<package name="default" namespace="/" extends="struts-default">

? ? ? <action name="*_*" method="{2}" class="com.imooc.action.{1}Action">

? ? ? ? <result>/result.jsp</result>

? ? ? ? <result name="add">/{2}.jsp</result>

? ? ? ? <result name="update">/{2}.jsp</result>

? ? ? </action>

? ? ??

? ? ? <!-- ?<action name="addAction" method="add" class="com.imooc.action.HelloWordAction">

? ? ? ? <result>/result.jsp</result>

? ? ? </action>

? ? ??

? ? ? <action name="updateAction" method="update" class="com.imooc.action.HelloWordAction">

? ? ? ? <result>/result.jsp</result>

? ? ? </action>-->

? ?</package>

? ?<constant name="struts.enable.DynamicMethodInvocation" value="false"></constant>

</struts> ?

正在回答

3 回答

struts2.5.2 通配符問題_親測有用

學了一段時間struts2,跟著教程做,但發現struts2的版本不同,很多東西的使用是有差異的。例如之前遇到的創建sessionFactory的方式就跟之前版本有著明顯的差異。今天又遇到一個問題,那就是通配符的使用。

?

問題:若不使用通配符,可以找到相對應的action,而使用通配符就會報錯,找不到actionmapping之內的錯,找不到action。

?

問題原因:?struts2.5 為了增加安全性,在 struts.xml 添加了這么個屬性:<global-allowed-methods>regex:.*</global-allowed-methods>

?

解決:

<?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><package name="default" namespace="/" extends="struts-default">
? <global-allowed-methods>regex:.*</global-allowed-methods>
<action name="helloworld" class="com.imooc.action.HelloWorldAction">
? ? ?<result>/result.jsp</result>
? ? ?<result name="add">/add.jsp</result>
? ? ?<result name="update">/update.jsp</result>
</action>
</package>
<constant name="struts.enable.DynamicMethodInvocation" value="true"></constant>
</struts>


1.首先,注意頭部信息,這個應該是用來指定文件中允許使用那些標簽。
  <!DOCTYPE struts PUBLIC"-//Apache Software Foundation//DTD Struts Configuration 2.5//EN" "http://struts.apache.org/dtds/struts-2.5.dtd">2.加上下面這句。
  <global-allowed-methods>regex:.*</global-allowed-methods>
 或者(不加上面這句),在action中加上指定允許調用的方法的語句:
  <allowed-methods>login,logout</allowed-methods>
  


0 回復 有任何疑惑可以回復我~
#1

幕布斯13241

轉,侵刪
2017-07-12 回復 有任何疑惑可以回復我~
#2

幕布斯13241

方法要是 public
2017-07-12 回復 有任何疑惑可以回復我~

給出的代碼不全,猜測可能是action中方法的返回值有問題。

1 回復 有任何疑惑可以回復我~

你輸入的地址是什么

0 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

第三種方式沒起作用

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號