Autu suggestion jsp

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Autocomplete Searchbox using jQuery, Ajax, JSP and Oracle Database</title>
        <link href="bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css">
    </head>
    
    <body>    
    <nav class="navbar navbar-default navbar-static-top">
      <div class="container">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
          </button>
            <a class="navbar-brand" href="https://onlyxscript.blogspot.com/">onlyxscript.blogspot.com</a>
        </div>
        <div id="navbar" class="navbar-collapse collapse">
            <ul class="nav navbar-nav">
                <li class="active"><a href="https://onlyxscript.blogspot.com/2018/11/autocomplete-searchbox-using-jquery.html">Back to Tutorial</a></li>
            </ul>       
        </div><!--/.nav-collapse -->
      </div>
    </nav>

        <div class="container">
            <label>Enter Country Name</label>
            <input type="text" id="txtCountry" class="form-control" placeholder="enter country name">
            <div id="showList">
                <ul class="list-group">
                </ul>
            </div>
        </div>
    </body>
</html>

<script src="js/jquery-1.12.4-jquery.min.js" type="text/javascript"></script>
<script src="bootstrap/js/bootstrap.min.js" type="text/javascript"></script> 
<script type="text/javascript">
        $(document).ready(function(){
            $('#txtCountry').keyup(function(){
                var search=$('#txtCountry').val();
                if(search !=='' && search !==null)
                {    
                    $.ajax({ 
                       type:'POST',
                       url:'record.jsp',
                       data:'key='+search,
                       success:function(data)
                       {
                           $('#showList').html(data);
                       }
                    }); 
                }
                else
                {
                    $('#showList').html('');
                }
            });
            $(document).on('click','li',function(){
               $('#txtCountry').val($(this).text());
            });
        });
</script>

3.83
6

                                    &lt;%@page import=&quot;java.sql.ResultSet&quot;%&gt;
&lt;%@page import=&quot;java.sql.PreparedStatement&quot;%&gt;
&lt;%@page import=&quot;java.sql.Connection&quot;%&gt;
&lt;%@page import=&quot;java.sql.DriverManager&quot;%&gt;

&lt;%
    if(request.getParameter(&quot;key&quot;)!=null) //get &quot;key&quot; variable from jquery &amp; ajax  part this line &quot;data:'key='+search&quot; and check not null 
    {
        String key=request.getParameter(&quot;key&quot;); //get &quot;key&quot; variable store in created new &quot;key&quot; variable
        String wild=&quot;%&quot; +key+ &quot;%&quot;; //remove &quot;%&quot; for use preparedstatement in query name like, and &quot;key&quot; variable store in &quot;wild&quot; variable for further use
        
        String url=&quot;jdbc:oracle:thin:@localhost:1521:XE&quot;; //database url string
        String username=&quot;system&quot;; //database username
        String password=&quot;tiger&quot;; //database password

        try
        {
            Class.forName(&quot;oracle.jdbc.driver.OracleDriver&quot;); //load driver
            Connection con=DriverManager.getConnection(url,username,password); //create connection

            PreparedStatement pstmt=null; //create statement

            pstmt=con.prepareStatement(&quot;SELECT * FROM country WHERE name LIKE ? &quot;); //sql select query
            pstmt.setString(1,wild); //above created &quot;wild&quot; variable set in this
            ResultSet rs=pstmt.executeQuery(); //execute query and set in ResultSet object &quot;rs&quot;.
           
            while(rs.next())
            {
                %&gt;
                    &lt;li class=&quot;list-group-item&quot;&gt;&lt;%=rs.getString(&quot;name&quot;)%&gt;&lt;/li&gt;
                &lt;%
            }
                con.close(); //close connection
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
    }
%&gt;
 

3.83 (6 Votes)
0
Are there any code examples left?
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source