Sei sulla pagina 1di 15

JSP HTML Form source example

text zoom
Previous: Best Practices in JSP Creating Web Application :Next

The previous section has explained what all controls are used in HTML for creating the forms. Lets see
with the help of below example how do we get the form data in JSP page which is send by the user.

We need to first define which JSP page should be accessed when this form is submitted. This can be
achieved by the action attribute in the <form>. For example:- <form action="/login.jsp"> will generate
a request for the login.jsp page when the submit button will be clicked for the form.

We will be creating the input1.jsp file which will show the data which user has sent from login.html
page from the previous example.

Example:-

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"


"http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Language" content="en-us">

<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">

<title>Login Form</title>

</head>

<body>

<p align="left"><b>Login Form

</b></p>

<form method="POST" action="login.jsp" name="loginForm">

<table border="1" width="50%" cellspacing="1" cellpadding="0" id="table1">

<tr>
<td width="50%">&nbsp;Login Name</td>

<td><input type="text" name="loginName" size="20"></td>

</tr>

<tr>

<td width="50%">Password</td>

<td><input type="password" name="password" size="20"></td>

</tr>

</table>

<p><input type="submit" value="Submit" name="B1"><input type="reset" value="Reset"


name="B2"></p>

</form>

</body>

</html>

JSP page:-

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"

pageEncoding="ISO-8859-1"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"


"http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

<title>Login Form Data</title>


mayor
robert adi
anywhere he always married married and workers in
jakarta jakarta tangerang always go with writing and
writing in everyday situations which always followed
him everywhere from
robert adi married with a baby boy around Jakarta for
photos of these workers continue to go with him
</head>

<body>

<b>Submitted Values are </b>

<table border="1" width="50%" cellspacing="1" cellpadding="0" id="table1">

<tr>

<td width="50%">&nbsp;Login Name</td>

<td><%=request.getParameter("loginName") %></td>

</tr>

<tr>

<td width="50%">Password</td>

<td><%=request.getParameter("password") %></td>

</tr>

</table>

</body>

</html>
Output:- The following screen will be displayed when login form will gets submitted.

* Printer Friendly
* Email to a friend
* Add to my Favourites
* Download PDF version
* Report Bad Submissions
* Submit Feedback

Share This ...

Previous: Best Practices in JSP Creating Web Application:Next


Give feedback and win a prize.
Jsp Discussion

* - Two forms in one JSP


* - PASS VARIABLES BETWEEN 2
* - Table data
* - Unable to laod the image
* - The Ultimate Web UI Frame

...more
Jsp Source Code

* - Writing Log Records To Standard


error
* - Serializing An Immutable Bean
property To Xml
* - Preventing A Bean Property From
being Serialized To Xml
* - Deserializing A Bean From Xml
* - Serializing A Bean To Xml

...more
Jsp Related Tutorials

* - Java Tutorial
* - Hibernate Tutorial
* - Spring tutorial
* - Java XML Tutorial
* - JDBC Tutorial

...more
New Jsp Resources

...more

Enter your search terms Submit search form VisualBuilder


Web
Member Panel
remember me

* Forgot your password?


* Resend Activation Email!
* New User? Click Here!

Explore VisualBuilder
Popular Links Popular Links Popular Links Popular Links

* - Java Tutorial
* - EJB 3 Tutorial
* - Spring Tutorial
* - JDBC Tutorial
* - J2EE Design tutorial
* - JSP tutorial
* - Struts tutorial
* - Hibernate tutorial

* - C# Tutorial
* - ASP.NET tutorial
* - ASP Tutorial
* - .NET Tutorial
* - Ajax Tutorial
* - Database Tutorial

* - JSP
* - Java
* - ASP.NET
* - PHP
* - ASP

* - Source Code
* - Components
* - Articles
* - Answers
* - Forum
* - Websites
* - Tutorials

* Contact Us
*|
* Site Index
*|
* Archives
*|
* Terms of Use
*|
* Contributor Policy
*|
* Privacy & Cookies

Copyright © 2010 VisualBuilder. All rights r

Potrebbero piacerti anche