2011-03-25 137 views
0

The following code is giving error as:如何使用<a href> tag

There is no Action mapped for namespace/and action name .

code: .jsp file:

<a href="<s:url action='DisconnectAction' />">Disconnect</a> 

struts.xml

<action name="DisconnectAction" class="ActionPackages.DisconnectAction"> 
    <result name="success">/JSP/mytemplate.jsp</result> 
    <result name="input">/JSP/mytemplate.jsp</result> 
    <result name="error">/JSP/mytemplate.jsp</result> 
    <result name="failure">/JSP/mytemplate.jsp</result> 
</action> 

I want to perform action and keep the current accessing page only which is mytemplate.jsp

回答

0

Though your question is not clear so better give details about the problem but if i read the subject you want to call action using so here is the struts2 standard way

<s:a cssClass="table_tabs_dis" href="%{GenURL}">General</s:a> 

and here is one more

<a href="<s:url action=MyAction" namespace="/abc/xyz" />">ClickME</a> 
+0

Hi i changed the code and it worked fine instead of writing as Disconnect調用操作類我寫它爲Disconnect pankaj 2011-03-25 08:56:40

0

According to your question the problem was in your <s:url/> tag you have to give action after DisconnectAction & it will work fine as you want.

<a href="<s:url action="DisconnectAction.action"/>">Disconnect</a> 

Struts.xml

<action name="DisconnectAction" class="ActionPackages.DisconnectAction"> 
    <result name="success">/JSP/mytemplate.jsp</result> 
    <result name="input">/JSP/mytemplate.jsp</result> 
    <result name="error">/JSP/mytemplate.jsp</result> 
    <result name="failure">/JSP/mytemplate.jsp</result> 
</action> 
+0

我不認爲這是真的;在''標籤中不應該要求動作擴展。 – 2013-08-25 04:07:09

0

It seems that you have not given ".action " extension in struts tag. When you are using

<s:form action="someAction"></s:form> 

you dont need to give .action extension to your action name. But since you are embedding it in HTML tag, you have to give .action Extension.

(Answer Verified on Live)

<a href="<s:url action="urlTagAction.action" />"> Disconnect </a>