16 August 2016

Creating a JSP Web Application with a Form in Java NetBeans

Index.jsp
Java 2016
<%-- 
    Document   : index
    Created on : Aug 16, 2016, 9:59:38 AM
    Author     : Lonely
--%>

<%@ page import ="java.util.Date"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <% Date date = new Date();%>
    <body>
        <h1>Hello World!</h1>
        <p>Today's date is<%= date %> </p>
        <h1>Using form</h1>
        <form name="myForm" action="display.jsp" method="POST">
            <table border="0">
               
                <tbody>
                    <tr>
                        <td>First name: </td>
                        <td><input type="text" name="first" value="" size="50" /></td>
                    </tr>
                    <tr>
                        <td>Lats name: </td>
                        <td><input type="text" name="last" value="" size="50" /></td>
                    </tr>
                    <tr>
                        <td>Email: </td>
                        <td><input type="text" name="email" value="" size="50" /></td>
                    </tr>
                    <tr>
                        <td>Gender:</td>
                        <td><input type="text" name="gender" value="" size="30" /></td>
                    </tr>
                    <tr>
                        <td>Date of Birth:</td>
                        <td><input type="text" name="birth" value="MM/DD/YYYY" size="30" /></td>
                    </tr>
                </tbody>
            </table>
            <input type="reset" value="Clear" name="clear" />
            <input type="submit" value="Submit" name="submit" />
        </form>
    </body>
</html>
Display.jsp
Java 2016
<%-- 
    Document   : display
    Created on : Aug 16, 2016, 11:52:46 AM
    Author     : Lonely
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Using form</title>
    </head>
    <body>
        <h1>Using form</h1>
        <% 
            String firstName = request.getParameter("first");
            String lastName = request.getParameter("last");
            String email = request.getParameter("email");
            String gender = request.getParameter("gender");
            String birth = request.getParameter("birth");
        %>
        <table border="1">
            <tbody>
                <tr>
                    <td>Firt Name: </td>
                    <td><%= firstName %></td>
                </tr>
                <tr>
                    <td>Last Name:</td>
                    <td><%= lastName%></td>
                </tr>
                <tr>
                    <td>Email:</td>
                    <td><%= email%></td>
                </tr>
                <tr>
                    <td>Gender:</td>
                    <td><%= gender%></td>
                </tr>
                <tr>
                    <td>Birth:</td>
                    <td><%= birth%></td>
                </tr>
            </tbody>
        </table>

    </body>
</html>

0 nhận xét:

Post a Comment

 

BACK TO TOP

Xuống cuối trang