我是Struts 2框架的新手,单击提交按钮时我遇到从一个名称空间更改为另一个名称空间的问题,我收到此错误。
<?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>
<package name="module-login" namespace="/login" extends="struts-default">
<action name="verifier" class="presentation.LoginAction" method="verifierLogin">
<result name="model.Client">/vuesJSP/client/client.jsp</result>
<result name="model.Administrateur">/vuesJSP/admin/ajouterClient.jsp</result>
<result name="error">/vuesJSP/login/login.jsp</result>
<result name="input">/vuesJSP/login/login.jsp</result>
</action>
</package>
<package name="module-Admin" namespace="/admin" extends="struts-default">
<action name="ajouter" class="presentation.AdminAction" method="ajouterClient">
<result name="success">/vuesJSP/admin/ajouterClient.jsp</result>
<result name="error">/vuesJSP/admin/ajouterClient.jsp</result>
<result name="input">/vuesJSP/admin/ajouterClient.jsp</result>
</action>
<action name="modifier" class="presentation.AdminAction" method="modifierClient">
</action>
<action name="supprimer" class="presentation.AdminAction" method="supprimerClient">
</action>
<action name="lister" class="presentation.AdminAction" method="listerClients">
</action>
</package>
<s:form method="post">
<s:textfield name="nom" label="Nom"></s:textfield>
<s:textfield name="prenom" label="prenom"></s:textfield>
<s:textfield name="cin" label="cin"></s:textfield>
<s:textfield name="login" label="login"></s:textfield>
<s:textfield name="password" label="password"></s:textfield>
<s:submit value="Ajouter Client" action="admin/ajouter"></s:submit>
<s:submit value="Lister les clients" action="admin/lister"></s:submit>
</s:form>
单击&#34; ajouter client&#34;时出现实际错误按钮
Error HTTP 404 - There is no Action mapped for namespace /login and action name admin/ajouter.
我想在点击&#34; ajouter client&#34;时更改网址按钮来自&#34; http://localhost:8080/GestionCommandes/login/verifier.action&#34;至 &#34; http://localhost:8080/GestionCommandes/admin/ajouter.action&#34;
有什么方法可以实现这个目标吗?
答案 0 :(得分:0)
在struts表单标记中,您应使用namespace
和action
属性。除非在struts.xml
中配置了斜杠,否则不要在操作名称中使用斜杠。
<s:form namespace="/admin" action="ajouter" method="post">
<s:textfield name="nom" label="Nom"></s:textfield>
<s:textfield name="prenom" label="prenom"></s:textfield>
<s:textfield name="cin" label="cin"></s:textfield>
<s:textfield name="login" label="login"></s:textfield>
<s:textfield name="password" label="password"></s:textfield>
<s:submit value="Ajouter Client"></s:submit>
<s:submit value="Lister les clients" action="lister"></s:submit>
</s:form>
注意,要在struts submit tag中使用action
属性,您应该为带有操作名称的参数启用操作前缀。有关详细说明,请参阅this答案。