View Full Version : OJT devl ? - mixing JSP in JavaScript

10-26-2006, 06:20 PM
Can anyone confirm or steer me to a web site or text book that can clue me in on why the code below will no work?

After testing several iterations I can only conclude that I can not mix JSP within a JavaScript function. Because I can not get the server query hand me a new record set. I output a system message to tell me if I'm getting anything back.

<%@ page language="java" import="java.sql.*" %>
<%@ include file="Connections/oracle.jsp" %>

<% // Get a list of distinct Application names we support to display in a drop down list.
Driver DrivergetApp = (Driver)Class.forName(MM_oracle_DRIVER).newInstance();
Connection ConngetApp = DriverManager.getConnection(MM_oracle_STRING,MM_oracle_USERNAME,MM_oracle_PASSWORD);
PreparedStatement StatementgetApp = ConngetApp.prepareStatement("SELECT distinct(TRIM(APP)) AS APP FROM ALL_APPLICATIONS");
ResultSet getApp = StatementgetApp.executeQuery();
boolean getApp_hasData = getApp.next();
boolean getApp_isEmpty=true;
Object getApp_data=null;
int getApp_numRows = 0;
String DD_Appnm = ""; <!-- With out this piece of c!@p defined here I get an error undefined in the query statement.

<script language="JavaScript" type="text/JavaScript">
function getsvrinfo() {
alert("Function getsvrinfo Fired");
ind = document.menu0.ApplGroup.selectedIndex;
DD_Appnm = document.menu0.ApplGroup.options[ind].value;
alert("Did get a value>" + DD_Appnm + "<");
Driver DrivergetSvr = (Driver)Class.forName(MM_oracle_DRIVER).newInstance();
Connection ConngetSvr = DriverManager.getConnection(MM_oracle_STRING,MM_oracle_USERNAME,MM_oracle_PASSWORD);
PreparedStatement StatementgetSvr = ConngetSvr.prepareStatement("SELECT VIRTUALSERVER FROM ALL_SERVERS WHERE APP=\'" + DD_Appnm.replace('\'', ' ') + "\' ");
ResultSet getSvr = StatementgetSvr.executeQuery();
boolean getSvr_hasData = getSvr.next();
System.out.println("True record set exists=" + getSvr_hasData);
boolean getSvr_isEmpty=true;
Object getSvr_data=null;
int getSvr_numRows = 0;
<html> <head> <title>Dynamic Select list Test</title>

<FORM name="menu0" method="post" action="emailFireID.jsp">
<table border="0" cellpadding="8" cellspacing="0" width="100%" bgcolor="#FFFFFF">
<td colspan="2" valign="top">Application
<select name="ApplGroup" size="1" onChange="getsvrinfo()">
while (getApp_hasData) {
<option value="<%=((getApp.getObject("APP")!=null)?getApp.getObject("APP"):"")%>"><%=((getApp.getObject("APP")!=null)?getApp.getObject("APP"):"")%></option>
getApp_hasData = getApp.next();
getApp = StatementgetApp.executeQuery();
getApp_hasData = getApp.next();
getApp_isEmpty = !getApp_hasData;
</select> </td>
<TD width="50%">Server List:
<SELECT name="ServerGroup" size="1" id="SvrCat">

10-26-2006, 10:23 PM
"Doesn't work" isn't an adequate description of the problem. What do you expect it to do? What does it do? Do you get any errors?