java 将 HTML 链接到 JSP 页面

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16756528/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 23:54:25  来源:igfitidea点击:

Linking HTML to JSP page

javahtmljspservlets

提问by user1789951

I'm have problems linking my HTML and JSP. Just trying to make a simple html page to take a "email" and "password" then have the jsp display on the next page. But when i click submit the parameters dont get passed i just get "null", any ideas where im going wrong?

我在链接 HTML 和 JSP 时遇到问题。只是试图制作一个简单的html页面来获取“电子邮件”和“密码”,然后在下一页上显示jsp。但是当我点击提交参数没有通过我只是得到“空”,任何想法我哪里出错了?

HTML Page

HTML页面

<html>

<head>
        <title>Enter your email and password</title>
</head>

<body>

        <form action="form.jsp" method="get">
        <table cellspacing="5" border="0">
                <tr>
                     <td align="right">Email:</td>
                     <td><input type="text" email=email></td>
                </tr>

                <tr>
                     <td align="right">Password:</td>
                     <td><input type="text" password=password></td>
                </tr>

                <tr>
                     <td></td>
                     <td><br><input type="submit" value="Submit"></td>
                </tr>
        </table>
        </form>
</body>
</html>

JSP Page

JSP页面

<html>
<body>

        <%
        // get info from request
        String email = request.getParameter("email");
        String password = request.getParameter("password");
        %>

        <p>Here is the info you provided:</p>

        <table cellspacing="5" cellpadding="5" border="1">
            <tr>
                <td align="right">Email:</td>
                <td><%= email %></td>
            </tr>

            <tr>
                <td align="right">Password:</td>
                <td><%= password %></td>
            </tr>

        </table>


        <form action= "Next" method="post">
                <input type="submit" value="Return">
        </form>

        </body>
        </html>

回答by NINCOMPOOP

You need to use the nameattribute in the form fields .

您需要name在表单字段中使用该属性。

<input type="text" name="email"></td>

The value of "email" can be retrieved in JSP as :

“email”的值可以在 JSP 中检索为:

String email = request.getParameter("email");

OR

或者

${param.email}

OR

或者

<c:out value="${param.email}"/> <%--(Using JSTL)--%>

Here are the complete listof attributes.

这是完整的属性列表

name = string #

名称 = 字符串 #

The name part of the name/value pair associated with this element for the purposes of form submission.

用于表单提交的与此元素关联的名称/值对的名称部分。

回答by Prabhakar Manthena

You should specify the input nameattribute. Try this,

您应该指定输入name属性。试试这个,

<form action="form.jsp" method="get">
        <table cellspacing="5" border="0">
                <tr>
                     <td align="right">Email:</td>
                     <td><input type="text" name="email"></td>
                </tr>

                <tr>
                     <td align="right">Password:</td>
                     <td><input type="text" name="password"></td>
                </tr>

                <tr>
                     <td></td>
                     <td><br><input type="submit" value="Submit"></td>
                </tr>
        </table>
        </form>

For more info you can try this link

有关更多信息,您可以尝试此链接