Form Code in JSP and Servlet

Ads

 
 

Share on Google+Share on Google+

sasi kumar
Form Code in JSP and Servlet
3 Answer(s)      9 years ago
Posted in : JSP-Servlet

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

Ads
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();
}

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

Ads









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
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  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
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
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
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
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
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
servlet code - JSP-Servlet
servlet code  Create a servlet to develop a login application with javascript clientside validations and serverside validations
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  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
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
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
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  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