我有一个这个java类:
import java.io.*;
public class sqlldrIam{
public static void chargement(){
try{
String sqlldrCmd="SQLLDR userid=scott/tiger
control=C:\\Users\\imrane\\descktop\\imrane.ctl";
System.out.println("operateur sqlldr started");
Runtime.getRuntime().exec(sqlldrCmd);
System.out.println("operateur sqlldr ended");
}
catch(Exception e){
e.printStackTrace();
}}}
我有这个jsp页面:
<%@page import="dao.sqlldrIam"%>
<%@page language="java" contentType="text/html;
charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01
Transactional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Reconciliation</title>
<style type="text/css">
@import url(yassir.css);
@import url(imrane.css);
</style>
</head>
<body>
<img src="C:\Users\imrane\Desktop\logo230.png"/>
</br></br></br></br> <center>
<h4> Données opérateur</h4>
<input type="submit" value="Chargement opérateur"
onclick="<%dao.sqlldrIam.chargement();%>">
</br>
<img src="C:\Users\imrane\Desktop\logo400.png"/>
</body>
</html>
问题是onclick需要Javascript和我我给他java,然后服务员在我点击短支持之前处理代码解决方案是创建一个函数javascipt,它调用带有ajax的servlet,并在servlet one调用方法java。 但是有人试过几次这样做而没有达到好的代码。 谢谢你给我代码。
答案 0 :(得分:0)
你永远不能在Javascript中直接调用Java函数。
有两种方法可以实现这一目标: 1)使用ajax将数据发布到WebServer,服务器将调用您的servlet。 如果您熟悉jquery,请参阅http://www.w3school.com.cn/jquery/ajax_ajax.asp。
2)提交表格。 有关表单元素的一般用法,请参阅http://www.w3school.com.cn/tags/tag_form.asp。