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



Home Answers Viewqa JSP-Servlet Sending form data from HTML page to SQLserver 2005 database by calling servlet code

Have Programming Question? Ask it here!
 
 
 


phyo ei
Sending form data from HTML page to SQLserver 2005 database by calling servlet code
3 Answer(s)      3 years and 9 months ago
Posted in : JSP-Servlet


Hi sir,
      I would like to know how to send the form data from html page to database by calling servlet code from html page .

Advertisement
View Answers

October 26, 2010 at 10:52 AM


Hello Friend,

Try the following code:

1)callServlet.html:

<html>
<center><h3>Registration Form</h3></center>
<form method="post" action="http://localhost:8080/examples/Registration">
<center>
<table>
<tr><td>ID:</td><td><input type="text" name="userId" size="20"></td></tr>
  <tr><td>First Name:</td><td><input type="text" name="firstname" size="20"></td></tr>
  <tr><td>Last Name:</td><td><input type="text" name="lastname" size="20"></td></tr>
    <tr><td>Email:  </td><td><input type="text" name="email" size="20"></td></tr>
  <tr><td>City:    </td><td><input type="text"  name="city" size="20"></td></tr>
  <tr><td>State:     </td><td><input type="text" name="state" size="20"></td></tr>
  <tr><td>Country:    </td><td> <input type="text" name="country" size="20"></td></tr>
  <tr><td><input type="submit" value="Submit" name="B1"></td><td><input type="reset" value="Reset" name="B2"></td></tr>
  </table>
  </center>
</form>
</html>

2)Registration.java:

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

public class Registration extends HttpServlet{
  public void init(ServletConfig config) throws ServletException{
  super.init(config);
  }
    public void doPost(HttpServletRequest req, HttpServletResponse res) 
    throws ServletException, IOException{
    String connectionURL = "jdbc:mysql://localhost:3306/test";
    Connection connection=null;
    ResultSet rs;
    res.setContentType("text/html");
    PrintWriter out = res.getWriter();
    String uId = req.getParameter("userId");
    String fname = req.getParameter("firstname");
    String lname = req.getParameter("lastname");
    String email = req.getParameter("email");
    String state = req.getParameter("state");
    String city = req.getParameter("city");
    String country = req.getParameter("country");
    try{
    Class.forName("com.mysql.jdbc.Driver");
    connection = DriverManager.getConnection(connectionURL, "root", "root"); 
    String sql = "insert into employee(empid,firstname,lastname,email,state,city,country) values (?,?,?,?,?,?,?)";
    PreparedStatement pst = connection.prepareStatement(sql);
    pst.setString(1, uId);
    pst.setString(2, fname);
    pst.setString(3, lname);
    pst.setString(4, email);
    pst.setString(5, state);
    pst.setString(6, city);
    pst.setString(7, country);
    int numRowsChanged = pst.executeUpdate();
    out.println("Hello:");
    out.println("'"+fname+"'");
    pst.close();
    }
    catch(Exception e){
    out.println(e);
    }
   }
}

3)Do the servlet mapping in web.xml:

<servlet>
        <servlet-name>Registration</servlet-name>
        <servlet-class>Registration</servlet-class>
    </servlet>
<servlet-mapping>
        <servlet-name>Registration</servlet-name>
        <url-pattern>/Registration</url-pattern>
    </servlet-mapping>

Thanks



November 1, 2010 at 10:54 AM


thanks for your answer



April 6, 2012 at 10:51 PM


what is i want to separate many names by semicolon how should i do it in html?



