user1789951
user1789951

Reputation: 661

Linking HTML to JSP page

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>

Upvotes: 1

Views: 26122

Answers (2)

AllTooSir
AllTooSir

Reputation: 49362

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.

Upvotes: 3

Prabhakar Manthena
Prabhakar Manthena

Reputation: 2303

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

Upvotes: 2

Related Questions