我想使用 scriptlet 编写单击“执行测试”按钮时调用的函数此代码不起作用:
这是我的jsp代码:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<html:file properties="tonFichier" name="tonForm"/>
<%!
public void executeTest() {
java.util.Date d = new java.util.Date();
System.out.println(d.toString()); }
%>
<form enctype="multipart/form-data" method="get">
<div>
<input type="submit" value="Execute Test" onclick="executeTest()" >
</div>
</form>
</body>
</html>
请提供任何帮助
干杯
您可以执行以下操作。
if(request.getParameter("btnSubmit")!=null) //btnSubmit is the name of your button, not id of that button.
{
java.util.Date d = new java.util.Date();
System.out.println(d.toString());
}
<input type="submit" id="btnSubmit" name="btnSubmit" value="Execute Test"/>
onclick="executeTest()"
使用按钮尝试调用 Javascript 函数。按照上面代码中提到的方式更改按钮标签,并将此代码封装在 sciptlet 中。当您单击此按钮时,它将完成这项工作。
此外,您可能想要替换
System.out.println(d.toString());
with
out.println(d.toString());
在你的代码中。
另外,在您的表单标签中,
<form enctype="multipart/form-data" method="get">
属性enctype="multipart/form-data"
上传文件时需要。如果不是这种情况,您应该将其删除,并且
method="post"
表单属性enctype="multipart/form-data"
不能工作,如果你使用method="get"
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)