简体   繁体   English

如何使HTML和Java表单重定向到自身,以便用户可以输入其他项?

[英]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.

相关问题 我如何为我的代码创建一个循环,直到用户输入正确的代码为止? - How can i make a loop for my code so it runs until user gives correct input? 当用户输入不正确时,如何使while / else语句正确重复? - How would I make this so the while/else statement correctly repeats itself when the user input is incorrect? 我如何做到这一点,以便用户可以连续输入,但可以使用符号停止输入? - How do I make it so the user has continuous input but can stop this with the use of a symbol? 如何使用户可以选择一个人的性别? - How do I make it so that the user can choose the gender of a person? 如何使我的代码检查用户是否输入了字母字符? [Java] - How do I make my code check that the user has input a alphabetical character? [Java] Java:如何确保或使用户输入字符串中的逗号? - Java: How do I ensure, or make a user, input a comma in a string? 我需要根据用户输入重复此 java 代码,我无法使用我目前拥有的代码使其重复 - I need to make this java code repeat based on the user input and I cannot make it repeat using the code that I do have so far 将实例添加到arraylist集合后,如何进行创建,以便可以在迭代期间输入实例所需的变量? - After adding my instances to my arraylist collection, how do I make it so that I can input the variables I need for my instances during iteration? 如何使我的代码重复出现? - How do I make make my code repeat itself? 如何在连接时使Java应用程序向Oracle标识? - How do I make my Java application identify itself to Oracle on connection?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM