我已经通过jsp创建并将数据添加到数据库中。现在我的问题是编辑/更新数据库应该通过html表单完成。在我选择学生rollno和表单应该显示所有其他字段然后我可以编辑它并更新数据库。
editcourse.jsp
<!DOCTYPE html>
<html>
<head>
<link href="css/redmond/jquery-ui-1.10.2.custom.min.css" media="screen" rel="stylesheet"/>
<link href="css/default.css" media="screen" rel="stylesheet"/>
<link href="sidebarmenu.css" rel="stylesheet" type="text/css">
<script src="sidebarmenu.js"></script>
<script src="scripts/jquery-1.9.1.min.js"></script>
<script src="scripts/jquery-ui-1.10.2.custom.min.js"></script>
</head>
<body>
<!--<form id="frmExamRegistration" method="post" enctype="multipart/form-data" class="anu">-->
<form name="f1" method="post" class="anu" action="Edit_coursedetails.jsp">
<%@include file="adminheader.jsp"%>
<%@include file="sidemenus.jsp" %>
<div id="container">
<div style="float:right;width:10%;border:0;font-color:#163362"><a href=logout.jsp">Log Out</a></div><br>
<div class="content"><center>Edit Course</center><br>
<div class="formElements,rightcol" align="center">
<label>Course code:
<span><input type="text" id="txtCoursecode" name="txtCoursecode" ></span></label>
</div><br>
<div class="buttons">
<button type="submit" class="primaryAction">Edit</button>
<button type="reset" class="primaryAction">Clear</button>
</div>
</div>
</div>
</form>
</body>
</html>
edit_coursedetails.jsp
<!DOCTYPE html>
<html>
<head>
<link href="css/redmond/jquery-ui-1.10.2.custom.min.css" media="screen" rel="stylesheet"/>
<link href="css/default.css" media="screen" rel="stylesheet"/>
<link href="sidebarmenu.css" rel="stylesheet" type="text/css">
<script src="sidebarmenu.js"></script>
<script src="scripts/jquery-1.9.1.min.js"></script>
<script src="scripts/jquery-ui-1.10.2.custom.min.js"></script>
</head>
<body>
<!--<form id="frmExamRegistration" method="post" enctype="multipart/form-data" class="anu">-->
<%
ccode=request.getParameter("txtCoursecode");
try {
Statement st = null;
st=conn.createStatement();
ResultSet rs = st.executeQuery("select * from courses where course='"+txtCoursecode+"'");
if(rs.next())
{
cname=rs.getString("cname");
Description=rs.getString("Description");
}
%>
Edit courses
<form name="f1" method="post" class="anu" action="Add_coursedetails.jsp">
<%@include file="adminheader.jsp"%>
<%@include file="sidemenus.jsp" %>
<div id="container">
<div style="float:right;width:10%;border:0;font-color:#163362"><a href=logout.jsp">Log Out</a></div><br>
<div class="content"><center>Add Course</center><br>
<div class="formElements,rightcol" align="center">
<label>Course code:
<span><input type="text" id="txtCoursecode" name="txtCoursecode" value="<%=rs.ccode%>"></span></label>
</div><br>
<div class="formElements,rightcol" align="center">
<label>Course Name:
<span><input type="text" id="txtCoursename" name="txtCoursename" value="<%=rs.cname%>"></span></label>
</div><br>
<div class="formElements,rightcol" align="center">
<label>Duration:
<span>        <input type="text" id="txtDuration" name="txtDuration" value="<%=rs.getString("3")%>"></span></label>
</div>
<div class="buttons">
<button type="submit" class="primaryAction">Update</button>
<button type="reset" class="primaryAction">Clear</button>
</div>
</div>
</div>
<%
}
}
catch(Exception e){}
%>
</form>
</body>
</html>
以editcourse形式给出ccode它应该显示来自数据库的所有其他字段的值,然后我可以修改它
答案 0 :(得分:0)
您可以在表单操作属性中使用ajax或给出jsp的url。 然后在jsp中从请求获取txtRollno,从数据库中检索此rollno的字段,将数据填充到适当的字段中,然后您可以编辑它然后更新到数据库。
答案 1 :(得分:0)
正如其他朋友所说,你需要使用ajax调用而你说你不知道ajax。 所以我认为这些教程可以帮助您:
祝你好运;)