• 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 ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Java to javascript and back again...please help:)

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What I am trying to do: A user hits the JSP on the web, the page hits an Oracle database and dynamically builds a sortable table.
Known problems: Besides the fact that it just isn�t working?
Passing the y value (a counter) to the JSP but even when I
Hard code in a value for y I get nothing.
Nothing displays.
I�ve extracted out most of the code and this should build a table within a &ITdiv> on another page but even when ran as a stand alone
I get errors. When I put it into the &ITdiv> All I see in the window where a table should be is my source code.
I�ve posted this in the JSP section and in Java section because I do not know where it should go.
As always, Thanks for the insights. I need some help as I have been struggling all week-end with this.

Side Note: all �less then� signs had to replaced with �&it�
And �onclick� had to replace with �onKlick� in order to post.

&IT%@ page import="java.sql.*" %>
&IT%@ page import="java.text.SimpleDateFormat" %>
&IT%@ include file="connectDB.jsp" %>
&ITHTML>
&ITBODY>
&ITSCRIPT FOR=window EVENT=onload LANGUAGE="javascript">

&IT% System.out.println("--------------------starting page--------------------");%>
&ITSCRIPT LANGUAGE="JAVASCRIPT" TYPE="TEXT/JAVASCRIPT">
&ITtable id="tblMISSION" width="100%">
&ITthead>
&ITtr bgcolor="lightyellow" style="font-size:10;font-weight:bold;font-family:arial" style="position:relative; top:expression(this.offsetParent.scrollTop -2);left: -1">
&ITth>&ITa href="#" title="Number" onklick="return sortTable(this)">#&IT/a>&IT/th>
&ITth>&ITa href="#" title="NAME" onklick="return sortTable(this)">NAME&IT/a>&IT/th>
&ITth>&ITa href="#" title="CITY" onklick="return sortTable(this)">CITY&IT/a>&IT/th>
&ITth>&ITa href="#" title="GENDER" onklick="return sortTable(this)">GENDER&IT/a>&IT/th>

&IT!--
&ITtd title="Number">#&IT/td>
&ITtd title="NAME">NAME&IT/td>
&ITtd title="CITY" >CITY&IT/td>
&ITtd title="GENDER" >GENDER&IT/td>
-->
&IT/tr>

&IT%
SimpleDateFormat formatter = new SimpleDateFormat("dd/MMM/yy");

String sql = "SELECT NUMBER, NAME, CITY, GENDER FROM MYTABLE ";

ResultSet rs = statement.executeQuery(sql);
String num="";
String name="";
String city="";
String gender="";

int counter=0;
System.out.println("--------------------calling while("+rs.next()+")--------------------");
while (rs.next())
{
//System.out.println("--------------------Hitting database--------------------");
num=rs.getString(1);
if(num == null){num = "";}
name=rs.getString(2);
if (name==null){name="";}
city=rs.getString(3);
if(city == null){city = "";}
gender=rs.getString(5);
if (gender==null){gender="";}


// add a step to convert from java to jsScript and put into an array
%>
&IT!-- Make a call to js to put all the data in a js array of data objects to be sorted. -->
&ITSCRIPT LANGUAGE="JavaScript">
SDBObject(num,name,city,gender, &IT% counter %> ;
&IT/SCRIPT>

&IT%
counter++;


%>
&IT!�I was just hard coding a table in here originally
&IT%
}
%>

&IT/thead>
&ITtbody id="sortData">&IT/tbody>
&IT/table>
&ITSCRIPT LANGUAGE="JavaScript">drawTable("sortDate");&IT/SCRIPT>
&IT%
statement.close();
connection.close();
%>
&IT/BODY>
&IT/HTML>

&ITSCRIPT LANGUAGE="JAVASCRIPT" TYPE="TEXT/JAVASCRIPT">
&IT!--
function drawTable(tbody) {
&IT%System.out.println("--------------------drawTable--------------------");%>
var tr, td;
tbody = document.getElementByID(tbody);
for(var k = 0; k &IT jsData.length; k++) {
tr = tbody.insertRow(tbody.row.length);
td = tr.insertCell(tr.cells.length);
td.setAttribute("align","center");
td.innerHTML = jsData[k].Num;
td = tr.insertCell(tr.cells.length);
td.innerHTML = jsData[k].NUM;
td = tr.insertCell(tr.cells.length);
td.innerHTML = jsData[k].NAME;
td = tr.insertCell(tr.cells.length);
td.innerHTML = jsData[k].CITY;
td = tr.insertCell(tr.cells.length);
td.innerHTML = jsData[k].GENDER;
td = tr.insertCell(tr.cells.length);

}
}
function sortTable(link) {
&IT%System.out.println("--------------------sortTable()--------------------");%>
switch(link.firstChild.nodeValue){
case "NUM":
js.Data.sort(sortByNumber);
break;
case "MISSION":
jsData.sort(sortByMission);
break;
}
drawTable("sortData")
return false;
}//end sortTable(link) function
function SDBObjects(name, city,gender, i){
&IT%System.out.println("--------------------SDBObjects()--------------------");%>
jsData[i] = {Num: i,NAME: name, CITY: city, GENDER: gender };
}
function sortByMission(a,b){
a = a.location.toLowerCase();
b = b.location.toLowerCase();
return((a&ITb) ? -1 (a>b) ? 1:0));
}
-->
&IT/SCRIPT>
 
drifter
Posts: 1364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you try to use Code Tags?
[ January 25, 2005: Message edited by: Carol Enderlin ]
 
Kevin Hamrick
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Didn't know about the code tags...here is the example again. I still needed to replace onclick with onKlick..please help
 
Carol Enderlin
drifter
Posts: 1364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You've got some extra script tags. What should be inside script tags? Stuff like functions. Not HTML, not scriptlets. Do you have end script tags for each start script tag? I guess I looked really quickly, but they seem to be nested and I didn't see very many end tags. What are you trying to do with the onload? I would expect to see javascript such as function calls inside the onload script tag.

Also, have you thought about using javabeans, jstl, etc. to get the java out of your jsp?

Carol
 
You got style baby! More than this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic