動態製作svg介紹

來源:互聯網
上載者:User

http://blog.itpub.net/post/860/39133近日從來郵中,發覺網友對動態製作svg高度興趣,但卻難以入手,現介紹一下(使用jsp)。
首先製作svg:

 

drawCircle.jsp:
-------------------------------------------------
<?xml
version="1.0"?>

<%@ page contentType="text/xml"
%>
<svg>
<circle cx="<%=request.getParameter("x")%>"
cy="<%=request.getParameter("y")%>"
r="<%=request.getParameter("r")%>"
/>
</svg>
-------------------------------------------------

這是畫一個圓,其中圓中心,圓半徑由參數定。各位可以測試這個程式,在瀏覽器地址欄打入:

http://127.0.0.1:8080/testsvg/drawCircle.jsp?x=40&y=40&r=30

應該可以看到:
-----------------------------------------------------
<?xml
version="1.0"?>
<svg>
<circle cx="40" cy="40" r="30"
/>
</svg>
-----------------------------------------------------

如果看到這個結果,測試就成功了。接下來,怎樣顯示呢?因為目前的瀏覽器並不直接支援svg,
所以前面即使將"<%@ page
contentType="text/xml" %>"換成"<%@ page contentType="text/xml+svg"
%>"
或"<%@ page contentType="image/xml+svg"
%>之類也是徒勞的。解決之道是激發plug-in作用,所以要
添加一個輔助檔案,html或jsp皆可:

test.html:
-------------------------------------------------
<html>
<body>
<embed
type="image/svg+xml" src="drawCircle.jsp?x=40&y=40&r=30" width="100"
height="100"
/>
</body>
</html>
-------------------------------------------------
現在,在瀏覽器地址欄打入:

http://127.0.0.1:8080/testsvg/test.html

就能看到你所需的

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.