Hi,
I'm new bee to JSP.I'm newly joined in company they want to finish this today please help me.

I need to check form field contains existing data(want to check database) are not.
if that field contain existing data it wants give alert..,

In database i set projectcode as Unique.if 1st user giving projectcode as 1 it wants to store.

if 2nd user giving the same projectcode it want's to throw alert msg..,

But i need to learn step by Step.
So i created Form with one Field(ProjectCode).In database i set ProjectCode as unique.

my code coming below

javaScript in Form

function loadContent(formj)
{

 xmlhttp=GetXmlHttpObject();

  if (xmlhttp==null)
  {
   alert ("Your browser does not support Ajax HTTP");
   return;
  }
  
    var stateValue = formj.dil_ProjectCode.value;
	alert(stateValue);
    var url="Code.jsp";
    url=url+"?dil_ProjectCode="+stateValue;
	alert(url);
    xmlhttp.onreadystatechange=getOutput;
    xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
}


function getOutput()
{
  if (xmlhttp.readyState==4)
  {
	
	 var result = xmlhttp.responseText;
	alert(result);
}
}

function GetXmlHttpObject()
{
    if (window.XMLHttpRequest)
    {
       return new XMLHttpRequest();
    }
    if (window.ActiveXObject)
    {
      return new ActiveXObject("Microsoft.XMLHTTP");
    }
 return null;
}

form field code

<input type="text" name="dil_ProjectCode" id="dil_ProjectCode" >

code.jsp(it is reffered in javascript)

DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());

	con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:sid","username","password");
	
	stateId = request.getParameter("dil_ProjectCode");
	
    String query = "select projectcode from jerald where projectcode ="+stateId+"";

	stmt = con.prepareStatement(query);
	
	rs = stmt.executeQuery();
	String Project = null;
	while(rs.next())
	{

	Project = ""+ rs.getString(1);

	}
	out.print(Project);
}

in this code i want to get value of project in alert msg.
but i'm not retrieving any data in alert msg showing blank window please help me...

Then it looks as though the query isn't returning anything, or, if that is the complete output, then the browser doesn't recognise it as a proper response.

i need to get the user input in java script
from java script send to another jsp and perform some action and return the RESULT..,


The above code i used for generating dynamic combo box, already fetch the data from database in the 1st combo box.tat data getting by java script,and sent to another JSP and perform action and getting output of 2nd combo box.

getting the user input in javascript and sending the data to another JSP is have different step r else we can use same steps like generating dynamic combo box..,

Okay? And?

The response still needs to be a properly formed html (actually, since your doing xmlhttp probably xml) response and not just a bare word.

JavaScript:

var stateValue = formj.dil_ProjectCode.value;
    var url="Code.jsp";
    url=url+"?dil_ProjectCode="+stateValue;
    xmlhttp.onreadystatechange=getOutput;
    xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
}


function getOutput()
{
  if (xmlhttp.readyState==4)
  {
	alert("xmlhttp.responseText");
	 var result = xmlhttp.responseText;
	alert(result);
}
}

servlet Code

stateId = request.getParameter("dil_ProjectCode");[B]--->(Here I'm Not Getting any Value)[/B]
	
    String query = "select projectcode from jerald where projectcode ='"+stateId+"'";

code is not change but i find out the error it is boldly displayed..,
and Y it is not retrieving value

Then, as I said, the query is not returning anything since the parameter is not getting returned. That the parameter is not getting valued can only depend on what that value should be. If it contains anything other than normal letters and numbers, make sure to url encode it before adding it to the url, and make sure there is a value. In any case, this is now more a JavaScript question than it is a Java question. Moving this thread.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.