我试图在 ecilipse 中运行以下代码并得到错误为document.form.0 is Null or not an object
. 请帮助我解决问题。我创建了一个动作类。
<!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.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>