Results 1 to 2 of 2

Thread: OJT devl ? - mixing JSP in JavaScript

  1. #1
    Join Date
    Oct 2006
    Location
    Neb.
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default OJT devl ? - mixing JSP in JavaScript

    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.


    Code:
    <%@ 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;
    %>
    }
    </script>
    <html> <head> <title>Dynamic Select list Test</title>
    </head>
    <body>
    
    <FORM name="menu0" method="post" action="emailFireID.jsp">
    <table border="0" cellpadding="8" cellspacing="0" width="100%" bgcolor="#FFFFFF">
    <tr>
    <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.close();
    	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">
      </SELECT></TD>
    </TR>
    </TABLE>
    </FORM>
    </body>
    </html>

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    "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?
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •