下面的代码来自我的addRemove.jsp,它服务的目的是要表单,一个用于向我的数据库的单词表提交一个新单词,一个用于删除一个。要添加一个词,必须完成 GermanName、gender 和 englishName。提交后,用户可以看到更新后的表格。
在此之下,我创建了一个删除表单,用户必须在其中指定 GermanName 值才能删除该单词。该按钮应将用户再次引导至更新的表格。问题是只有第一个提交按钮会重定向我。此外,似乎根本没有发生删除。我将只提供 addRemove.jsp,但如果您认为还需要查看它,我也可以发布 WordDataBean.java 文件。
添加删除.jsp
<?xml version = "1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<%-- beans used in this JSP --%>
<jsp:useBean id = "word" scope = "page"
class = "org.me.jsp.beans.WordBean" />
<jsp:useBean id = "wordData" scope = "request"
class = "org.me.jsp.beans.WordDataBean" />
<html xmlns = "http://www.w3.org/1999/xhtml">
<head>
<title>Student Registration Form</title>
<style type = "text/css">
body {
font-family: tahoma, helvetica, arial, sans-serif;
}
table, tr, td {
font-size: .9em;
border: 1px groove;
padding: 2px;
background-color: white;
}
</style>
</head>
<body>
<jsp:setProperty name = "word" property = "*" />
<% // start scriptlet
if (word.getGermanName() == null
|| word.getGender() == null
|| word.getEnglishName() == null) {
%> <%-- end scriptlet to insert fixed template data --%>
<form method = "post" action = "addRemove.jsp">
<p>To add a new word complete the form below</p>
<table>
<tr>
<td>German name</td>
<td>
<input type = "text" name = "germanName" />
</td>
</tr>
<tr>
<td>Gender</td>
<td>
<input type = "text" name = "gender" />
</td>
</tr>
<tr>
<td>English Name</td>
<td>
<input type = "text" name = "englishName" />
</td>
</tr>
<tr>
<td colspan = "2">
<input type = "submit"
value = "Submit" />
</td>
</tr>
</table>
</form>
<% // continue scriptlet
} // end if
else {
wordData.addWord(word);
%> <%-- end scriptlet to insert jsp:forward action --%>
<%-- forward to display word list --%>
<jsp:forward page = "wordListView.jsp" />
<% // continue scriptlet
} // end else
%> <%-- end scriptlet --%>
<% // start scriptlet
if (word.getGermanName() == null
|| word.getGender() == null
|| word.getEnglishName() == null) {
%> <%-- end scriptlet to insert fixed template data --%>
<form method = "post" action = "addRemove.jsp">
<p>To remove word complete the form below</p>
<table>
<tr>
<td>German name</td>
<td>
<input type = "text" name = "germanName" />
</td>
</tr>
<tr>
<td colspan = "2">
<input type = "submit"
value = "Remove" />
</td>
</tr>
</table>
</form>
<% // continue scriptlet
} // end if
else {
wordData.removeWord(word);
%> <%-- end scriptlet to insert jsp:forward action --%>
<%-- forward to display word list --%>
<jsp:forward page = "wordListView.jsp" />
<% // continue scriptlet
} // end else
%> <%-- end scriptlet --%>
</body>
</html>