Javascript 未调用操作类:Document.form.0为Null或不是对象
我已尝试在ecilipse中运行以下代码,并以Javascript 未调用操作类:Document.form.0为Null或不是对象,javascript,eclipse,struts,Javascript,Eclipse,Struts,我已尝试在ecilipse中运行以下代码,并以文档的形式获取错误。form.0为Null或不是对象。请帮我解决这个问题。我创建了一个动作类 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"&g
文档的形式获取错误。form.0为Null或不是对象。请帮我解决这个问题。我创建了一个动作类
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
<%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles"%>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"%>
<head>Welcome To struts Application.
<title>Struts</title>
<script language="javascript">
function input() {
alert('Insie input function');
if (document.forms[0]) {
alert('true');
document.forms[0].reset();
}
var abs = '<%=request.getContextPath()%>'
alert(abs);
document.form[0].action=abs + "index.do?submit=execute";
document.form[0].submit();
}
</script>
</head>
<body>
<html:form method="post" action="/index">
<html:text property="username"></html:text>
<html:password property="password"></html:password>
<html:button value="Hello" property="button"
onclick="javascript:input();"></html:button>
<html:link page="/index.do">Test the Action</html:link>
</html:form>
</body>
</html>
欢迎使用struts应用程序。
支柱
函数输入(){
警报(“Insie输入功能”);
if(document.forms[0]){
警报(“真”);
document.forms[0].reset();
}
var abs=''
警报(abs);
document.form[0]。action=abs+“index.do?submit=execute”;
document.form[0]。提交();
}
测试动作
我已将Struts.config文件配置如下:
<action path="/index"
name="indexform" scope="request" parameter="submit"
validate="false" type="com.work.Action.IndexAction"
>
<forward name="success" path="success.jsp" />
<forward name="failure" path="path.error" />
</action>
它是文档。表单[0]
(注意复数形式)。这将显示在JavaScript控制台中
另外,从
中删除额外的内容(即“欢迎使用struts应用程序”部分)
并使用空标签表单来处理空标签(即,
)。非常感谢Dave。这些愚蠢的错误总是让我付出代价。