File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes Using AJAX in Struts.... need steps to Implement.. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Using AJAX in Struts.... need steps to Implement.." Watch "Using AJAX in Struts.... need steps to Implement.." New topic

Using AJAX in Struts.... need steps to Implement..

Harish Maridi
Ranch Hand

Joined: May 20, 2008
Posts: 60
Hi Friends,

I am new to java, I am trying to implement AJAX with struts framework.
Please let me know the steps to be followed to do that.

What I did is,

step 1: I attached a listner to the JSP dropdown menu field
step 2: I made a java script file with url: db.jsp
step 3: created a db.jsp, and accessed the parameter from the jsp here
step 4: I catched the response of the server in java script file

Here comes the problem, I am unable to populate the list from the server responce in to the JSP drop down menu list.

I am also providing the code that I did....

JSP code where I am checking the State change:
Name: EnterNewRequest.jsp

<script type="text/javascript" src="select.js">


<select name="state" onchange="show(this.value)">

This is my java script for AJAX call� Observe the FUNCTION stateChanged()�.
Name: select.js

var xmlHttp

function show(str)
if (xmlHttp==null)
alert ("Your browser does not support AJAX!");
var url="DB.jsp";

function stateChanged()
if (xmlHttp.readyState==4)



function GetXmlHttpObject()
var xmlHttp=null;
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
catch (e)
// Internet Explorer
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
catch (e)
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
return xmlHttp;

This is my DB.Jsp from where the data from DB is fetching�..

ArrayList COCLLIList = new ArrayList();
EnterNewRequestFormENRF = new EnterNewRequestForm();

Connection conn = Connection.getConnection();

PreparedStatement pstmt = null;
ResultSet rs = null;

String COCLLIsql = "SELECT LOC "+"FROM FINAL"+" WHERE LOC like '%"+request.getParameter("q")+"%'";
System.out.println("SQL :"+sql);
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
List = new ArrayList();

while ({

String loc = rs.getString(1);



}catch (Exception e){
throw e;
if(rs!=null){try{rs.close();}catch(SQLException e){}}
if(pstmt!=null){try{pstmt.close();}catch(SQLException e){}}
if(conn!=null){try{conn.close();}catch(SQLException e){}}

System.out.println("ArrayList is Emplty");


The List is coming here��.

The section where I need to put that CLLIList in JSP is �..
Name: EnterNewRequest.jsp

<select id="list" name="second">
<option selected value="0">Choose</option><option value="1"><div id="cllilist"><b></b></div>
</option> <option value="2">No Values</option></select></td>

This is the process I followed, but I am not getting the data to this dropdown menu.

My frame work is Struts, but here I am operating on db.jsp which is not encourageble, Please suggest me how to do it with struts.

any help will be appreciated....
Ben Souther

Joined: Dec 11, 2004
Posts: 13410

Please check your private messages regarding an important administrative matter.

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
I agree. Here's the link:
subject: Using AJAX in Struts.... need steps to Implement..
It's not a secret anymore!