我的index.jsp是:
<html>
<head>
<title>Basic Struts webapp</title>
</head>
<body>
<h2>Hello to Struts 2 !!</h2>
<s:url action="hello" var="helloLink">
<s:param name="userName" value="VolodiaL" />
</s:url>
<p>
<a href="${helloLink}">Get my nickname</a>
</p>
<p>My nickname is</p>
</body>
</html>
我的struts.xml是:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constant name="struts.devMode" value="true"/>
<package name="basicstruts2" extends="struts-default">
<action name="start">
<result>/index.jsp</result>
</action>
<action name="hello" class="basicstruts2.HelloWorldAction" method="execute">
<result name="success">/index.jsp</result>
</action>
</package>
</struts>
当我点击“获取我的昵称”链接时,我收到此错误:
There is no Action mapped for namespace [/] and action name [helloLink] associated with context path [/basicStruts]. - [unknown location]
com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:185)
org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:63)
org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:37)
com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:58)
org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:552)
org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
为什么会这样?
我解决了。只有这样才有效:
<s:a action="helloVova">get my nickname!
<s:param name="userName">VolodiaL</s:param>
</s:a>
但是如果我使用s:param的value属性那么它就不起作用了。