使用scriptlet的onClick函数调用 [英] onClick function call using scriptlet
问题描述
我想使用scriptlet编写单击执行测试"按钮时调用的函数,此代码不起作用:
I want to use scriptlet to write the function called when clicking the Execute Test button This code didn't work :
这是我的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中.当您单击此按钮时,它将完成工作.
onclick="executeTest()"
with your button tries to invoke a Javascript function. Change your button tag as mentioned in the above code and encolse this code within a sciptlet. It will do the job when you click this button.
此外,您可能需要替换
System.out.println(d.toString());
使用
out.println(d.toString());
在您的代码中.
此外,在您的表单标签中,
Also, in your form tag,
<form enctype="multipart/form-data" method="get">
上传文件时,属性enctype="multipart/form-data"
是必需的.如果不是这种情况,则应将其删除,并且
the attribute enctype="multipart/form-data"
is required when you're uploading files. You should remove it, if such is not a case and
method="post"
如果使用method="get"
这篇关于使用scriptlet的onClick函数调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!