第三種方式?jīng)]起作用
你好,老師。 我根據(jù)視頻中的書(shū)寫(xiě),采用第三種方式為何沒(méi)有跳轉(zhuǎn)到指定頁(yè)面呢!非常奇怪。
<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 通配符問(wèn)題_親測(cè)有用
學(xué)了一段時(shí)間struts2,跟著教程做,但發(fā)現(xiàn)struts2的版本不同,很多東西的使用是有差異的。例如之前遇到的創(chuàng)建sessionFactory的方式就跟之前版本有著明顯的差異。今天又遇到一個(gè)問(wèn)題,那就是通配符的使用。
?
問(wèn)題:若不使用通配符,可以找到相對(duì)應(yīng)的action,而使用通配符就會(huì)報(bào)錯(cuò),找不到actionmapping之內(nèi)的錯(cuò),找不到action。
?
問(wèn)題原因:?struts2.5 為了增加安全性,在 struts.xml 添加了這么個(gè)屬性:<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.首先,注意頭部信息,這個(gè)應(yīng)該是用來(lái)指定文件中允許使用那些標(biāo)簽。
<!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中加上指定允許調(diào)用的方法的語(yǔ)句:
<allowed-methods>login,logout</allowed-methods>
2016-01-21
給出的代碼不全,猜測(cè)可能是action中方法的返回值有問(wèn)題。
2016-01-12
你輸入的地址是什么