怪怪的 No result defined for action 错误(解决办法)
================================================================================
环境:eclipse3.2 struts2.0.6 + myeclipse5 +tomcat5.0.17
strusts.xml的action是这样写的,正确的。
================================================================================
<!-- 删除某个 -->
<action name="Dele"
class="com.Struts.Action.ListAction" method="Delete">
<result name="DeleteError">/Error.jsp?info=del</result>
</action>
==================================================================================
对应com.Struts.Action.ListAction--类的方法,也看似正常的
public class ListAction extends ActionSupport {
private static final long serialVersionUID = -6486171247622587609L;
...
...
private Integer PId;
public Integer getPId(){
return this.PId;
}
public void setPId(Integer PId){
this.PId=PId;
public String Delete()throws Exception{
HttpServletRequest request = ServletActionContext.getRequest();
HttpServletResponse response = ServletActionContext.getResponse();
HBService HbSession = HBService.instance();
HbSession.SessionClean();
TeamPracticeImpl _TeamPracticeImpl = TeamPracticeImpl.instance();
//...
try {
String[] idsArray = request.getParameterValues("checkboxId");
if (idsArray==null){
return "DeleteError";
}
for (int i = 0; i < idsArray.length; i++) {
HbSession.TransactionBegin();
_TeamPracticeImpl.deleteMemberOther(Integer.valueOf(idsArray[i])); //delete by Ids array
HbSession.TransactionCommit();
}//for
}// try
catch (java.lang.Exception ee){
//ee.printStackTrace();
HbSession.TransactionRollback();
return "DeleteError";
}
finally{
HbSession.SessionClose();
}
out.println("<script>"+"window.location='List.do?PId="+PId+"';</script>");
return NONE;
}//end
浏览器键入测试
url: http://localhost:8080/myhome/Dele.do?PId=11
此url由上一个页面的点击触发,
以下是返回的错误信息:
console端返回
ERROR [org.apache.struts2.dispatcher.Dispatcher] - Could not find action or result
No result defined for action
浏览器返回:
HTTP Status 500 -
--------------------------------------------------------------------------------
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
No result defined for action .....
=======
检查主调用jsp页面
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<script language="javascript" src="../js/checkbox.js">
</script>
<script language="javascript" src="../js/SWList.js">
</script>
<link rel="stylesheet" type="text/css" href="../css/style.css">
<title> </title>
<style type="text/css">
<!--
.STYLE3 {color: #000000}
.STYLE4 {color: #FFFFFF}
-->
</style>
<script language='JavaScript' >
function submitByDelete(){
return "Dele.do?PId=11"; //此处第一次出现 PId
}
</script>
</head>
<body onLoad="Resize();">
<form name="searchform" method="post" action="">
<input type="hidden" name="PId" id="PId" value="11"> //此处第二次出现PId
...
...
解决办法:
去掉其中一个关于PId的参数
原因:
第一个PId,servlet 由get获得(url后面进来的)
第二个PId,servlet 由post获得(通过form进来的)
这可能是导致struts2不能识别,最终返回了错误。