reain values

reain values

Sir I have Jsp page for regisering customers,when i submit form it goes to servlet in servelets it checks for the username if it already exits i m using reuest.sendredirect to same jsp but all textbox values are cleard, i want to retain all values in textboxs after request.sendredirect .Please Hlp Thanks

View Answers

May 17, 2011 at 1:09 PM

1)checkusername.jsp:

<%@page import="java.sql.*"%>
<html>
<head>
<script type="text/javascript">
function showData(){ 
var user=document.getElementById("uname").value;
var pass=document.getElementById("pass").value;
var add=document.getElementById("address").value;
var email=document.getElementById("email").value;

xmlHttp=GetXmlHttpObject()
var url="../AjaxServlet";
url=url+"?user="+user+"&&pass="+pass+"&&address="+add+"&&email="+email;
xmlHttp.onreadystatechange=stateChanged 
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}
function stateChanged() { 
if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
    var showdata = xmlHttp.responseText; 
    alert(showdata);
} 
}
function GetXmlHttpObject(){
var xmlHttp=null;
try {
  xmlHttp=new XMLHttpRequest();
 }
catch (e){
 try {
  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  }
catch (e){
  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
}
return xmlHttp;
}
</script>
</head>
<form name="employee">
<div id="mydiv"></div>
<table>
<tr><td>Username</td><td><input type="text" id="uname"></td></tr>
<tr><td>Password</td><td><input type="password" id="pass"></td></tr>
<tr><td>Address</td><td><input type="text" id="address"></td></tr>
<tr><td>Email</td><td><input type="text"  id="email"></td></tr>
<tr><td></td><td> <input type="button" value="check" onclick="showData();"></td></tr>
</table>

 </form>
</html>

2)AjaxServlet.java:

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

public class AjaxServlet extends HttpServlet {
    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html");
        PrintWriter out = response.getWriter();
        String user = request.getParameter("user");
        String pass = request.getParameter("pass");
        String address = request.getParameter("address");
        String email = request.getParameter("email");
        System.out.println(user);
        int count = 0;
        String data = "";
        try {
            Class.forName("com.mysql.jdbc.Driver");
            Connection con = DriverManager.getConnection(
                    "jdbc:mysql://localhost:3306/test", "root", "root");
            Statement st = con.createStatement();
            ResultSet rs = st
                    .executeQuery("select * from login where username='" + user
                            + "'");
            while (rs.next()) {
                count++;
            }
            if (count > 0) {
                data = "Username Already Exists";
            } else {
                int i = st
                        .executeUpdate("insert into login(username,password,address,email) values('"
                                + user
                                + "','"
                                + pass
                                + "','"
                                + address
                                + "','"
                                + email + "')");
                data = "Inserted Successfully!";
            }
            out.println(data);
            System.out.println(data);
        } catch (Exception e) {
            System.out.println(e);
            e.printStackTrace();
        }
    }
}









