以文本方式查看主题

-  计算机科学论坛  (http://bbs.xml.org.cn/index.asp)
--  『 SVG/GML/VRML/X3D/XAML 』  (http://bbs.xml.org.cn/list.asp?boardid=21)
----  关于jsp与SVG中变量引用的问题,急!  (http://bbs.xml.org.cn/dispbbs.asp?boardid=21&rootid=&id=16882)


--  作者:kerons
--  发布时间:4/12/2005 1:01:00 PM

--  关于jsp与SVG中变量引用的问题,急!
我的jsp页面从数据库中取的数据,具体就是SVG图形中RECT的高度,
下面有两个文件,我想问问:怎么样将jsp里面取到的num的数据用到SVG中的改变高度中去? 是用脚本控制么?怎么样写?

本人非常急,希望大家帮忙!谢谢
ex12.jsp

<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.sql.*"%>
<html>
<body>

<embed name="id1" pluginspage=http://www.adobe.com/svg/viewer/install/ align="top" src="1.svg" height="1200px" width="1200px" type="image/svg+xml">

<%
  Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();  
   Connection conn= DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=date","sa","sa");
  Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
  String sql="select * from record";
  ResultSet rs=stmt.executeQuery(sql);
  String date;
  int num;
while(rs.next())

  {       date= rs.getString(1);
        //   num 数值要用到svg图象中去,具体就是rect的高
          num=rs.getInt(2);
          out.println("<br>");
         out.println(" "+date+" ");
         out.println(" "+num+" ");
          out.println("</br>");
     }
%>
<%out.print("<br> 数据库操作成功,恭喜你</br>");%>
<%rs.close();
stmt.close();
conn.close();
%>

</body>
</html>

1.svg

<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN"
  "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
<svg width="1000" height="1000" viewBox="-100 -100 1300 1300" xmlns="http://www.w3.org/2000/svg"
                      xmlns:xlink="http://www.w3.org/1999/xlink"  >
<script type="text/javascript">
<![CDATA[

function setHeight_1(rect_id,num,evt)
   {
     var svgDocument=evt.getTarget();

     var  y_old=svgDocument.getAttribute("y");
     svgDocument.setAttribute("y",600-num);
     svgDocument.setAttribute("height",num);
   }

  var num1,num2;

//]]>
</script>
<g>
  <line x1="60" y1="600" x2="60" y2="-20" stroke="rgb(0,0,0)"/>
<text id="chuizhi" x="0" y="-20" style="font-size :30 ;fill:red " > Num </text>
<line x1="60" y1="600" x2="600" y2="600" stroke="rgb(0,0,0)"/>
  <line x1="60" y1="300" x2="600" y2="300" />
<line x1="60" y1="0" x2="600" y2="0" />
<text x="40" y="0" > 600 </text>
<text x="40" y="300"> 300 </text>
<rect id="rect1"  x="75" y="400" fill="orange" height="200" width="40"
                 onclick="setHeight_1('rect1',num1,evt)" />
<rect id="rect2" x="155" y="200" fill="purple " height="400" width="40"
                      onclick="setHeight_1('rect2',num2,evt)" />
     
</g>
</svg>



--  作者:mi9
--  发布时间:4/12/2005 2:21:00 PM

--  
ex12.jsp

<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.sql.*"%>
<html>
<script type="text/javascript">
function setHeight_1(rect_id,num,evt)
   {
     var svgDocument=evt.getTarget();

     var  y_old=svgDocument.getAttribute("y");
     svgDocument.setAttribute("y",600-num);
     svgDocument.setAttribute("height",num);
   }

  var num1,num2;

</script>
<body>

<embed name="id1" pluginspage=http://www.adobe.com/svg/viewer/install/ align="top" src="1.svg" height="1200px" width="1200px" type="image/svg+xml">

<%
  Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();  
   Connection conn= DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=date","sa","sa");
  Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
  String sql="select * from record";
  ResultSet rs=stmt.executeQuery(sql);
  String date;
  int num;
while(rs.next())

  {       date= rs.getString(1);
        //   num 数值要用到svg图象中去,具体就是rect的高
          num=rs.getInt(2);
          out.println("<br>");
         out.println(" "+date+" ");
         out.println(" "+num+" ");
 %>
 num1 = <%=num%>;
 num2 = <%=num%>;
 <%
          out.println("</br>");
     }
%>
<%out.print("<br> 数据库操作成功,恭喜你</br>");%>
<%rs.close();
stmt.close();
conn.close();
%>

</body>
</html>

1.svg

<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN"
  "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
<svg width="1000" height="1000" viewBox="-100 -100 1300 1300" xmlns="http://www.w3.org/2000/svg"
                      xmlns:xlink="http://www.w3.org/1999/xlink"  >
<g>
  <line x1="60" y1="600" x2="60" y2="-20" stroke="rgb(0,0,0)"/>
<text id="chuizhi" x="0" y="-20" style="font-size :30 ;fill:red " > Num </text>
<line x1="60" y1="600" x2="600" y2="600" stroke="rgb(0,0,0)"/>
  <line x1="60" y1="300" x2="600" y2="300" />
<line x1="60" y1="0" x2="600" y2="0" />
<text x="40" y="0" > 600 </text>
<text x="40" y="300"> 300 </text>
<rect id="rect1"  x="75" y="400" fill="orange" height="200" width="40"
                 onclick="setHeight_1('rect1',num1,evt)" />
<rect id="rect2" x="155" y="200" fill="purple " height="400" width="40"
                      onclick="setHeight_1('rect2',num2,evt)" />
     
</g>
</svg>
这样改不知道行不行,我jsp不好,就当是在学习你的代码喽,但你这样做的话只会以最后一条数据中的num值来改变矩形阿,你是想要这个效果吗


--  作者:henrybenben
--  发布时间:4/13/2005 9:49:00 PM

--  
学习中,谢谢指点!
--  作者:kerons
--  发布时间:4/14/2005 8:44:00 PM

--  
问题我解决了,谢谢

我后来将num该成用数组,这样就可以把所有数据都用上。


--  作者:犬神狼
--  发布时间:4/23/2005 4:08:00 PM

--  
能不能这仔细说一下啊?
num1 = <%=num%>;
num2 = <%=num%>;这两句有效吗?
可以直接在JSP代码中对JavaScript中的变量赋值?

--  作者:kerons
--  发布时间:4/24/2005 9:02:00 AM

--  
不是改js的变量,只是以一个参数带进去
W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
93.750ms