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
Related Tutorials/Questions & Answers:
Advertisements
Calling a jsp page from ServletCalling 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
Inserting data from the HTML page to the database Inserting
data from the
HTML page to the
database... have got
from the
html will be set in
the
database by using the setString... program in which
we are going to insert the values in the
database table
from 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
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
Uploading file in servlet from a html formUploading 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 code to servlet to database using jdbcHTML code to
servlet to
database using jdbc pls send me the
code related to the title
Hi Friend,
Try the following
code:ADS_TO_REPLACE_1
1)form.html:
<html>
<
form method="post" action="http://localhost
Data fetching from JSP or HTML - JSP-ServletData 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 idecalling 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
data are not display in JSP from database - JSP-Servletdata 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 displaying data retrieved from a database in a jsp pagedisplaying
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 dataProcess
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
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 form - JSP-Servlethtml 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
sending email code - JSP-Servletsending 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
ACCESS DATABASE FROM HTMLACCESS
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
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