• 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 ...
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

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

Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 (rs.next()){

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....
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please check your private messages regarding an important administrative matter.
Looky! I'm being abducted by space aliens! Me and this tiny ad!
the value of filler advertising in 2021
    Bookmark Topic Watch Topic
  • New Topic