Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Ajax and JSTL Query possible?

843840Mar 21 2010 — edited May 29 2010
Hi all ! I want to know if this is possible and if you have an example you could show. So far Im trying like this:
function ajaxFunction(){
	alert("ajaxFunction");
	var ajaxRequest;  // The variable that makes Ajax possible!
	
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){	
		appendOptionLast(ajaxRequest.responseText);
		}
	}
	//var age = document.getElementById('age').value;
	//var wpm = document.getElementById('wpm').value;
	//var sex = document.getElementById('sex').value;
	//var queryString = "?age=" + age + "&wpm=" + wpm + "&sex=" + sex;
	//alert("Antes open");
	ajaxRequest.open("GET", "/TWC/Comun/Ajax.jsp", true);
	//alert("Despues open");
	ajaxRequest.send(null); 
}
And here is my JSP thats doing the query.
<%@page contentType="text/html"%>
<%@ page import="beans.*,java.util.*" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix=”sql” %>

<%@page pageEncoding="ISO-8859-1"%>

<sql:setDataSource dataSource=”jdbc/TWC” />

<sql:query var=”qryItems” >
    SELECT User_ID
    FROM product
    ORDER BY nombre
</sql:query>

<c:forEach var=”row” items=”${qryItems.rows}”>
     User: <c:out value=”${row.User_ID}” /><br>  
</c:forEach>
Thanks!
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 26 2010
Added on Mar 21 2010
15 comments
3,143 views