第三種方式沒起作用
你好,老師。 我根據視頻中的書寫,采用第三種方式為何沒有跳轉到指定頁面呢!非常奇怪。
<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> ?
2017-07-12
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>
2016-01-21
給出的代碼不全,猜測可能是action中方法的返回值有問題。
2016-01-12
你輸入的地址是什么