Related Tutorials/Questions & Answers:
Sending form data from HTML page to SQLserver 2005 database by calling servlet code
Sending form data from HTML page to SQLserver 2005 database by calling servlet code  Hi sir, I would like to know how to send the form data from html page to database by calling servlet code from html page .   
How to send the data selected from drop down menu from html page to sql 2005 database.
How to send the data selected from drop down menu from html page to sql 2005... by user from html drop down menu such as check-in date for hotel reservation system ,how can I save these data in database and how to retrieve later .Thanks
Advertisements
Calling In JavaScript Functions from HTML Form To Validate User Entered Data
Calling In JavaScript Functions from HTML Form To Validate User Entered... and editing my html to call my functions to validate the user entered data... to the acknowledgement page --> </head> <body> <!--insert form
Calling a jsp page from Servlet
Calling a jsp page from Servlet  How can I do this? Suppose I have jsp page aaa.jsp. From aaa.jsp on form action I have made a call to a servlet xxx.java. In xxx.java I have written code to retrieve data from database through
Calling Servlet to build a List of data from database and show this on the JSP page in table
Calling Servlet to build a List of data from database and show this on the JSP... to retrieve all the data from database and then add the data into list. The list... to the database and retrieves the data from database. After getting the values from
display data from a table in Access Database in a HTML page
display data from a table in Access Database in a HTML page  how to display data from a table in Access Database in a HTML page in a Java Program
SEARCHING THE DATA FROM DATABASE AND DISPLAY THE SEARCHED DATA IN HTML PAGE
SEARCHING THE DATA FROM DATABASE AND DISPLAY THE SEARCHED DATA IN HTML PAGE  pls help me....in this i want to search books from the database...\htdocs\project\opac1.php on line 10 HERE IS MY CODE my html page is <
calling java method from html form with out using javascript - JSP-Servlet
calling java method from html form with out using javascript  How can i call java method from a HTML form, java script should be disabled?  ...;script LANGUAGE="JavaScript">function testResults(form
Inserting data from the HTML page to the database
Inserting data from the HTML page to the database... program in which we are going to insert the values in the database table from the html form. To make our program working we need to make one html form
sending data to google chart api from mysql database using java
sending data to google chart api from mysql database using java  how to send data from mysql database to google chart api using java
Servlet to add the data into database
the data in the database table from a html form.  This servlet program... from the HTML form will be retrieved by the server side program i.e. servlet. ... Servlet to add the data into database   
Calling servlet from servlet .
Calling servlet from servlet .  How to call a servlet from another... ServletException, IOException { System.out.println("Calling another servlet by using...); System.out.println("Calling another servlet by using SendRedirect
Regarding connection between sqlserver 2005 and android application
Regarding connection between sqlserver 2005 and android application  hi to all, i want to know how to create webservice to connect sqlserver 2005 and android. can you please help me by providing source code for ref.. thanks
calling servlet from jsp
calling servlet from jsp  how to call a servlet from jsp
JSP to add details to a database from a HTML form.
JSP to add details to a database from a HTML form.  Hi I'm a second year CS student who has to use JSP to validate a HTML form and add the details..... Can anyone tell me what is wrong with my code? html code first
sending data to google chart api from mysql database using java
sending data to google chart api from mysql database using java  Добовляйтесь в группу "МАЙНКРАФТА" Будьте участниками Группы Помогаите нам и себе Наша группа https://vk.com/club60851464 Есть свой сервер! Хорошая атмосфера
Uploading file in servlet from a html form
Uploading file in servlet from a html form  Sir, I want to upload a picture from my html file and save it to my database as BLOB,but what JAR should i use for this purpose i am really confused about.And also is it possible to do
HTML Form data into .CSV?
HTML Form data into .CSV?  how to store data from html form to csvfile in java
jsp or sevlet and html form to send picture to database - JSP-Servlet
that contains his picture to database. What I need are html page for the form that will browse for the picture, jsp or servlet that the info from html will go...jsp or sevlet and html form to send picture to database  Hello guys
HTML code to servlet to database using jdbc
HTML code to servlet to database using jdbc  pls send me the code related to the title   Hi Friend, Try the following code: 1)form.html: <html> <form method="post" action="http://localhost:8080/examples/Data
How to search the table name in MS SQL Database 2005 from application
How to search the table name in MS SQL Database 2005 from application  How to search the table name in MS SQL Database 2005 from application from our helpdesk application? application might be in html
how to pass form values from javascript of html page to jsp page
how to pass form values from javascript of html page to jsp page   This is my sample html page which contains inline javascript which calculates... to submit all the form values with lattitude and longitude returned from
How to pass parametes from JSP page to HTML page? - JSP-Servlet
How to pass parametes from JSP page to HTML page?  Hi all, In my project I have one JSP page and one HTML page. In JSP page I have created HTML... to pass the values from my JSP page to HTML page. Pls help me out. Hitendra 
displaying data retrieved from a database in a jsp page
displaying data retrieved from a database in a jsp page  the page... ServletException, IOException { response.setContentType("text/html;charset=UTF-8...("PageTitle"); try { response.setContentType("text/html;charset=UTF-8
Process HTML FORM data
Process HTML FORM data  Can a JSP page process HTML FORM data?   Yes. Preemptive termination of request processing on an error condition is a good way to maximize the throughput of a high-volume JSP engine. The trick
sending data from java to facebook wall
sending data from java to facebook wall  how to send data form a java program to facebook wall
Data fetching from JSP or HTML - JSP-Servlet
Data fetching from JSP or HTML  Hi Deepak, Can u pls help me as i have a problem with jsp/html frameset. my question is how can i fetch the data from frameset which is in html format.pls help me. Thanks
Convert sqlserver database to msexcel
Convert sqlserver database to msexcel  How to i convert sqlserver database values into msexcel sheet using java...   We have used MySQL database. import java.io.*; import java.sql.*; import
Fetched Record from database show into text field of html page
Fetched Record from database show into text field of html page  hi, i have a database with field merchant_code, merchant_name, city, region, and also have html page with all above mentioned field i have submit 20 record from
Fetching database field from servlet to jsp page ?
Fetching database field from servlet to jsp page ?  Hello Java... field. I wanted to pass some of the database field from servlet to jsp... (i am opening my database in servlet init() method ) how to pass rs.getString(8
code for selected checkbox columns data from database
code for selected checkbox columns data from database  in my page iam... one or more checkboxes i have to get data of that selected columns only. what is the jsp code for this thanks in advance kalyani
calling servlet from jsp in netbeans ide
calling servlet from jsp in netbeans ide  I have tried to call servlet from jsp code in netbeans for checking the database values . but while running it showing the error that the resource not available. i dono wat mistake i did
storing date from html form to oracle 10g using servlet
this date month year from html form into oracle 10g database where i have...storing date from html form to oracle 10g using servlet  i have following html form from where date,month and year is retrieved separately.. <
storing date from html form to oracle 10g using servlet
this date month year from html form into oracle 10g database where i have...storing date from html form to oracle 10g using servlet  i have following html form from where date,month and year is retrieved separately.. <
data are not display in JSP from database - JSP-Servlet
data are not display in JSP from database   i want to finding some data through a SQL query from SQL server database to a JSP page based on some... of this jsp page. like.. School Result and three request parameters 'class', 'from
sending email code - JSP-Servlet
sending email code  How To Send Emails using jsp  Hi friend, I am sending you a link. This link will help you. Please visit for more information. http://www.roseindia.net/mail/sending-an-email
Store XML file into Sqlserver Database
Store XML file into Sqlserver Database  Code for storing a typical XML file into SQl server database in 1 or more tables using asp.net using C
calling one jsp from another jsp page
calling one jsp from another jsp page  need coding for calling one jsp from another jsp including the xml file.Its urgent
Getting and sending data to and from mobile and the system
Getting and sending data to and from mobile and the system  Hi, For getting and sending data to mobile from system.make system is a server.From mobile send a request to the server and get response.Then process the response
design chart takes data from database and through jsp page
design chart takes data from database and through jsp page  how can I design chart takes data from database and through in jsp page
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
problem from registering a data in database with servlet - JSP-Servlet
problem from registering a data in database with servlet  Hi Rose, i created a servlet to validates ten user details in the database, if present...); System.out.println("Connected to the database"); String query1="Select * from user
how to call servlet from html page at anchor tag ?
how to call servlet from html page at anchor tag ?  I have a very... to other page and at that place i give url of a servlet but in server that url... it is not working properly. I split and merge template. In the header part of my page i use
How we delete a data of database from front end jsp page
How we delete a data of database from front end jsp page   I make a website and featch a data from data base and now i want that a delete button put... deleted from jsp page as well as from database.I used mysql and jsp. Please help me
calling servlet from JS and return response from servlet to JS
calling servlet from JS and return response from servlet to JS  hello... page when user clicks on a button i am calling a javascript function(eg myFunc) which inturn calls a servlet(myServlet).servlet performs some DB related
how to get a values from a multipart/form-data - JSP-Servlet
how to get a values from a multipart/form-data  Dear sir , I used your code for getting a values,i used the fllowing function submitForm(f){ var form = document.createElement("form"); with(form
JSP:HTML Form in-place Editing - JSP-Servlet
from a stringquery into another page and having the same form, for some reason...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
HTML login page code
the complete HTML JavaScript code for User Login Page. Thanks in Advance!   ...: " + form.pwd1.value); return true; }   html registration form code...HTML login page code  Hi all, I am writing my first HTML JavaScrip
HTML(Registration form) to Jsp to stored into MS ACCESS database
you for waiting that code. This is My Html page Link...HTML(Registration form) to Jsp to stored into MS ACCESS database  i am sending one html file that contain 18 fields these are stored in ms-access
ACCESS DATABASE FROM HTML
ACCESS DATABASE FROM HTML  I want to access sql 2008 database in html page without help of ADODB connection.. because if access through ADODB means there is a security problem. so, Access database in html page(client side
 

 

 

DMCA.com