我使用jsp + servlets并且有一个表单。如何在不离开包含表单的实际页面的情况下将表单数据发送到servlet(到doPost()方法)?jsp表单发送数据到servlet而不改变页面
我想按下“提交”按钮,数据应该发送,我想仍然留在页面上的形式。我宁愿不使用JavaScript。
我有http://localhost/myproject/
<form action="http://localhost/myproject/anotherpage" method="POST">
First Name: <input type="text" name="first_name">
<br />
Last Name: <input type="text" name="last_name" />
<input type="submit" value="Submit" />
</form>
点击提交按钮我被转发到以下页面时:http://localhost/myproject/anotherpage
但我想留在
http://localhost/myproject/
编辑:现在我要写
request.getRequestDispatcher("/index.jsp").forward(request, response);
在doPost()方法中
但是,您如何通过发出POST请求离开页面? –
尝试使用ajax。例如jquery.ajax –