Form Code in JSP and Servlet

Form Code in JSP and Servlet

Hi, I am looking for a form code in JSP and Servlet.

View Answers

April 16, 2008 at 8:43 PM

HI,

Here is the form code:
----

<html>
<title>registration form</title>

<head>

<script language="JavaScript">

function isProper(string) {

if (!string) return false;
var iChars = "*|,\":<>[]{}`\';()@&$#%";

for (var i = 0; i < string.length; i++) {
if (iChars.indexOf(string.charAt(i)) != -1)
return false;
}
return true;
}
function validateForm(theForm){

if(theForm.firstname.value==""){
//Please enter accountholder
alert("Enter the First Name.");
theForm.firstname.focus();
return false;
}

if (isProper(theForm.firstname.value) == false) {
alert("Please enter a valid First Name.");
theForm.firstname.focus();
return false;
}

if(theForm.firstname.value.length > 20) {
alert("Maximum 20 characters allowed for 'First Name'.")
theForm.firstname.focus() ;
return false;
}

if(theForm.address.value==""){
//Please enter accountholder
alert("Enter the address.");
theForm.address.focus();
return false;
}

if(theForm.email.value==""){
//Please enter accountholder
alert("Enter the E-mail address.");
theForm.email.focus();
return false;
}

if(theForm.contect.value==""){
//Please enter accountholder
alert("Enter the contect number.");
theForm.contect.focus();
return false;
}
return true;
}

</script>
</head>
<body>
<table border="1" width="50%" cellpadding="0" cellspacing="0">
<tr>
<td width="100%">
<h2>Registration form</h2>
<form method="GET" action="DataInsertServletExam" onsubmit="return validateForm(this);">
<table border="1" width="100%" cellspacing="0" cellpadding="0">
<tr>
<td><b>Name:</b></td>
<td><input type="text" name="firstname" size="30"></td>
</tr>
<tr><td><b>Address:</b></td>
<td><input type="text" name="address" size="50"></td>
</tr>
<tr>
<td><b>E-mail:<b></td>
<td><input type="text" name="email" size="30"></td>
</tr>
<tr><td><b>Contect No:</b></td>
<td><input type="text" name="contect" size="30"></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="submit" value="Submit" name="submit">
<input type="reset" value="Reset" name="reset">
</td>

</tr>
</table>
</form>
<p>&nbsp;</p>
</tr>
</td>
</table>
</body>

</html>

April 16, 2008 at 8:44 PM

Please enter following code in web.xml file:
-----------------------------------------
<servlet>
<servlet-name>InsertDataExample</servlet-name>
<servlet-class>DataInsertServletExam</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>InsertDataExample</servlet-name>
<url-pattern>/DataInsertServletExam</url-pattern>
</servlet-mapping>
---------------------------------

April 16, 2008 at 8:45 PM

And finally here is the code of Servlet:
--------------------------------------

import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class DataInsertServletExam extends HttpServlet{
public void doGet(HttpServletRequest request, HttpServletResponse response)throws
ServletException, IOException{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
Connection con = null;
String url = "jdbc:mysql://localhost:3306/";;
String db = "register";
String driver = "com.mysql.jdbc.Driver";
try{
Class.forName(driver);
con = DriverManager.getConnection(url+db,"root","root");
try{
Statement st = con.createStatement();
String firstname=request.getParameter("firstname");
String address=request.getParameter("address");
String email=request.getParameter("email");
String contect=request.getParameter("contect");
int val = st.executeUpdate("insert regiform values('"+firstname+"','"+address+"','"+email+"','"+contect+"')");
con.close();
out.println("Successfully insert data in database");
}
catch (SQLException ex){
System.out.println("SQL statement is not executed!");
}
}
catch (Exception e){
e.printStackTrace();
}

}
}
------------------------------









