我想知道<s:action> 与<s:a> 的区别
最近写网站遇到了关于<s:action/>的问题,我就写了个小程序测试了下,但结果很让我不解。这个测试程序的结构是这样的
index.jsp页面是这样的 <body>
<s:a href="show.action">点我</s:a>
</body>
struts.xml中这样配置
<package name="default" namespace="/" extends="struts-default">
<action name="show" class="com.test.action.Show">
<result>show.jsp</result>
</action>
</package>
action是这样的
public class Show extends ActionSupport {
@Override
public String execute() throws Exception {
// TODO Auto-generated method stub
return SUCCESS;
}
}
在show.jsp中输出一句话
<body>
<h1>hello</h1>
</body>
这样写的话,页面可以正常显示。但是我把Index.jsp中的<s:a>改成<s:action>就会报错
<body>
<%-- <s:a href="show.action">点我</s:a> --%>
<s:action name="show.action" executeResult="true"></s:action>
</body>
报的错误
SEVERE: Could not execute action: /show.action
There is no Action mapped for action name show.action. - [unknown location]
at com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:185)
at org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:63)
at org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:39)
at com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:58)
at org.apache.struts2.components.ActionComponent.executeAction(ActionComponent.java:289)
at org.apache.struts2.components.ActionComponent.end(ActionComponent.java:175)
at org.apache.struts2.views.jsp.ComponentTagSupport.doEndTag(ComponentTagSupport.java:42)
at org.apache.jsp.index_jsp._jspx_meth_s_005faction_005f0(index_jsp.java:128)
at org.apache.jsp.index_jsp._jspService(index_jsp.java:97)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:88)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilt