struts2如何通过url执行action中的方法呢?
struts.xml:<?xmlversion="1.0"encoding="UTF-8"?><!DOCTYPEstrutsPUBLIC"-//ApacheSoftwar...
struts.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<package name="default" namespace="/" extends="struts-default"><!-- 定义一个package -->
<!-- 对action返回结果的配置 -->
<action name="loginAction" class="com.zx.action.LoginAction">
<result name="success">/welcome.jsp</result>
<result name="login">/index.jsp</result>
</action>
<action name="find" class="com.zx.action.LoginAction" method="dofind">
<result name="success">/welcome.jsp</result>
<result name="login">/index.jsp</result>
</action>
</package>
</struts>
action中加入方法:
public String dofind()
{
System.out.println("1");
return SUCCESS;
}
jsp页面中加3个链接:
<a href="loginAction!dofind.action">1</a>
<a href="loginAction">2</a>
<a href="find">3</a>
第二个和第三个都能正确访问。
第一个链接报错:
Could not find action or result: /struts2test/loginAction!dofind.action
There is no Action mapped for namespace [/] and action name [loginAction!dofind] associated with context path [/struts2test]. - [unknown location]
at com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:185) 展开
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<package name="default" namespace="/" extends="struts-default"><!-- 定义一个package -->
<!-- 对action返回结果的配置 -->
<action name="loginAction" class="com.zx.action.LoginAction">
<result name="success">/welcome.jsp</result>
<result name="login">/index.jsp</result>
</action>
<action name="find" class="com.zx.action.LoginAction" method="dofind">
<result name="success">/welcome.jsp</result>
<result name="login">/index.jsp</result>
</action>
</package>
</struts>
action中加入方法:
public String dofind()
{
System.out.println("1");
return SUCCESS;
}
jsp页面中加3个链接:
<a href="loginAction!dofind.action">1</a>
<a href="loginAction">2</a>
<a href="find">3</a>
第二个和第三个都能正确访问。
第一个链接报错:
Could not find action or result: /struts2test/loginAction!dofind.action
There is no Action mapped for namespace [/] and action name [loginAction!dofind] associated with context path [/struts2test]. - [unknown location]
at com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:185) 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询