Related Tutorials/Questions & Answers:
java code for uploading a resume in a form - JSP-Servlet
java code for uploading a resume in a form  can anyone help me with the codes 4 uploading a resume in a registration form  Refer this link http://www.devsphere.com/mapping/docs/guide/upload.html Thanks Rajanikant
JSP code for registration form
JSP code for registration form  Haiiii can u please tell me how to encrypt password field in registration form and to compare both password and confirm password fields using jsp
Advertisements
jsp code - JSP-Servlet
jsp code  Can anyone help me in writing jsp/servlet code to retrieve files and display in the browser from a given directory.  Hi Friend, Try the following code: Thanks
disable the form - JSP-Servlet
Multiple form are created in Jsp. Servlet is used to insert the data. Ajax is used... Ajax. after response is coming to the jsp page,particular form button... wrote jsp page in that 8 forms are there.all forms are same but the input values
jsp code - JSP-Servlet
jsp code  hi i am doing project work i am generating time table for this i have taken form courseyear textbox semistername textbox no of periods... of r/subjs will be to sports or library when submit the form the subjects
Searching for Code - JSP-Servlet
JSP, Servlet Searching for Code  Hi, i am looking for a jsp servlet code examples for the search function in my application.Thanks
servlet code - JSP-Servlet
servlet code  Create a servlet to develop a login application with javascript clientside validations and serverside validations
jsp code - JSP-Servlet
jsp code  sample code for change password example Old Password: new Password: confirm Password
jsp code - JSP-Servlet
jsp code  i want to design page into four pages 1) header to diplay 2) left page has to display hyperlink 3)right page has to display related page... : RoseIndia left:Add,delete right:employee Registration form Footer
jsp code - JSP-Servlet
jsp code  i want to design page into four pages 1) header to diplay 2) left page has to display hyperlink 3)right page has to display related page... : RoseIndia left:Add,delete right:employee Registration form Footer
servlet code - JSP-Servlet
servlet code  how to implement paging or pagination in java code using servlets.  Hi Friend, Try the following code: import java.io.... of JSP page"); out.println(""); out.println(""); out.println
jsp code - JSP-Servlet
jsp code  I need code for bar charts using jsp. I searched some code but they are contain some of their own packages. Please give me asimple code... friend, Code to solve the problem : Thanks
jsp code - JSP-Servlet
jsp code  sample code to create hyperlink within hyperlink example: reservation: train: A/C department non A/c Department
jsp code - JSP-Servlet
jsp code  how to count no of clicks made on a link and save it on database( using jsp)  Hi Friend, Try the following code: 1)click.jsp var numberOfClicks = 0; function hello(){ numberOfClicks
jsp code - JSP-Servlet
jsp code  in a jsp a table is existed ,in table each row contain one checkbox and name and desription how to delete specific rows in a table .  Hi Friend, Try the following code: 1)form.jsp: Name
login form - JSP-Servlet
login form  Q no.1:- Creat a login form in servlets?  Hi Friend, Try the following code: import java.io.*; import javax.servlet....(""); } } For more information,visit the following link: http://www.roseindia.net/jsp
JSP code - JSP-Servlet
me how to link these pages with each other using JSP..and how to write the code using JSP.. requriment for Newuser: 1>fname,lastname 2>Loginname...JSP code  hello,i working in project with JSP technology,i have one
JSP code - JSP-Servlet
JSP code  Hi! Can somebody provide a line by line explanation of the following code. The code is used to upload and download an image. <...(); if ((contentType != null) && (contentType.indexOf("multipart/form-data") >= 0
jsp code - JSP-Servlet
jsp code  in my table there are 3 fields named orderid ,itemname, itemqty. i want code that fetch orderid in dropdown... on select dropdown get table of item details of that orderid... there are multiple items at one orderid
JSP Code - JSP-Servlet
JSP Code  Create a html reader JSP tag that read the html page from a link and will display the contents on the JSP. Do not use include directive
code for JSP and Servlet - JSP-Servlet
code for JSP and Servlet  i have to create a jsp page that contains username and password, so how to code servlet according to it?  Hi... -------------------- loginaction javacode.LoginAction loginaction /jsp/LoginAction
jsp code - JSP-Servlet
jsp code  how to write a code in jsp with out using servelts finding sum and avg of 40 numbers  Hi Friend, Try the following code: Thanks  Hi Friend, Do one change in the provided code.As we
jsp code - JSP-Servlet
jsp code  hi my requirement is generate dynamic drop down lists... statement? pls provide code how to get first selected drop down list value to generate second drop down list by using jsp? pls ?   Hi Friend
jsp code - JSP-Servlet
jsp code   the value did not passed from script and not inserted in to database in the code u given . var numberOfClicks = 0; function hello(){ numberOfClicks++; alert( numberOfClicks ); document.form1.text.value
JSP code - JSP-Servlet
JSP code  hi i want to clear text box fields after click on submit.... thanking u......... This is what my code is. Jam Name...;   Hi Friend, Try the following code: Jam Name
jsp code - JSP-Servlet
jsp code  Hello Everybody, can anyone help me to findout the modules as i am developing a whiteboard application using jsp? this application is my dream application. Thank you
JSP Code - JSP-Servlet
JSP Code  Hi, Do we have a datagrid equivalent concept in JSP..., Please visit the following links: http://www.roseindia.net/jsp/data-grid.shtml http://www.roseindia.net/jsp/paging.shtml Thanks
jsp code - JSP-Servlet
jsp code  i want to add below code data in mysql database using jsp... using below code we got data in text box i want to add multiple data in database... Add/Remove dynamic rows in HTML table
JSP Code - JSP-Servlet
JSP Code  Hi, I have a problem in limiting the number of row... to display only 10 records per pages in jsp, then how can i achieve this concept... Rai.  Hi Friend, Try the following code: Pagination
jsp code - JSP-Servlet
jsp code  hello frns i want to display image from the database along... from database in Jsp to visit.... http://www.roseindia.net/jsp/retrieve-image.shtml http://www.roseindia.net/jsp/downloadimage.shtml Thanks
jsp code - JSP-Servlet
jsp code  how to get multi-chat client using jsp? i will be very glad if i'd get an idea from you people. thank you .  Hi Friend, Chat server is a standlone application that is made up the combination of two
jsp code - JSP-Servlet
jsp code  i want to add and remove rows dynamically ... in that row 3 colums are there... first colum shows one number , second colum shows second... colum.  Hi Friend, Try the following code: Add/Remove
creation of a form - JSP-Servlet
creation of a form  how to create a question paper using JSP...) in the mysql database and try the following code: 1)radio.jsp... visit the following link: http://www.roseindia.net/jsp/online-quiz
Jsp code - JSP-Servlet
Jsp code  PlaceAd.jsp function Calculate() { var fpval; var cityamt; var newspaper; var sizeval; var city = document.form.city.value; var noofwd = document.form.Count.value
Jsp code - JSP-Servlet
Jsp code   function Calculate() { var fpval; var cityamt; var newspaper; var sizeval; var city = document.form.city.value; var noofwd = document.form.Count.value; var nofw
html form - JSP-Servlet
html form  how to retrieve database value in dropdown list box placed in html form  Hi friend, Visit for more information. http://www.roseindia.net/jsp/ Thanks
atm code in servlet& jsp
atm code in servlet& jsp  pls send me the code of ATM project in servlet jsp . my requirements are first of all an user login window open then balance enquiry, withdraw of money, money transfer, then log out. pls send as early
jsp excel code - JSP-Servlet
jsp excel code  Hi how to insert form data into excel file using jsp?  Hi Friend, Try the following code: 1)register.jsp: Registration Form First Name: Last Name: User Name: Password
jsp code problem - JSP-Servlet
jsp code problem  Hi, I have employee details form in jsp. After validate all the fields, it will update the database, then move to next form. I have a problem with open the next form. plz, help me. thanks,  Hi
code - JSP-Servlet
; use some server side script like servlet or jsp, call these when user click...code  i have one check box in my form. When i click the check box i want to execute some sql query.so i write one javascript function. but i dont
Code - JSP-Servlet
Code  Using servlet,JSP,JDBC and XML create a Web application for a courrier company to provide online help in tracking the delivery status of items
jsp excel code - JSP-Servlet
jsp excel code  hi how to store html form data into excel sheet by using jsp? and repeat this process continuously for entire sheet
javascript Code - JSP-Servlet
javascript Code  how to count controls in form and find no of contriols in html or jsp page.for example one table is there with 10 rows,each row consists of 3 fields as 2 text box and one drop down box
automatic updation of a form - JSP-Servlet
automatic updation of a form   Sir, I need the code for if we fill the details in one page(form) that details should be updated automatically in another table like page.Please provide the code for this problem in JSP or java
JSP:HTML Form in-place Editing - JSP-Servlet
JSP:HTML Form in-place Editing  I have an HTML form (form #1) which uses a java servlet to save customer data by entering values into textfield... of a customer search in a small table on the same page using another servlet(also working
servlet code problem - JSP-Servlet
servlet code problem  This is my JSP code index.jsp Sync... here!!!..., i want to pass the texbox value and file to servlet im stuck with this error plzz help me..., in servlet if i use request.getParameter() its
Encryption code - JSP-Servlet
Encryption code  Iam developing a web security application for that reason i need a code of encryption in servlet. Can u please send it to me.Its very urgent Because my project delivery date is very near
servlet code problem - JSP-Servlet
servlet code problem  This is my JSP code index.jsp Sync Data Sync Data Please use the following input box to upload file or enter... to servlet im stuck with this error plzz help me..., thanks in advance....  
source code - JSP-Servlet
source code  i need source code for client server application in jsp to access multiple clients   Hi Friend, Please visit the following link: http://www.roseindia.net/jsp/ Here you will get lot of examples
JSP code problem - JSP-Servlet
JSP code problem  Hi friends, I used the following code... is the code: Display file upload form to the user...: <% //to get the content type information from JSP

Ads