Guest Ramesh Posted February 1, 2010 Report Share Posted February 1, 2010 (edited) Sir Actually i am using servlet to check whether the username is already existing or not in html text box? The servlet code is package ser; import java.sql.*; import javax.servlet.*; import javax.servlet.http.*; import java.io.IOException; import javax.swing.*; import java.io.*; public class AJAXCheckUsernameServlet extends HttpServlet{ boolean isExist; public void init(ServletConfig config) throws ServletException { super.init(config); } public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{ String Username = request.getParameter("username").trim(); isExist = check(Username); if(isExist){ response.setContentType("text/html"); response.setHeader("Cache-Control", "no-cache"); response.getWriter().write("true"); } else{ response.setContentType("text/html"); response.setHeader("Cache-Control", "no-cache"); response.getWriter().write("false"); } } public boolean check(String Username){ String uuse = Username; Connection con; isExist= false; //JOptionPane.showMessageDialog(null,""); try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); con = DriverManager.getConnection("jdbc:odbc:mail_server","Admin","12061985"); PreparedStatement stat = con.prepareStatement("SELECT USER_NAME FROM REG_USER WHERE USER_NAME = '"+uuse+"'"); ResultSet rs = stat.executeQuery(); while(rs.next()){ isExist = true; // con.close(); } con.close(); stat.close(); } catch(Exception e){ System.out.println("Error"+e); } return isExist; } } The AJAX-Javascript code is function check7(){ var username_ = document.getElementById('username').value; var url = "http://localhost:8081/CLIENT/AJAXCheckUsernameServlet.class?username="+username_; //alert(url); if(window.XMLHttpRequestObject){ xmlHttpRequestObject = new XMLHttpRequest(); } else if(window.ActiveXObject){ xmlHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP"); } xmlHttpRequestObject.open("GET",url); xmlHttpRequestObject.onreadystatechange = callback; xmlHttpRequestObject.send(null); } function callback() { if( xmlHttpRequestObject.readyState==4 ){ alert(xmlHttpRequestObject.status); if( xmlHttpRequestObject.status==200 ) { alert (xmlHttpRequestObject.responseText); document.getElementById('username').value = xmlHttpRequestObject.responseText; } } } It showing only Empty message in the alert box... This line -> alert (xmlHttpRequestObject.responseText); please help me... Edited February 1, 2010 by Ramesh Quote Link to comment Share on other sites More sharing options...
administrator Posted February 1, 2010 Report Share Posted February 1, 2010 I would need more information to be able to really say much. That said, it sounds like a path issue - check you file names. Stefan Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.