[英]How do I make my HTML and java form redirect to itself so that the user can input another item?
I am not even sure if I should use redirect. 我什至不确定是否应该使用重定向。 What I have is a form (html) that uses java to read the input when the submit button is pressed and that part works fine.
我所拥有的是一种表单(html),当按下“提交”按钮时,该表单会使用java读取输入,并且该部分可以正常工作。 What I want is to be able to enter another item in the same form and submit this new item the same way.
我想要的是能够以相同的形式输入另一个项目并以相同的方式提交此新项目。 I am using a Java servlet.
我正在使用Java servlet。
I think you have 2 options. 我认为您有2个选择。 The first one is to put a redirect script on the page that appears after the form is submitted to redirect the user to the previous page.
第一个是将重定向脚本放在提交表单后出现的页面上,以将用户重定向到上一页。 It should be something like:
应该是这样的:
<html>
...
<META HTTP-EQUIV="refresh" CONTENT="5;URL=PreviousPageURL">
<body>
You have successfully created an item! <br/>
You will be redirected to the previous page to create more items after 5s.
</body>
...
</html>
Another way is to use Ajax to submit your form instead. 另一种方法是使用Ajax提交表单。 Try this jQuery plugin ajaxForm :
试试这个jQuery插件ajaxForm :
<form id="myForm">
...
</form>
<div id="status"></div> // Show the result here
<script type="text/javascript">
$('#myForm').ajaxForm({
beforeSubmit: function() {
$("#status").html("");
},
success: function(response){
var status = $(response).find("status").text();
$("#status").html(status);
},
dataType: "xml"
});
</script>
In the above example, I return the result as an xml file like this: 在上面的示例中,我将结果作为xml文件返回,如下所示:
<status>Successful/Failed/etc.</status>
You can also return the result as a string. 您还可以将结果作为字符串返回。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.