这是我的servlet。我可以在我的网页上上传无法播放的歌曲。一切似乎都是对的。我不知道我哪里出错了。 src我提到一个链接是正确的。我的意思是路径是正确的。但是我出错了我不知道。
这是我的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 :(得分:0)
我自己得到了答案 我刚刚用过 SRC1 = “HTTP://本地主机/ EHSAUDIO /” + f.getName()“; 而不是考虑路径。 谢谢