Hello,
I have been having this problem for the whole day today, so even after i googled for the solution i was not able to get one, so i had to post to this forum. I had checked the solutions suggested on this forum but its not working for me still.
Ok I would start from the beginning:
Plastform:
---------------
MAC OS X 10.5.2
Netbeans IDE 6.0.1
Glassfish V2UR1
MySQL 5.0
Firefox
Code:
1> I have an enterprise application in the NetBeans and basically i am trying to create a web 2.0 based project in which the user when he/she inputs the username they are immediately informed if the userid is available or not.
JSP code:
---------------
[CODE=java]<%--
Document : UserSignOn
Created on : Mar 13, 2008, 4:07:08 PM
Author : ankittoshniwal
--%>
<%@page contentType="te xt/html" pageEncoding="U TF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>User Sign On</title>
<script language="javas cript">
var xmlHttp;
function createXmlHttpRe quest()
{
try
{
xmlHttp = new XMLHttpRequest( );
} catch (tryMicrosoft)
{
try {
xmlHttp = new ActiveXObject(" Msxml2.XMLHTTP" );
}
catch (otherMicrosoft )
{
try
{
request = new ActiveXObject(" Microsoft.XMLHT TP");
}catch (failed)
{
xmlHttp = false;
}
}
}
if (!xmlHttp)
alert("error initializing XMlHttpRequest" );
}
function callServer()
{
createXmlHttpRe quest();
// var nameValue = document.getEle mentById("n");
var userNameValue = document.getEle mentsByName("us er").value;
var url = "/TestProject-war/data?tempUserNa me=" + escape(userName Value);
xmlHttp.open("G ET", url, true);
xmlHttp.onready statechange = confirmUpdate;
xmlHttp.send(nu ll);
}
function confirmUpdate()
{
if (xmlHttp.readyS tate == 4)
{
if (xmlHttp.status == 200)
{
var message =
xmlHttp.respons eXML
.getElementsByT agName("valid")[0]
.childNodes[0].nodeValue;
// Basically this is the point which is giving me errors
document.getEle mentById("resul ts").innerHTM L = message;
}
else
{
alert("Error loading page" + xmlHttp.status );
}
}
}
</script>
</head>
<body>
<p> We are trying to read</p>
<input type="text" onkeyup="callSe rver();"/>
<td width="31%" id=”results”>&n bsp;</td>
</body>
</html>
[/CODE]
Servlet Code:
--------------------
So what i was planning to do was get the input from the JSP page and transfer it to the Servlet. In the servlet i was trying to connect to database and get the username approved, but i was getting the same errors, and hence i deleted the whole code and i just wrote a simple code in which whatever might be the input by the user in the JSP page the servlet would return "true" from the servlet meaning the username is true and available.
Code is as follows:
[CODE=java]/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package org.web;
import java.io.*;
import java.net.*;
import java.math.*;
import java.util.List;
import java.util.ListI terator;
import javax.ejb.EJB;
import javax.servlet.* ;
import javax.servlet.h ttp.*;
import org.ejb.UserDet ailsFacadeLocal ;
import org.ejb.UserDet ails;
/**
*
* @author ankittoshniwal
*/
public class data extends HttpServlet {
@EJB
private UserDetailsFaca deLocal userDetailsFaca de;
String tempUsr;
String tempUsername;
String tempId;
/**
* Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
* @param request servlet request
* @param response servlet response
*/
protected void processRequest( HttpServletRequ est request, HttpServletResp onse response)
throws ServletExceptio n, IOException {
response.setCon tentType("text/html;charset=UT F-8");
PrintWriter out = response.getWri ter();
try {
// TODO output your page here
out.println("<h tml>");
out.println("<h ead>");
out.println("<t itle>Servlet data</title>");
out.println("</head>");
out.println("<b ody>");
out.println("<h 1>Servlet data at " + request.getCont extPath () + "</h1>");
UserDetails UserDetailsObj = new UserDetails();
out.println("</body>");
out.println("</html>");
} finally {
out.close();
}
}
// <editor-fold defaultstate="c ollapsed" desc="HttpServl et methods. Click on the + sign on the left to edit the code.">
/**
* Handles the HTTP <code>GET</code> method.
* @param request servlet request
* @param response servlet response
*/
protected void doGet(HttpServl etRequest request, HttpServletResp onse response)
throws ServletExceptio n, IOException {
PrintWriter out = response.getWri ter();
UserDetails userObj = new UserDetails();
// String checkName = request.getPara meter("name");
// String checkUserName = request.getPara meter("user");
// String temp;
response.setCon tentType("appli cation/xml");
response.setHea der("Cache-Control", "no-cache");
response.getWri ter().write("<v alid>true</valid>");
}
/**
* Handles the HTTP <code>POST</code> method.
* @param request servlet request
* @param response servlet response
*/
protected void doPost(HttpServ letRequest request, HttpServletResp onse response)
throws ServletExceptio n, IOException {
PrintWriter out = response.getWri ter();
doGet(request, response);
// processRequest( request, response);
}
/**
* Returns a short description of the servlet.
*/
public String getServletInfo( ) {
return "Short description";
}
// </editor-fold>
}[/CODE]
----------------------------------------------------------------------
can somebody explain me where i am going wrong, i have been following the IBM's AJAX tutorial but its not helping out.
Any help would be greatly appreciated.
Thanks,
Ankit.
I have been having this problem for the whole day today, so even after i googled for the solution i was not able to get one, so i had to post to this forum. I had checked the solutions suggested on this forum but its not working for me still.
Ok I would start from the beginning:
Plastform:
---------------
MAC OS X 10.5.2
Netbeans IDE 6.0.1
Glassfish V2UR1
MySQL 5.0
Firefox
Code:
1> I have an enterprise application in the NetBeans and basically i am trying to create a web 2.0 based project in which the user when he/she inputs the username they are immediately informed if the userid is available or not.
JSP code:
---------------
[CODE=java]<%--
Document : UserSignOn
Created on : Mar 13, 2008, 4:07:08 PM
Author : ankittoshniwal
--%>
<%@page contentType="te xt/html" pageEncoding="U TF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>User Sign On</title>
<script language="javas cript">
var xmlHttp;
function createXmlHttpRe quest()
{
try
{
xmlHttp = new XMLHttpRequest( );
} catch (tryMicrosoft)
{
try {
xmlHttp = new ActiveXObject(" Msxml2.XMLHTTP" );
}
catch (otherMicrosoft )
{
try
{
request = new ActiveXObject(" Microsoft.XMLHT TP");
}catch (failed)
{
xmlHttp = false;
}
}
}
if (!xmlHttp)
alert("error initializing XMlHttpRequest" );
}
function callServer()
{
createXmlHttpRe quest();
// var nameValue = document.getEle mentById("n");
var userNameValue = document.getEle mentsByName("us er").value;
var url = "/TestProject-war/data?tempUserNa me=" + escape(userName Value);
xmlHttp.open("G ET", url, true);
xmlHttp.onready statechange = confirmUpdate;
xmlHttp.send(nu ll);
}
function confirmUpdate()
{
if (xmlHttp.readyS tate == 4)
{
if (xmlHttp.status == 200)
{
var message =
xmlHttp.respons eXML
.getElementsByT agName("valid")[0]
.childNodes[0].nodeValue;
// Basically this is the point which is giving me errors
document.getEle mentById("resul ts").innerHTM L = message;
}
else
{
alert("Error loading page" + xmlHttp.status );
}
}
}
</script>
</head>
<body>
<p> We are trying to read</p>
<input type="text" onkeyup="callSe rver();"/>
<td width="31%" id=”results”>&n bsp;</td>
</body>
</html>
[/CODE]
Servlet Code:
--------------------
So what i was planning to do was get the input from the JSP page and transfer it to the Servlet. In the servlet i was trying to connect to database and get the username approved, but i was getting the same errors, and hence i deleted the whole code and i just wrote a simple code in which whatever might be the input by the user in the JSP page the servlet would return "true" from the servlet meaning the username is true and available.
Code is as follows:
[CODE=java]/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package org.web;
import java.io.*;
import java.net.*;
import java.math.*;
import java.util.List;
import java.util.ListI terator;
import javax.ejb.EJB;
import javax.servlet.* ;
import javax.servlet.h ttp.*;
import org.ejb.UserDet ailsFacadeLocal ;
import org.ejb.UserDet ails;
/**
*
* @author ankittoshniwal
*/
public class data extends HttpServlet {
@EJB
private UserDetailsFaca deLocal userDetailsFaca de;
String tempUsr;
String tempUsername;
String tempId;
/**
* Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
* @param request servlet request
* @param response servlet response
*/
protected void processRequest( HttpServletRequ est request, HttpServletResp onse response)
throws ServletExceptio n, IOException {
response.setCon tentType("text/html;charset=UT F-8");
PrintWriter out = response.getWri ter();
try {
// TODO output your page here
out.println("<h tml>");
out.println("<h ead>");
out.println("<t itle>Servlet data</title>");
out.println("</head>");
out.println("<b ody>");
out.println("<h 1>Servlet data at " + request.getCont extPath () + "</h1>");
UserDetails UserDetailsObj = new UserDetails();
out.println("</body>");
out.println("</html>");
} finally {
out.close();
}
}
// <editor-fold defaultstate="c ollapsed" desc="HttpServl et methods. Click on the + sign on the left to edit the code.">
/**
* Handles the HTTP <code>GET</code> method.
* @param request servlet request
* @param response servlet response
*/
protected void doGet(HttpServl etRequest request, HttpServletResp onse response)
throws ServletExceptio n, IOException {
PrintWriter out = response.getWri ter();
UserDetails userObj = new UserDetails();
// String checkName = request.getPara meter("name");
// String checkUserName = request.getPara meter("user");
// String temp;
response.setCon tentType("appli cation/xml");
response.setHea der("Cache-Control", "no-cache");
response.getWri ter().write("<v alid>true</valid>");
}
/**
* Handles the HTTP <code>POST</code> method.
* @param request servlet request
* @param response servlet response
*/
protected void doPost(HttpServ letRequest request, HttpServletResp onse response)
throws ServletExceptio n, IOException {
PrintWriter out = response.getWri ter();
doGet(request, response);
// processRequest( request, response);
}
/**
* Returns a short description of the servlet.
*/
public String getServletInfo( ) {
return "Short description";
}
// </editor-fold>
}[/CODE]
----------------------------------------------------------------------
can somebody explain me where i am going wrong, i have been following the IBM's AJAX tutorial but its not helping out.
Any help would be greatly appreciated.
Thanks,
Ankit.
Comment