2009-11-16 42 views
0

我做了一个数据库,我打印我的必填字段在选取框中。调用函数

现在我想的是

if (change>0); 
print (image_21); 
else print (image_2); 

这是我使用的代码:

<%@page import="java.sql.*" %> 

<html> 
    <head> 
     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
     <title>JSP Page</title> 
     <script type="text/javascript"> 


      function img() 
      { 
       if(change > 0) 
       upimg(); 

       else 
       downimg(); 

      } 
        function upimg() 
    { 
      <img src="up.png" > 
    } 
      function downimg() 
    { 
      <img src="down.png"> 
    } 
     </script> 
    </head> 
    <body onload=" img() " > 


    <marquee style="font-size: 28pt; text-transform: uppercase; font-family: Times New Roman; color: #000fff; font-weight: bold"> 

    <% 
try{ 
try{} 
catch(Exception e) 
{} 


    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); 
    Connection conn=DriverManager.getConnection("jdbc:odbc:all","",""); 

     Statement stat=null; 
    ResultSet rst=null; 
    stat=conn.createStatement(); 


      String query="select * from list "; 
      rst=stat.executeQuery(query); 

      while(rst.next()) 
      { 


String Company=(String)rst.getString("Company"); 
String Open_Price=(String)rst.getString("Open_Price"); 
String change=(String)rst.getString("change"); 


    out.println(Company); 
    out.println(" "); 
    out.println(Open_Price); 
    out.println(",");   
} 
} 
catch(Exception e) 
     { 
    } 

%> 


    </marquee> 



    </body> 
</html> 

任何人可以请帮助?

+0

我建议w3schools。 – BalusC 2009-11-16 12:45:22

回答

0

恐怕你混淆了JSP和Javascript的问题。

我注意到,在服务器端(即JSP代码)你吃了抛出的任何异常:

catch(Exception e) { } 

这是坏的,因此无法检测到任何潜在的问题。

除此之外,假设change有效的Javascript(即客户端)的变量(我看不出它引用的其他地方),我认为这是在的Javascript功能相关的问题:

function upimg() 
{ 
    <img src="up.png" > 
} 

我宁愿把静态<img>在HTML体,并动态地改变它的来源:

<body onLoad="img()"> 
    ... 
    <img name="dynImg" /> 
</body> 

然后

function upimg() 
{ 
    document["dynImg"].src = "up.png"; 
} 

(检查语法)。