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



Home Answers Viewqa Ajax how to get popup fro servelt to jsp by using ajax........
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


sumit kumar jain pithani
how to get popup fro servelt to jsp by using ajax........
1 Answer(s)      2 years and 3 months ago
Posted in : Ajax


how to get popup fro servelt to jsp by using ajax.

I went popup in jsp page when my form submit successfully. through servlet can any buddy give r explian how to write the code

Sumit kumar jain pithani


Advertisement
View Answers

July 30, 2012 at 4:23 PM


this simple dude it is like popup after submiting the form the value of field will sub,mit r insert into data base server the is simple code for it 
1.jsp page 
2.java script page 
3.servlet page
here is jsp page :Salu2.jsp file
----------------------------------------------------------------------------------------------------------------------------
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
    <%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page import="Controller.ConnectionString"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<link rel="stylesheet" type="text/css" href="Main.css">
<script language="javascript" type="text/javascript" src="saluValidate.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>


<div id="coltwo1">

<div id="salu" >
                 <div id="tittle"> SALUTATION  </div>
                 <div id="saluin">              
                    <form name="Salutation" method="post" action="Salutation">

      <fieldset style="width:350px;height: 100px; ">    


              <div id="smart" style="margin-top: 10px;" >
              <label style="font-size: medium;" title="Fulltitle">Full Name </label>
              <input type="text" name="Fulltitle" id="title1" style="width: 180px" title="select Fulltitle "> 
              </div>

              <div id="smart" style="padding-top: 5px;">
              <label style="font-size: medium;" title="Shorttitle">Short Name </label>
              <input  type="text" name="Shorttitle" id="title2" title="select Shorttitle "> 
              </div>
               <input type="hidden" name="id" id="title3" value="xx"> 

      </fieldset>

      <div  style=" clear: both;">  
                    <input type="submit"  name ="s1" value="SUBMIT"  onclick="return validateSalu(this.value);" class="button" title="SUBMIT">
                    <input type="reset"   name ="s2" value="RESET"   class="button"  title="RESET">
                    <input type="button"  name ="s3" value="UPDATE"  class="button"  onclick="return validateSalu(this.value);" title="UPDATE">
                    <input type="button"  name ="s4" value="DELETE"  class="button"  onclick="return validateSalu(this.value);" title="DELETE">         
        </div>     

                     </form>
             </div>

 <div id="salu1" >
            <select name="drop1"  size="6" multiple="multiple" style="width: 150px;" id="listB1"    onclick="return func(this.value);" title="drop1">
            <optgroup label=" SALUTAION"></optgroup>
                <%
            ConnectionString cs=new ConnectionString();
            cs.getConn();
            PreparedStatement p=cs.conn.prepareStatement("select * from Salutation ");
            ResultSet rs=p.executeQuery();
            while(rs.next())
            {
                String sid=rs.getString(1);
                String stitle=rs.getString(2);
                %>
                <option value="<%=sid%>">    
                <% out.println(sid +"   "+stitle); %>
                </option>
                <%}
            rs.close();
            p.close();
            %>
            </select>

       </div>
           </div>
  </div>



</body>
</html>
------------------------------------------------------------------------------------------------------------------------
this my java script and ajax file same..:saluValidate.js
----------------------------------------------------------
function validateSalu(butt){
    var fn=document.Salutation.Fulltitle.value;
    var sn=document.Salutation.Shorttitle.value;
    var salu_id=document.Salutation.id.value; 
    var i=0;
    var j=0;
    alert("sumit "+(++j));

             if(fn=="")
                 {
                 alert("Please Enter Full Name");
                 fn="";
                 document.Salutation.Fulltitle.focus();
                 return false;
                 }else if(!fn.match(/^[a-zA-Z]+$/)){
                     alert("Please Enter Correct Full Name");
                     fn="";
                     document.Salutation.Fulltitle.focus();
                     return false;
                }    

                if(sn=="")
                 {
                     alert("Please Enter Short Name");
                     sn=""; 
                     document.Salutation.Shorttitle.focus();
                     return false;
                     }else if(!sn.match(/^[a-zA-Z]+$/)){
 alert("Please Enter Correct Short Name");
 sn="";
 document.Salutation.Shorttitle.focus();
 return false;
                    }

                var B=true;
                if((/SUBMIT/g).test(butt)){
                     B=confirm("DO YOU WANT SUBMIT --- SALUTATION !!! PRESS OK ELSE CANCEL");
                      i=1;
                      //alert(""+butt+""+i);
                  }else if((/UPDATE/g).test(butt)){
                      B=confirm("DO YOU WANT UPDATE --- SALUTATION !!! PRESS OK ELSE CANCEL");
                      i=2;
                      //alert(""+butt+""+i);
                  }else if((/DELETE/g).test(butt)){
                      B=confirm("DO YOU WANT DELETE --- SALUTATION !!! PRESS OK ELSE CANCEL");
                      i=3;
                      //alert(""+butt+""+i);
                  }   


            if(B==true){
                AjexFun(fn,sn,i,salu_id);
                 return true;   
            }else{
                return false;
            }



}
var xmlhttp;
function  AjexFun(f,s,b,i){
    alert("sumit1");
    url="Salutation?full="+f+"&short="+s+"&button1="+b+"&id="+i;
    if(window.XMLHttpRequest){
        xmlhttp=new XMLHttpRequest();
    }
    else{
        xmlhttp=new ActiveXobjective("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange=fun;
    alert("sumit2");
    xmlhttp.open("post",url, true);
    alert("sumit3");
    xmlhttp.send(); 

}
function fun(){

    if(xmlhttp.readyState==4){

        var x=xmlhttp.responseText;

                alert(x);   
                document.getElementById("salu1").innerHTML=x;
                document.getElementById("title3").value="";
                document.getElementById("title1").value="";
                document.getElementById("title2").value="";
                return false;

    }
}



function func(id){
    //alert("sumit1");
    url="Salutation?id1="+id;
    if(window.XMLHttpRequest){
        xmlhttp=new XMLHttpRequest();
    }else{
        xmlhttp=new ActiveXobjective("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange=fun1;
    //alert("sumit2");
    xmlhttp.open("get",url, true);
    //alert("sumit3");
    xmlhttp.send();     
}


function fun1(){

    if(xmlhttp.readyState==4){

        var x=xmlhttp.responseText; 
        alert("sumit1"+x);
        var y=x.split(":");
        document.getElementById("title3").value=y[0];
        document.getElementById("title1").value=y[1];
        document.getElementById("title2").value=y[2];

        return true;


    }
}
------------------------------------------------------------
------------------------------------------------------------
this my java servlet page ............:Salutation.java

---------------------------------------------------------
package Controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;


import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class Salutation
 */
@WebServlet("/Salutation")
public class Salutation extends HttpServlet {
    private static final long serialVersionUID = 1L;

    /**
     * @see HttpServlet#HttpServlet()
     */
    public Salutation() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        //PrintWriter out=response.getWriter();

        System.out.println("get1");
        ConnectionString cs=new ConnectionString();
        cs.getConn();
        String salid=" ";
        String result="";
        salid=(request.getParameter("id1")).toUpperCase();
        try{
            PreparedStatement p=cs.conn.prepareStatement("select * from Salutation where salu_id ='"+salid+"'" );
            ResultSet rs=p.executeQuery();
            System.out.println("get3");
                    while(rs.next())
                    {
                        result+=rs.getString("salu_id");
                        result+=":"+rs.getString("salu_name");
                        result+=":"+rs.getString("salu_title");
                    }
                    response.getWriter().print(result);
        }catch(Exception e){
            System.out.print(e.getMessage());
            }

    }

    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        try{

        PrintWriter out=response.getWriter();
        System.out.println("servlet1");
    ConnectionString cs=new ConnectionString();
    cs.getConn();
            String fullname=" ";
            String shortname=" ";
            String sid=" ";
            int count=0;
            System.out.println("servlet2");
            fullname=(request.getParameter("full")).toUpperCase();
            shortname=(request.getParameter("short")).toUpperCase();
            sid=(request.getParameter("id")).toUpperCase();

            String button=request.getParameter("button1");
            System.out.println(button);
            Integer i= Integer.valueOf(button);
            System.out.println(i+""+sid);





        switch(i){
                case 1:



    try{

    PreparedStatement p=cs.conn.prepareStatement("select * from Salutation where salu_name ='"+fullname+"'"+"and salu_title='"+shortname+"'" );
    ResultSet rs=p.executeQuery();
    System.out.println("servlet3");
            while(rs.next())
            {
                count++;
            }

                    if(count>=1) 
                    {
                        System.out.println("servlet4");
                        out.println("already exist !!!");                       

                    }

                    else
                    {
                        System.out.println("servlet5");

                        String url="{call salut (?,?)}";                        
                        CallableStatement p1=cs.conn.prepareCall(url);
                        p1.setString(1, fullname);
                        p1.setString(2, shortname);
                        p1.executeUpdate();     
                        out.println("Submit successfull !!!");

                    }


    }catch(Exception e){
    System.out.print(e.getMessage());
    }
    break;
                case 2:

                    try{    


                    String url="{call update_salut (?,?,?)}";                       
                    CallableStatement p1=cs.conn.prepareCall(url);
                    p1.setString(1,sid);
                    p1.setString(2,fullname);
                    p1.setString(3,shortname);
                    p1.executeUpdate();
                    PreparedStatement p2=cs.conn.prepareStatement("select * from Salutation where status<>"+2);
                    p2.executeQuery();

                        response.getWriter().print("Update successfull !!!");


                        }catch(Exception e){
                        System.out.print(e.getMessage());
                        }
                        break;

                    case 3:

    try{    


   System.out.print("jain Delete 1"+sid);
    String url="{call del_salu1 (?)}";  
    System.out.print("jain Delete 1");
    CallableStatement p1=cs.conn.prepareCall(url);

    p1.setString(1,sid);                        
    p1.executeUpdate();

    PreparedStatement p2=cs.conn.prepareStatement("select * from Salutation where status<>"+2);
    p2.executeQuery();

        response.getWriter().print("Delete successfull !!!");



        }catch(Exception e){
        System.out.print(e.getMessage());
        }
        break;

    }
        }catch(Exception e){
            response.sendRedirect("Salu2.jsp");
            System.out.println(e.getMessage());
        }
}

}
------------------------------------------------------------------------------------------------------------------------
connection between the database and servelet using java script:ConnectionString.java
-----------------------------------------------
package Controller;



import java.sql.*;

public class ConnectionString {
public Connection conn=null;
public void getConn()
    {   
try
 {
   String url="jdbc:sqlserver://"*******ip--address***********";databaseName=komal";
   Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
   conn=DriverManager.getConnection(url, "username", "password");
 }

 catch(Exception e)
 {
  e.getMessage();
   }

    }

}


Related Tutorials/Questions & Answers:
how to get popup fro servelt to jsp by using ajax........
how to get popup fro servelt to jsp by using ajax........  how to get popup fro servelt to jsp by using ajax........ I went popup in jsp page when my form submit successfully.....through servlet can any buddy give r explian how
how to get popup fro servelt to jsp by using ajax........
how to get popup fro servelt to jsp by using ajax........  how to get popup fro servelt to jsp by using ajax. I went popup in jsp page when my form submit successfully. through servlet can any buddy give r explian how to write
Advertisements
Popup Window using Ajax In JSP
Popup Window using Ajax In JSP       In this section, we will develop a Popup Window application using Ajax in JSP. For this, we will create the following
How to get data from DB in to Text box by using Jsp & Ajax
How to get data from DB in to Text box by using Jsp & Ajax   I want to get the data from database in to text box in a jsp page by using Ajax. If I enter the letter A in the textbox it should show only those values which starts
excel report fro jsp mysql
excel report fro jsp mysql  Dear Sir, I am facing some problem while generating excel report form mysql database using jsp code. With the help from your site, I can able to generate excel file for all data types other than blob
using jsp's....and ajax - Ajax
using jsp's....and ajax  Hi, i need code using ajax .....in a text box when i enter an alphabet i should get list of words starts with the alphabet given in the text box
servelt -jsp Encryption Decryption Code
servelt -jsp Encryption Decryption Code  Encryption code&Decryption code Iam developing a web security application for that reason i need a code of encryption &Decryption in servlet. Can u please send it to me.Its very
How Can I get ArrayList of Data from jsp with ajax request
How Can I get ArrayList of Data from jsp with ajax request  Hi, I retereved 5 Employee Record of Data from Struts Action class to jsp with ajax response. But I don't how how can reterve this dynamic 5 employee records
how to display jsp page containing mysql query in particular division using ajax ?my code is below bt i cundt get it properly
how to display jsp page containing mysql query in particular division using ajax ?my code is below bt i cundt get it properly   index.html <... request; // The variable that makes Ajax possible! try{ // Opera 8.0
How to get the output of JSP program using Bean
How to get the output of JSP program using Bean  Hi Kindly go... visit the following link: http://www.roseindia.net/jsp/using-bean-counter.shtml...; <jsp:useBean id="counter" scope="session" class="CounterBean" /> <
How to get the output of jsp program using Bean
How to get the output of jsp program using Bean  Hello my Roseindia...; Next i created JSP program for the above one by using Bean and i opened the Tomcat webserver and clicked the JSP and i got the HTTP Status -500
how to show popup in javascript
how to show popup in javascript  How to show popup in javascript
popup ballon in jsp - JSP-Servlet
popup ballon in jsp  How to show a popup ballon in jsp when pointing to a link using javascript.Please help me  Hi Friend, Try the following code: #popup{ width:147px; position:absolute; display:none
how to generate reports from oracle database using jsp and ajax code
how to generate reports from oracle database using jsp and ajax code  Hai masters i am new to this Java world. my team leader ask me to generate sales report data from oracle database to jsp page please any one know how to do
how to fetch the record using AJAX? - Ajax
how to fetch the record using AJAX?  Can anyone tell me how to fetch the records from database using Ajax
How to get the data from the database using Servlet or JSP program
How to get the data from the database using Servlet or JSP program  ... database using JSP Get data from database using JSP... by using servlet or jsp program by typing the output as like this below
how to get data using dropdownlist, textbox and search button in jsp
how to get data using dropdownlist, textbox and search button in jsp  Hi, I want to display data using jsp,javascript and mysql. My Q. is If i select an entry suppose 'title' from dropdownlist and give a title name 'partial dif
How to get data from Oracle database using JSP
How to get data from Oracle database using JSP  hello i have a simple problem in jsp in the sense to get data from the database like oracle . I have... what i have done is that ( i have a simple problem in jsp in the sense to get
Ajax using jsp
Ajax using jsp  <%@ page import="java.io.*" %> <%@ page import="java.util.*" %> <%@ page import="java.sql.*" %> <%@ page import...); } %> Is there Any error...........In first Page I use ajax for displaying
ajax using jsp
ajax using jsp  <%@ page import="java.io.*" %> <%@ page import="java.util.*" %> <%@ page import="java.sql.*" %> <%@ page import="java.util.StringTokenizer" %> <%@ page import="java.lang.*" %> <
datagid with paging using jsp - Ajax
datagid with paging using jsp  datagrid with paging using ajax and jsp  Hi friend, For read more information : http://www.roseindia.net/jsp/data-grid.shtml Thanks
How to get sub category based on category from database using jsp and javascript.
How to get sub category based on category from database using jsp and javascript.  How to get sub category based on category from database using jsp and javascript
application using AJAX and JQuery and also use JSP
application using AJAX and JQuery and also use JSP   i need create an application using AJAX and JQuery and also use JSP
How to perform search using AJAX?
How to perform search using AJAX?  Hi, I have following HTML code... and hit button, there is a Ajax call to retrieve search results from a simple txt file kept on my local. Please guide how do I achieve this? I have written loadDOC
How to get more than one value from ajax
How to get more than one value from ajax  I have multiple select list box in php. i filled the value using ajax. how to get different value to fill the same list box Ex. option value as id option name as some string
How do i get the number of online users from a site using jsp?
How do i get the number of online users from a site using jsp?  Hi, Can any one tell me how to get the number of records from a database dynamically, when each person got logged into the page in jsp
how to get the checkbox value in jsp
how to get the checkbox value in jsp  how to get the checkbox value in jsp?   JSP CheckBox Example - how to get the checkbox value in jsp
Ajax with java(using Dojo) - JSP-Servlet
Ajax with java (using Dojo)  Hi, In In place Edit Box,when I click "save" button how can I save the data in server side i.e JSP or how can I call.... Is there a possibility for tutorial on Scriptaculous. us,for Java programmers
how to operate on select box using ajax in struts2?
how to operate on select box using ajax in struts2?  I am doing a project on struts2 in which i have a jsp page which has two select boxes like Now i want to use ajax so that when i select a district value
How to get the text from textarea in HTML and store it in database using javascript and jsp
How to get the text from textarea in HTML and store it in database using javascript and jsp  How to get the text from textarea in HTML and store it in database using javascript and jsp <script> function str() { <
jsp and ajax
jsp and ajax  how to enable or disable textbox using radio buttons by using jsp and ajax
 

 

 

DMCA.com