form表单提交与Struts2框架中Action的问题?

form表单提交与Struts2框架中Action的问题


红颜莎娜
浏览 746回答 2
2回答

当年话下

form表单的action应该设置为设置为"UserLogin.action",拦截器就是按照Action名称去拦截的,因此,这里不能加上包名,应该写你在struts.xml中配置的那个Action类的名称即可,可以不加.action。错误信息就是找不到这个Action类的意思。There is no Action mapped for namespace / and action name XXXXX. - [unknown location]配置文件中,你需要配置这个Action类,首先为它取一个名字,一般就叫“UserLogin.action”,然后为它指定具体的类,也就是告诉Struts,你的这个Action由那个类来进行处理。例如:<!-- 登陆action --><action name="Login" class="struts2.LoginAction" ><result name="input">index.jsp</result><result name="success">success.jsp</result></action>这个配置就是说,Action动作的名字是Login,由struts2包下的LoginAction类来处理。

翻翻过去那场雪

你的命名空间是 namespace="/XXX" 那你form表单中的action应该是action=XXX/UserLogin.action 最前面没有 / 因为struts2的web.xml&nbsp;的核心控制器里的url-pattern 是/* 就是所有的action 都是以/开头 所以表单中的action 属性 =&nbsp;命名空间/ Action名字.后缀
打开App,查看更多内容
随时随地看视频慕课网APP