Linking HTML to JSP page

只谈情不闲聊 提交于 2020-02-05 05:20:29

问题


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 Page

<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

<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>

回答1:


You should specify the input name attribute. Try this,

<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




回答2:


You need to use the name attribute in the form fields .

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

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

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

OR

${param.email}

OR

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

Here are the complete list of attributes.

name = string #

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



来源:https://stackoverflow.com/questions/16756528/linking-html-to-jsp-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!