Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa JSP-Servlet Form Code in JSP and Servlet
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


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


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


Advertisement
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
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
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
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
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
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
How to validate a form - JSP-Servlet
How to validate a form   Dear Sir, I have a one jsp... submit a form without any Id values in a text field i have to get an aleert message....  Hi Friend, Try the following code: function validate(){ var
servlet code - JSP-Servlet
servlet code  Create a servlet to develop a login application with javascript clientside validations and serverside validations
multipart/form-data - JSP-Servlet
multipart/form-data  When we are uploading a file we are using the encoded type of form of type multipart/form-data. When we are using... with the example available in http://www.roseindia.net/jsp/file_upload/Sinle
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  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
creating a feedback form - JSP-Servlet
and submitting the form. so questions are coming from the jsp page and also... button into database". the code you gave is working absolutely fine. but now i am refining this problem as follows: i am creating a feedback form
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
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 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  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  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  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  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
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
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
login form validation - JSP-Servlet
login form validation  hi, how to validate the login form that contains user name and password using post method . the validation should not allow user to login in the address bar thanks regards, anand
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 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   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
 

 

 

DMCA.com