• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

readyState=4 and Http 404 error in Ajax /Struts

 
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
I trying to solve out this problem ... i am trying a double combo box but i cant make a head where i have gone wrong. WHen i run it, i get a Ready State=4 but along side i get Http 404 error. Also my action class is not called.(I had some SOPs there).
Please Please help me...
-----------
index.jsp
-----------

<html:html>

<title>Double Combo - Ajax In Action</title>
<script type="text/javascript" src="net.js"></script>
<script type="text/javascript">
alert('I am in double combo ajax in action');
function FillTerritory(oElem,oTarget){
alert('I am in fill territory function');
alert('oElem :'+oElem.value);
alert('oTarget :'+oTarget.value);
var strValue = oElem.options[oElem.selectedIndex].value;
alert('strValue :'+strValue);
var url = '/SecondOptionsAction.do';
var strParams = 'q=' + strValue +"&f=" + oTarget.form.name +"&e=" + oTarget.name;
alert('q'+ strValue);
alert('f'+ oTarget.form.name);
alert('e'+ oTarget.name);
var loader1 = new
net.ContentLoader(url,FillDropDown,null,"POST",strParams);

}
function FillDropDown(){
var xmlDoc = this.req.responseXML.documentElement;
alert('Im in FillDropDown');
var xSel = xmlDoc.getElementsByTagName('selectElement')[0];
alert('before strfname 0');
var strFName = xSel.childNodes[0].firstChild.nodeValue;
alert('before strfname 1');
var strEName = xSel.childNodes[1].firstChild.nodeValue;

var objDDL = document.forms[strFName].elements[strEName];
objDDL.options.length = 0;

var xRows = xmlDoc.getElementsByTagName('entry');
alert('I am in Fill Drop Down function');
for(i=0;i<xRows.length;i++){
var theText = xRows[i].childNodes[0].firstChild.nodeValue;
var theValue = xRows[i].childNodes[1].firstChild.nodeValue;
var option = new Option(theText,theValue);
objDDL.options.add(option,objDDL.options.length);
}
}
</script>
</head>
<body>
<html:form action="/SecondOptionsAction" styleId="inputForm">
<html:select property="ddlRegion" onchange="javascript:FillTerritory(this,document.forms[0].ddlTerritory)" styleId="Select1">
<html ption value="-1">Pick A Region</html ption>
<html ption value="Eastern">Eastern</html ption>
<html ption value="Western">Western</html ption>
<html ption value="Northern">Northern</html ption>
<html ption value="Southern">Southern</html ption>
</html:select>
<html:select property="ddlTerritory" styleId="Select2"></html:select>
</html:form>
</body>
</html:html>
---------------------------
--------------------------
Action Class
--------------------
package com.cris;
import org.apache.log4j.*;
import com.cris.ResultBean;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import java.io.*;

import java.util.*;
import java.sql.*;
import java.sql.Connection;

import javax.servlet.http.*;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


