Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4124562
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T23:45:24+00:00 2026-05-20T23:45:24+00:00

HTML Code : <html> <head> <script type=text/javascript> function checkforValid(str) { var xmlhttp; if (str.length==0)

  • 0

HTML Code :

<html>  
<head>
<script type="text/javascript">
function checkforValid(str)
{
        var xmlhttp;
        if (str.length==0)
        { 
              document.getElementById("txtHint").innerHTML="";
              return;
        }
        if (window.XMLHttpRequest)
        {
            // code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp=new XMLHttpRequest();
         }
        else
        {
            // code for IE6, IE5
            xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        }

        xmlhttp.onreadystatechange=function()
        {
            if (xmlhttp.readyState==4 && xmlhttp.status==200)
            {
                document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
            }
        }
        xmlhttp.open("GET","get.jsp?q=" + str ,true);
        xmlhttp.send();
    }
    </script>
    </head>

    <body>

        <form action=""> 
            Name: <input type="text" id="user" name = "user" onkeyup="checkforValid(this.value)" />
        </form>

        <br>
        <p>Here : <span id="txtHint"></span> </p> 

    </body>
</html>

JSP:

<%@ page language="java" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.math.*" %>
<%@ page import="java.security.*" %>
<html>
<body>
<%
    String user = request.getParameter("user");
    out.println("Username is::"+user+".");
    Connection con = null;

    try
    {
        Connection conn = null;
        String url = "jdbc:mysql://localhost:3306/";
        String dbName = "p2p";
        String driver = "com.mysql.jdbc.Driver";
        String userName = "root";
        String password = "123";

        Class.forName(driver).newInstance();
        conn = DriverManager.getConnection(url+dbName,userName,password);

        Statement st = conn.createStatement();
        ResultSet rs = st.executeQuery( "select * from newuser where username =" + user  );

            if(rs.next())
            out.println("ok");
            else out.println("absent");

        st.close();
    }
    catch( Exception e )
    {
        out.print( "Database Error"+ e );
    }
    finally
    {
        try
        {
            con.close();
        }
        catch(Exception e1)
        {
        }
    }

%>
</body>
</html>

When i run it on glassfish the,jsp page request.getParameter function is receiving null i.e. it is outputting User:null, so pls help and also suggest some nice projects for ajax

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T23:45:25+00:00Added an answer on May 20, 2026 at 11:45 pm

    You are sending the username parameter to the JSP in the variable named q in your code and retrieving using the variable user

    xmlhttp.open("GET","get.jsp?q=" + str ,true);

    Now there can be two fixes :

    First and the best

    Fix in the javascript , change the name of variable from q to user like this, and let the JSP code remain unchanged.

    xmlhttp.open("GET","get.jsp?user=" + str ,true);

    Second Fix (not recommended)

    Fix the code in the JSP.

    Instead of String user = request.getParameter("user"); change it to String user = request.getParameter("q"); and let the script remain as it is…

    I think this should do the trick.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Code: <html xmlns=http://www.w3.org/1999/xhtml> <head> <title>Unusual Array Lengths!</title> <script type=text/javascript> var arrayList = new Array();
Code and preview: <html> <head> <title>Testing some CSS</title> <style type=text/css> .dDay { font-size:205% }
I have the following code <html> <head> <title>Test</title> <style type=text/css> <!-- body,td,th { color:
I have this code <html> <head> <style type=text/css> .frame {width: 50em; border: 1px solid
Let's say I have some code like this: <html> <head><title>Title</title></head> <body> <?php if (!$someCondition){
I am using jQuery and Ajax. My MainFile has the following code: <html> <head>
I have the following html code: <h3 id=headerid><span onclick=expandCollapse('headerid')>&uArr;</span>Header title</h3> I would like to
I have html code that looks roughly like this: <div id=id1> <div id=id2> <p>some
The following html code works in Firefox, but for some reason fails in IE
I have HTML code like this : <div> <a>Link A1</a> <a>Link A2</a> <a>Link A3</a>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.