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
Login         

View Questions and Answers by Category

Advertisements


 
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)      4 years and 2 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
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
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   
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
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
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
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
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
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
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 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
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
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
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
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
Advertisements
 

 

 

DMCA.com