WTA12 JSP Forms DatabaseConnectivity

WTA12 JSP Forms DatabaseConnectivity - Java Server Pages...

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon
1 Java Server Pages (JSP) Forms Database Connectivity 1 Execution b Load Apache Tomcat Server. b Start Tomcat. b Store the .jsp programs in C:\Program Files\Apache Group\Tomcat 4.1\webapps\examples\jsp b To execute the jsp program open IE and give the url as http://localhost:8080/examples/jsp/ name offile.jsp 2
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 Forms 3 Working with HTML Form b HTML pages have also used to create the forms which gather the information from user in the interactive web pages. In HTML we have <form> tag and form controls which are used to create the forms in web pages. All the controls related to a particular form need to define inside the <form></form> tag. b The browser will always submit the data as name/value pair from form. So all the controls need to have the name attribute whose data you need to pass to the server. 4
Background image of page 2
3 Ex 1 : Login.html <html> <head> <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%"> 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> 5 Ex 1 : Login.jsp <html> <head> <title>Login Form Data</title> </head> <body> <b>Submitted Values are </b> <table border="1" width="50%" cellspacing="1" cellpadding="0" id="table1"> <tr> <td width="50%"> Login Name</td> <td> <%=request.getParameter("loginName") %> </td> </tr> <tr> <td width="50%">Password</td> <td> <%=request.getParameter("password") %> </td> </tr> </table> </body> </html> 6
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
4 Ex 2 : Form Validation b There are two mainly two types of form validations: server- side (using JSP ASP, etc), and client-side (usually done using JavaScript). b The following code is the difference between the server side and client side validations 7 validateRegistration.jsp <html> <head> <title>Registration Form</title> </head> <script> function validateForm(form){ if(form.firstName.value==''){ alert ("First Name can not be blank"); return false;} if(form.lastName.value==''){ alert ("Last Name can not be blank"); return false;} if(form.introduction.value==''){ alert ("Introduce Yourself can not be blank"); return false;} 8 if(form.phone.value==''){ alert ("Phone can not be blank"); return false;} if(form.address.value==''){ alert ("Address can not be blank"); return false;} if(form.city.value==''){ alert ("City can not be blank"); return false; } if(form.state.value==''){ alert ("State can not be blank"); return false; } } </script>
Background image of page 4
5 registrationForm.jsp(1) <body> <p align="left"><b>Registration Form</b></p> <form name="registerationForm" method="POST" action="validateRegistration.jsp" onsubmit="return validateForm(document.registerationForm); ">
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 15

WTA12 JSP Forms DatabaseConnectivity - Java Server Pages...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online