public class SecondOptionsAction extends Action
{
public ArrayList fillDataTable(String sqlQuery )
{
ArrayList results= new ArrayList();
ResultSet rs=null;
Connection con=null;
try
{
System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>");
System.out.println("----fillDataTable Method----");
System.out.println(">>>>>>>>>>>>>>>>>>>>>>");
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc dbc:ankitDB1","scott","tiger");
Statement st=con.createStatement();
rs= st.executeQuery(sqlQuery);
while (rs.next())
{
//ArrayList results= new ArrayList();
System.out.println(">>>>>>>>>>>>>>>>>>");
System.out.println("-Inside rs.next()");
System.out.println(">>>>>>>>>>>>>>");
ResultBean resultBean = new ResultBean();

resultBean.setTerritoryDescription( rs.getString("TerritoryDescription") );
resultBean.setRegionid(rs.getString("regionid"));
resultBean.setTerritoryID(rs.getString("TerritoryID"));

results.add(resultBean);
System.out.println(">>>>>>>>>>>>>>>>");
System.out.println("---results added ---");
System.out.println(">>>>>>>>>>>>>>>>>>>>");
}
}
catch(Exception e)
{
System.out.println("Exception "+e);
}
finally
{
if (rs != null)
{
/*
Statement stmt = rs.getStatement();
if (stmt != null)
{
stmt.close();
}
*/
//rs.close();
//con.close();
}
}
return results;
}

public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
{
response.setContentType("text/xml");
String strQuery="";
// 'q' is the selected Region='Eastern'
strQuery = request.getParameter("q");
String strForm="";
// 'f' is the name of the form
strForm = request.getParameter("f");
String strElem="";
// 'e' is the second select (teritory)in the jsp= 'assam'
strElem = request.getParameter("e");
System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
System.out.println("-----------Action Class-----------------");
System.out.println("the Region, is set as ["+strQuery+"]");
System.out.println("the form, is set as ["+strForm+"]");
System.out.println("the territory is set as ["+strElem+"]");
System.out.println(">>>>>>>>>>>>>>>>>>>>");

String strSql = "SELECT TerritoryDescription,TerritoryID FROM Territories"
+ " WHERE regionid ='" + strQuery +"' ORDER BY TerritoryDescription";

ArrayList dtOptions=new ArrayList();
System.out.println("!!!");
System.out.println("------After the Query-------");
System.out.println("the Query is ["+strSql+"]");
System.out.println("!!!>");

dtOptions=fillDataTable(strSql);

while(!(dtOptions.isEmpty()))
{
for(Iterator iterator=dtOptions.iterator();iterator.hasNext()
{
ResultBean rb = new ResultBean();
rb = (ResultBean) iterator.next();
String terr_description = rb.getTerritoryDescription();
System.out.println(">>>>>>>>>>>>>>>>>>>>");
System.out.println("---Im in Iterator---");
System.out.println("the terr_description is ["+terr_description+"]");
String terr_id=rb.getTerritoryID();
System.out.println("the terr_id is ["+terr_id+"]");
System.out.println(">>>>>>>>>>>>>>>>>>>");

StringBuffer strXML= new StringBuffer("<?xml version=1.0 ?>");
System.out.println("--------------");
System.out.println("-----XML Creation---");
System.out.println("--------------------");

strXML.append("<selectChoice>");
strXML.append("<selectElement>");
strXML.append("<formName>"+strForm+"</formName>");
strXML.append("<formElem>"+strElem+"</formElem>");
strXML.append("</selectElement>");
System.out.println(">>>>>>>>>>>>>>");
System.out.println("--<selectChoice>------");
System.out.println(">>>>>>>>>>>>>>>>>>");

strXML.append("<entry>");
strXML.append("<optionText>Select A Territory</optionText>");
strXML.append("<optionValue>-1</optionValue>");
strXML.append("</entry>");
System.out.println("--------------");
System.out.println("----creating entry--");
System.out.println("----------------");
strXML.append("<entry>");
strXML.append("<optionText>"+terr_description
+"</optionText>");
strXML.append("<optionValue>"+terr_id
+"</optionValue>");
strXML.append("</entry>");
strXML.append("</selectChoice>");
System.out.println("------------------");
System.out.println("----XML End-----");
System.out.println("----------------");
}
}
return mapping.findForward("index");

}
}
--------------------------------------
cant post the Net.js ....sys doent allow me...
--------------------------------------
Please help me....
Regards,
Roshani
[ September 11, 2006: Message edited by: RoshaniG Gopal ]
 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

Since your action class is not being called, most probably your request is not being set properly.

Try calling the action class directly by setting the url location to

http:// <server name >/ context path/ SecondOptionsAction.do? requestparams

see if you get the proper xml output.
 
RoshaniG Gopal
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI anay,
Thanks for the reply, but still cant get things to work out.

Regards,
Roshani
 
Anay Nayak
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
did you try calling the action class directly? Did it return any output ? If that failed..then i guess you have not set the configuration properly.

Another thing that i noticed, what's the purpose of strXML? You dont seem to be using it. I guess that was supposed to be part of the output

Check the last post by Merrill over here
[ September 13, 2006: Message edited by: Anay Nayak ]
 
RoshaniG Gopal
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Anay,
Thanks a lot for the replies.. The link was really usefull i wonder how i missed it..Im quite regular..anyhow..I changed the whole thing to a new one.. Im posting it in a new thread as else i would be hijacking this one..Im having problem in the XML reposonse..
Regards,
Roshani
 
Slideshow boring ... losing consciousness ... just gonna take a quick nap on this tiny ad ...
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic