为什么struts.xml是正确的,但页面是404?

时间:2014-09-25 08:16:54

标签: java validation struts2 actionresult struts-action

Struts版本是2.3.16

struts.xml中,我添加了此

<action name="ajaxuser" class="com.pp.ajax.UserAccount">
    <result name="success">/out.jsp</result>
</action>

xml和UserAccount类是正确的,因为对此url的某些请求是正常的,但某些请求是404。

这是成功的请求

Request URL:http://localhost:8080/pp/ajaxuser
Request Method:POST
Status Code:200 OK
Request Headersview source
Accept:*/*
Accept-Encoding:gzip,deflate
Accept-Language:zh-TW,zh;q=0.8,en-US;q=0.6,en;q=0.4
Connection:keep-alive
Content-Length:45
Content-Type:application/x-www-form-urlencoded; charset=UTF-8
Cookie:JSESSIONID=B6D15A95251B1477473BC524E7E9E148; Siggraph-Fontresizer=105; targetEncodinghttp://your-site=1; PHPSESSID=k2fi36gbn8979riffibp2mt1f7; _ga=GA1.1.2049659497.1410967472
Host:localhost:8080
Origin:http://localhost:8080
Referer:http://localhost:8080/pp/user-account
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.124 Safari/537.36
X-Requested-With:XMLHttpRequest
Form Dataview sourceview URL encoded
userId:2
username:b
password:b
oper:edit
id:8
Response Headersview source
Content-Length:5
Content-Type:text/html;charset=ISO-8859-1
Date:Thu, 25 Sep 2014 07:09:26 GMT
Server:Apache-Coyote/1.1

这是失败的请求

Remote Address:127.0.0.1:8080
Request URL:http://localhost:8080/pp/ajaxuser
Request Method:POST
Status Code:404 Not Found
Request Headersview source
Accept:*/*
Accept-Encoding:gzip,deflate
Accept-Language:zh-TW,zh;q=0.8,en-US;q=0.6,en;q=0.4
Connection:keep-alive
Content-Length:55
Content-Type:application/x-www-form-urlencoded; charset=UTF-8
Cookie:JSESSIONID=B6D15A95251B1477473BC524E7E9E148; Siggraph-Fontresizer=105; targetEncodinghttp://your-site=1; PHPSESSID=k2fi36gbn8979riffibp2mt1f7; _ga=GA1.1.2049659497.1410967472
Host:localhost:8080
Origin:http://localhost:8080
Referer:http://localhost:8080/pp/user-account
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.124 Safari/537.36
X-Requested-With:XMLHttpRequest
Form Dataview sourceview URL encoded
userId:abc
username:abc
password:abc
oper:add
id:_empty
Response Headersview source
Content-Language:en
Content-Length:1089
Content-Type:text/html;charset=utf-8
Date:Thu, 25 Sep 2014 07:10:15 GMT
Server:Apache-Coyote/1.1

我看不出这两个请求之间有什么不同,所以我不明白为什么会出现这个问题

我还在UserAccount的开头添加了一个断点,但程序无法到达此断点,并且服务器显示此错误

WARNING: Could not find action or result: /pp/ajaxuser
No result defined for action com.pp.ajax.UserAccount and result input

我不知道如何追踪这个问题,我现在该怎么办?

1 个答案:

答案 0 :(得分:1)

您正在执行POST请求,验证拦截器可能会返回INPUT结果。通常,您可以通过向操作配置添加INPUT结果来解决此问题。

<action name="ajaxuser" class="com.pp.ajax.UserAccount">
    <result name="success">/out.jsp</result>
    <result name="input">/out.jsp</result>
</action>

您还可以通过从操作配置中删除validation interceptor或通过覆盖拦截器配置参数excludeMethods添加方法来从验证中排除此操作,然后您不需要此结果。