Html文件中代码如下:
<body>
<bgsound src="file:///E|/a.mp3" loop="-1" balance="0" />
</body>运行有效
但是在Jsp文件中会出错,如何修改??   JSP中如何添加背景音乐???

解决方案 »

  1.   

    路径错误,在jsp添加背景音乐时,<bgsound src="<%=<%=request.getContextPath()%>%>music.mid" loop="-"> 必须要使用绝对路径,否则发布后网页无法播放背景音乐
      

  2.   

    src="file:///E|/a.mp3" 路径错误,要用你的request.getContextPath()作为src的头,最好音乐像你的jsp一样放在你的工程里面去,否则要配路径比较麻烦的。你把音乐文件当作一个jsp,然后在浏览器里面怎么找到这个jsp,就把浏览器里面的路径当作src的路径就可以。
      

  3.   

    <%@ page contentType="text/html; charset=gb2312"%>
    <html>
      <head>
        <title>页头</title>
      </head>
          <bgsound src="<%=<%=request.getContextPath()%>%>mr.wav" loop="-">
      <center>      <table border="0" width="100%" height="115" cellspacing="0" cellpadding="0">        <tr><td><img src="images/index/indexT.jpg"></td></tr>      </table>    </center>
      </body>
    </html>
    --------------------------------------------------------------
    运行结果:
    org.apache.jasper.JasperException: Unable to compile class for JSP
    An error occurred at line: 6 in the jsp file: /view/top.jsp
    Generated servlet error:
    Syntax error on token "<", invalid Expression
      

  4.   

    <bgsound src=" <%= request.getContextPath()%>mr.wav" loop="-"> 
    兄弟你加了两层
      

  5.   

    还不行的话,先在上面
    String path = request.getContextPath();
    System.out.println(path);
    看看这个path是啥,然后再拼路径定位到您那个mr.wav.good luck
      

  6.   

    <bgsound src="<%=request.getContextPath()%>/mr.wav" loop="-">
    可以了
    谢谢各位啦