我在我的php文件的同一文件夹中运行我的文件,并且我还使用Apache的管理员帐户登录。
这是我的代码:
<?php
exec("testbat.bat");
?>
答案 0 :(得分:0)
创建一个文件并将其另存为filename.bat
这是一个例子
批处理文件名是test.bat
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String email = request.getParameter("email");
String password = request.getParameter("password");
if (Login.validate(email, password)) {
RequestDispatcher rd = request.getRequestDispatcher("servlet2");
rd.forward(request,response);
}
else {
out.print("Sorry username or password error");
RequestDispatcher rd = request.getRequestDispatcher("index.html");
rd.include(request,response);
}
out.close();
}
之后从php文件“executeme.php”
调用它public static boolean validate(String email,String password){
boolean status=false;
try {
Class.forName("com.mysql.jdbc.Driver");
String conStr = "jdbc:mysql://localhost:3306/virtuoso?user=root&password=";
Connection con = DriverManager.getConnection(conStr);
String sql = "SELECT * FROM tutor WHERE email=? and password=?";
PreparedStatement ps = con.prepareStatement(sql);
ps.setString(1,email);
ps.setString(2,password);
ResultSet rs = ps.executeQuery();
status = rs.next();
} catch (ClassNotFoundException | SQLException e) {
//empty
}
return status;
}