我尝试将代码重写为jsp,但我只能测试代码连接到数据库的部分。
<?php
$connect=mysql_connect("localhost","root","");
if (!$connect) {
die("Cannot connect to the server");
}
$db=mysql_select_db("payroll",$connect);
if (!$db) {
die("Cannot read the database");
}
if (isset($_POST['delete'])) {
if(isset($_POST['employee'])) {
mysql_query("DELETE FROM employee WHERE EMP_ID=\"".$_POST['employee']."\"");
}
header("Location:manage.php");
}
?>
这是我可以翻译的地方 &LT;% 用户currentUser = null; Integer currentUserId = null;
if(session.getAttribute("name") == null) {
response.sendRedirect(request.getContextPath() + "/normal/login.jsp?previousPageURL=user/edit_profile.jsp");
} else {
currentUser = (name)session.getAttribute("name");
currentUserId = currentname.getId();
}
%GT;
答案 0 :(得分:0)
Class.forName("com.mysql.jdbc.Driver");
Connection con;
con =DriverManager.getConnection("jdbc:mysql://localhost/payroll", dbuser, dbpassword);
PreparedStatement stmt = con.prepareStatement("DELETE FROM employee WHERE EMP_ID="+request.getParameter("employee"));
stmt.execute();
stmt.close();