Question: Servlets



Share on Google+Share on Google+

1 Answer(s)      7 years ago
Posted in : JSP-Servlet
initially i have one registraion html page.

i entered values into that html. now i am reading values into servlet from this html page. These values are going to be inserted into here i want display one thing i.e,

If suppose the values insertion in database, will take 10 sec. I dont want to display these 10 sec as white page.I want to display in this 10 seconds as some processing symbo/jpeg etc on webbrowse.

how is it please send me..
View Answers

May 7, 2010 at 4:35 PM

Hi Friend,

Try the following code:

<form method="POST" action="http://localhost:8080/examples/Registration">;
<tr><td>User 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>State: </td><td><input type="text" name="state" size="20"></td></tr>
<tr><td>City: </td><td><input type="text" name="city" 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></tr>


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

public class Registration extends HttpServlet{
public void init(ServletConfig config) throws ServletException{
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException{
String connectionURL = "jdbc:mysql://localhost:3306/test";;
Connection connection=null;
ResultSet rs;
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");
long s1 = System.currentTimeMillis()/1000;
long s2=0 ;
try {
connection = DriverManager.getConnection(connectionURL, "root", "root");
String sql = "insert into login(id,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+"'");
s2 = System.currentTimeMillis()/1000;
catch(Exception e){

out.println("Time taken in inserting data: "+(s2-s1) +"seconds ");



Related Tutorials/Questions & Answers:
servlets  what is the duties of response object in servlets
servlets  why we are using servlets
what are advantages of servlets  what are advantages of servlets   Please visit the following link: Advantages Of Servlets
Servlets  How to edit and delete a row from the existing table in servlets
servlets  How do you communicate between the servlets?   We can communicate between servlets by using RequestDespatcher interface and servlet chaining
what is the architecture of a servlets package  what is the architecture of a servlets package   The javax.servlet package provides interfaces and classes for writing servlets. The Servlet Interface The central
Servlets  How to check,whether the user is logged in or not in servlets to disply the home page
servlets  why we require wrappers in servlets? what are its uses? Please explain   These wrappers classes help you to modify request...://
. Anyways, please visit the following links:
servlets  How to open and read the contents of a text file in servlets?   Please visit the following link: Read text file using Servlet
servlets   Hi what is pre initialized servlets, how can we achives?   When servlet container is loaded, all the servlets defined in the web.xml file does not initialized by default. But the container receives
Servlets and
Servlets and   Sir...! I want to insert or delete records form oracle based on the value of confirm box can you please give me the idea.... thanks
servlets why do we need web-inf directory in web application  why do we need web-inf directory in web application? means what's the benefits of doing so
which are the differ ways you can communicat between servlets  which are the differ ways you can communicat between servlets   Different ways of communicating between servlets:- 1)Using RequestDispatcher object. 2
package supports the development of servlets that use the HTTP protocol. The classes... javax.servlet.GenericServlet and serves as the base class for HTTP servlets. HttpServlet-Request
what are sessions in servlets  what are sessions in servlets   A Session refers to all the request that a single client makes to a server...:
the servlets
what is diff between generic servlets and httpservlets  what is diff between generic servlets and httpservlets   Difference between GenericServlet and HTTPServlet: 1)GenericServlet belongs to javax.servlet package
regarding the user usage and habits. Servlets sends cookies to the browser client...://
servlets  hi i am using servlets i have a problem in doing an application. in my application i have html form, in which i have to insert on date value, this date value is retrieved as a request parameter in my servlet
what are filters in java servlets  what are filters in java   Filters are powerful tools in servlet environment. Filters add certain functionality to the servlets apart from processing request and response paradigm
servlets  what are different authentication options available in servlets   There are four ways of authentication:- HTTP basic authentication HTTP digest authentication HTTPS client authentication Form-based
jsp -servlets
jsp -servlets  i have servlets s1 in this servlets i have created emplooyee object, other servlets is s2, then how can we find employee information in s2 servlets
Servlets with Extjs
Servlets with Extjs  how to integrate servlets and extjs and also show database records in extjs grid using servlet how to get servlets json response. Can any one please help me
Authentication in Servlets
Authentication in Servlets  What are different Authentication options available in Servlets
java servlets
java servlets  please help... how to connect java servlets with mysql i am using apache tomcat 5.5
advantages of Servlets
advantages of Servlets  What is advantages of Servlets ?    Portability. Powerful. Efficiency. Safety. Integration. Extensibilty. Inexpensive
servlets and struts
servlets and struts  wat is the diffrence between servlets and struts?   A Servlet is a technology and Struts is a framework which relies on or makes use of Servlets.A Servlet is a controller. Struts has its own Servlet
Servlets Programming
Servlets Programming  Hi this is tanu, This is a code for knowing... visit the following links: http
Sessions in servlets
Sessions in servlets  What is the use of sessions in servlets?   The servlet HttpSession interface is used to simulate the concept that a person's visit to a Web site is one continuous series of interactions
servlets - Servlet Interview Questions
what is servlets in Java  what is servlets in Java
Java Spring Hibernate Struts Training fat image from db fat image from db fat image from db fat image from db unable to get value returned from javascript variable in page How to change image size before adding to mysql using jsp Design a registration.jsp page with input for user registration details Cart Quantity jsp servlet coding issue servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ? servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ? servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ? servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ? servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ? servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ? servlet,jsp login registration forms without database in ecalipse ide using hashmap to store the registraion details ? image pdf marking pdf marking Multiple image upload using JSP Read code from excel sheet and upload into database using JSP Student java about search engine Convert BLOB to PDF and save it to a location how to copy files from remote to local machine using SFTP SSL in java? Like Team viewer Socket and Servert -Jsp how to copy files from remote location to local using java? How To Store Multilple Images In MySQL database dynamically with image uploader and then retrieve them in image gallery using java how to create SOAP based web service in java? how to fetch data from mysql database table and draw a bar chart on that data using in jsp how to create users in LDAP using java? how to authenticate user using TIVOLI api in java? how to create users using IBM Tivoi API in jsp/servelet? Java/J2ee Please explain this code as many packages and classes are unknown to me .! how to download the uploaded folder files using jsp Login Query image is display from path of mysql database please reply the code to store dynamic fields in database? Reloading issue in jsp How to get Button Id ? calling one jap page from another jsp page login login Problem to get connection from DAO class to JDBC Page Loading Time Fix table's column's name row(1st row of the table) so that it does not move up when the table is scrolled up to view more rows below Sending hidden values


Advertisement null