我正在使用 JSP 和 servlet 开发一个 Web 应用程序。
在我的 JSP 中,我有几种形式,例如以下
<form method="post" action="quotation">
<input type="submit" name="addStep" value="Add a Step" class="noLabel" />
</form>
我正在使用表单的“名称”属性在我的 servlet 的 doPost 方法中知道我应该调用哪个代码。
问题如下:
- 我在我的网络服务器中加载我的 jsp
- 我单击表单上的“添加步骤”按钮 => 应用了正确的代码
- 如果我通过在地址栏上按“enter”重新加载网页,则会再次应用相同的代码,因为我猜想在 Http 请求上没有重置 addStep 属性
您知道如何重置请求属性(此处为 addStep)以防止这种行为发生吗?
这是 doPost 方法:
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
request.setAttribute(DATABASE_ATT, databaseData);
this.getServletContext().getRequestDispatcher(VIEW)
.forward(request, response);
}