Related Tutorials/Questions & Answers:
reain values
reain values  Sir I have Jsp page for regisering customers,when i... if it already exits i m using reuest.sendredirect to same jsp but all textbox values are cleard, i want to retain all values in textboxs after request.sendredirect .Please
duplicate values
duplicate values  My database having cursor that has duplicate values.i want to remove duplicate values through java application
Advertisements
Values to listbox
Values to listbox  I have two textboxes by the name street and city.I have an add button and a name listbox. When I enter street and city and press the add button ,all the names of the people residing there are listed in listbox
hibernate.archive.autodetection values
hibernate.archive.autodetection values  Hi, What are the hibernate.archive.autodetection values? How to use the hibernate.archive.autodetection in Hibernate project? Thanks   Hi, You can use the class, hbm as values
Retrive Values
Retrive Values  I want to retrive the values between the td by the id using the javascript.So please help me... html form like this <TABLE width="100%" bgColor=""> <TR> <TD ID="td1">Cell 1</TD>
JTable duplicate values in row
JTable duplicate values in row  JTable duplicate values in row
multiple select values
multiple select values   can you provide an example for multiple select values for html:select tag
Quotes around attribute values.
Quotes around attribute values.  Should I put quotes around attribute values
disallow NULL values in a table.
disallow NULL values in a table.  How do I disallow NULL values in a table
percentage values for <TD WIDTH=...>
percentage values for   Can I use percentage values for <TD WIDTH=...>
how to set the values in jsp
how to set the values in jsp  how to set the values text boxs in jsp frm dbase via servlet
ModuleNotFoundError: No module named 'values'
ModuleNotFoundError: No module named 'values'  Hi, My Python... 'values' How to remove the ModuleNotFoundError: No module named 'values'... to install padas library. You can install values python with following command
retrive values - JSP-Servlet
retrive values  how to get multiple values from html to jsp
fetch values in dropdown
fetch values in dropdown  in my application i want fetch dropdown values in jsp page through servlet. means i have to fetch the database fields values in array variable of servlet and then i have to print those values in dropdown
Atomic values in Xml
Atomic values in Xml  Hi..... please give me the ans How you define atomic values in Xml?ADS_TO_REPLACE_1 Thanks
select tag multiple values
select tag multiple values   I want to insert multiple values in database which i have selected from select tag
Java plateform dependent values
Java plateform dependent values  How will you get the platform dependent values like line separator, path separator, etc., ?  we will get the the platform dependent values like line separator, path separator
Read Bit values
Read Bit values  how to read bit values in the program Please give suggestion, which is useful in Simplified DES Algorithm
Remove duplicate values
Remove duplicate values  i am trying to insert values into database... is primary key. other attributes can allow null. am trying to insert values...:subject],[CreatedBy])" + " values('"+Cname[i]+"','"+textdescription[i
passing values on button click
passing values on button click  Please help me to solve this issue.I want to pass a value assigned to button to another view upon button click in xcode
Sending hidden values
Sending hidden values  how to send more than one hidden values through javascript function . Main purpose is to remove href link (Query string should not appear in url bar
Retain jsp values
Retain jsp values  how to retain a jsp values without using session and cookies?   Hello Friend, You can use request.getParameter() and request.setAttribute() methods to get the jsp fields values. For more information
Hibernate hbm2ddl.auto values
Hibernate hbm2ddl.auto values  Hi, What are the values for Hibernate... of hbm2ddl.auto is set correctly. Hibernate hbm2ddl.auto values The possible values for this property are: validate: Its used to validate the schema
retrive values - JSP-Servlet
retrive values  how to retrive multiple values from html to jsp  Hi Friend, Try the following code: 1)calljsp.html: Enter Name: Enter Address: Gender:MF Qualification: Btech MBA MCA MSC
passing values in hyperlink
passing values in hyperlink  Hi. I have given a hyperlink in one jsp page. Can i able to pass that hyperlink label as a value to the next page its navigating when the user clicks it. Plz respond me quickly. Thanks in advance
passing values in hyperlink
passing values in hyperlink  Hi. I have given a hyperlink in one jsp page. Can i able to pass that hyperlink label as a value to the next page its navigating when the user clicks it. Plz respond me quickly. Thanks in advance
passing values in hyperlink
passing values in hyperlink  Hi. I have given a hyperlink in one jsp page. Can i able to pass that hyperlink label as a value to the next page its navigating when the user clicks it. Plz respond me quickly. Thanks in advance
passing values in hyperlink
passing values in hyperlink  Hi. I have given a hyperlink in one jsp page. Can i able to pass that hyperlink label as a value to the next page its navigating when the user clicks it. Plz respond me quickly. Thanks in advance
passing values in hyperlink
passing values in hyperlink  Hi. I have given a hyperlink in one jsp page. Can i able to pass that hyperlink label as a value to the next page its navigating when the user clicks it. Plz respond me quickly. Thanks in advance
retaining textbox values
retaining textbox values  i have a calculator program, when i press a button the value displays but disappears when i press another button so how can i keep values to display when i press multiple buttons
iterating hashmap values in struts2
iterating hashmap values in struts2  hi, i am not getting how to display this map values in jsp page using struts2 public class ViewOperation2 { public Map<String,Object> viewCustDetails(){ Map<String
Default Values
Default Values The elements which do not have any children can have default values. Default values are assigned automatically if no value is supplied. The "default" attribute of the xs:element element can be used
values in combobox - Java Beginners
values in combobox  how to fill values in combo box i.e. select tag in html using javascript?   Hi Friend, Try the following code: ComboBox var arr = new Array(); arr[0] = new Array("-select-"); arr[1
pass parameter names and values
pass parameter names and values  What is the <jsp:param> standard action?   The <jsp:param> standard action is used with <jsp:include> or <jsp:forward> to pass parameter names and values
Replacing a template with actual values
holders with acutal value. The acutal values are in the map with key as the place
Hibernate envers revtype values
Hibernate envers revtype values  Hi, What are Hibernate envers revtype values? Thanks   Hi, Hibernate envers library automatically keep track of the changes made to the entity. It create a new table with _AUD suffix
form values in java script - Struts
form values in java script  how to get form values in java script functions with struts1.1
shifting values - Java Beginners
shifting values  write a program to shift the array values in a circular way according to user's choice. user will supply the size of the array,array elements,the number of times the array will be shifted and also the direction
Arraylist from row values
Arraylist from row values  Hello, can anyone please help on how to make an arraylist from the row values of a particular column from a database table? Thanks in advance!   import java.sql.*; import java.util.ArrayList
retrieve multiple attribute values
; What I would like is to retrieve both the attribute values of process
retrieve multiple attribute values
like is to retrieve both the attribute values of process:Output during execution
retrieve multiple attribute values
like is to retrieve both the attribute values of process:Output during execution
JTable values are not gettiing properly
JTable values are not gettiing properly  Sir, I created one JTable with two columns and one row i have given two values,but i getting only one value .That is a[1][1] is String array. if i have given 8,9 then i got 8 only
ma access reading values
values throught servlet and register.jsp now i need code for reading values from...(table in my ms access) need to display values in jsp .............please help me... and inserted values throught servlet and register.jsp now i need code for reading
show the database values graphical represantation
show the database values graphical represantation   show the database values graphical represantation and auto refresh for every 30 secand displaying in webpage
inserting dropdown values into database table
inserting dropdown values into database table   hi i want to insert dropdown values into a database table by using jsp
Python sum dictionary values by key
Python sum dictionary values by key  Hi, In python we can easily create dictionary and store the values in it. In dictionary we store the values... values. We are getting these two dictionaries from two different web services. We
insert values - JSP-Servlet
insert values  How to insert values in the oracle database using JSP. Plz tell the core answer as soon as possible .  HiThis is html...;insert user_details values('"+username+"','"+jobposition+"
passing values - JSP-Servlet
_DataInsertion(Name,Hallno,Time,Date,Mobileno,Status) values('"+name+"','"+hallno+"','"+time
Getting image pixel values
Getting image pixel values  how to get image pixels values on mouse click   import java.awt.*; import java.awt.event.*; import java.awt.image.BufferedImage; import java.io.*; import javax.swing.*; public class

Ads