2015-09-13 107 views
0

這是我的servlet。,我能夠上傳歌曲bur無法播放它在我的網頁上。一切似乎都對。我不知道我出錯的地方。 src我已經提到了一個鏈接是正確的,我的意思是路徑是正確的。但是我出錯了,我不知道。錯誤:音頻播放被中止HTML

This is the error Im getting

這裏是我的servlet PlaySinger.java

package com.ea.servlet; 

import java.io.File; 
import java.io.IOException; 
import java.io.PrintWriter; 
import java.sql.Connection; 
import java.sql.DriverManager; 
import java.sql.ResultSet; 
import java.sql.SQLException; 
import java.sql.Statement; 

import javax.servlet.RequestDispatcher; 
import javax.servlet.ServletContext; 
import javax.servlet.ServletException; 
import javax.servlet.http.HttpServlet; 
import javax.servlet.http.HttpServletRequest; 
import javax.servlet.http.HttpServletResponse; 
import javax.servlet.http.HttpSession; 

public class PlaySinger extends HttpServlet 
{ 
private static final long serialVersionUID = 1L; 

public Statement st; 
public ResultSet rs; 
/** 
* @see HttpServlet#HttpServlet() 
*/ 
public PlaySinger() { 
    super(); 
    // TODO Auto-generated constructor stub 
} 

/** 
    * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) 
*/ 
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 
    try{ 

     //loading drivers for mysql 
     Class.forName("com.mysql.jdbc.Driver"); 

     //creating connection with the database 
      Connection con=DriverManager.getConnection 
        ("jdbc:mysql://localhost:3306/EATWO","root",""); 
      PrintWriter out=response.getWriter(); 
      HttpSession h=request.getSession(); 
      String film=request.getParameter("film"); 
      String uname=request.getParameter("userID");    

     st = con.createStatement(); 
     ResultSet rs = st.executeQuery("select * from eatwo.vocal where userID='"+uname+"'"); 
     out.println("<html><head>" 
        + "<title>Listen</title>" 
        //+ "<link rel='stylesheet' href='table2.css' type='text/css' media='screen' title='no title' charset='utf-8'/>" 
        + "<link rel='stylesheet' href='style4.css' type='text/css' media='screen' title='no title' charset='utf-8'/>" 
        + "</head>" 
        + "<body background='musicOne.jpg'>"); 
     out.println("<table width='358' border='0' cellspacing='0' cellpadding='0' class='table'>"); 
     out.println("<tr><td><p id='head'>Songs Uploaded</p></td></tr>"); 
     out.println("<tr><td><br></td></tr>"); 
      while(rs.next()) 
      {     
         //out.println("<tr><td>'"+h.getAttribute("phno1")+"'</tr></td>"); 
         File f = new File(rs.getString(4)); 
         //C:\wamp\www\EHSAUDIO 
         String src1 = "c:\\wamp\\www\\EHSAUDIO\\"+f.getName(); 
         String audformat = f.getName(); 

         if(audformat.contains("mp3")) 
         { 
          audformat = "audio/mpeg"; 
         } 
         else 
          if(audformat.contains("ogg")) 
          { 
           audformat = "audio/ogg"; 
          } 
         else 
          if(audformat.contains("wav")) 
           { 
            audformat = "audio/wav"; 
           } 
          else 
           if(audformat.contains("")) 
           { 
            audformat=""; 
           } 

         //out.println(src1 + ""+ audformat); 
         System.out.println("source "+src1+" Audio Format "+audformat); 

    out.println("<tr><td><audio controls autoplay><source src=\""+src1+"\" type=\""+audformat+"\"> </audio><br><br><br>") ; 

      } 
      out.println("<tr><td><a href='logout.html'>LOGOUT</a></td></tr>"); 
      System.out.println("uname is"+uname); 
      // out.println("<tr><td><a href='prod1?username="+uname+"'>Contact This Singer</a></td></tr>"); 
      out.println("</table>"); 

        out.println("</body></html>"); 
        out.println("");      


    } 
catch(Exception e3) 
{ 
    e3.printStackTrace(); 
} 
} 

/** 
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) 
*/ 
    protected void doPost(HttpServletRequest request, HttpServletResponse  response) throws ServletException, IOException { 
    // TODO Auto-generated method stub 
} 

} 

回答

0

我得到了我的答案我自己 我只是用 SRC1 = 「HTTP://本地主機/ EHSAUDIO /」 + f.getName( )「; 代替考慮路徑 謝謝