Java Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesJava Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old March 23rd, 2003, 05:27 PM
srivalli9 srivalli9 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Posts: 48 srivalli9 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 m 4 sec
Reputation Power: 6
Problems in servlet responding with an audio file

Hi ,

Could anyone please inform me about how can a servlet return an html file with background music in it?

in.html is a normal html file that cn be viewed in a browser. Music was played. its working fine.
But when i put the same code(in.html) as a response from a servlet, it isn't working. Could you please tell me how it can be done?

This is how I tested it...
I put in.html in C:/Tomcat/webapps/vegdeli2/
I run Tomcat, and in browser window typed...
http:\\localhost:8080\vegdeli2\in.html
It worked fine(music was played)

I put Test.java in
C:/Tomcat/webapps/vegdeli2/web-inf/classes
I run Tomcat and in browser window typed
http:\\localhost:8080\vegdeli2\servlet\Test
Music wasn't played

I couldn't figure out why music isn't played from a servlet.

CODE FOR TEST.JAVA..................
-----------------------------------------
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;

public class Test extends HttpServlet{

private PrintWriter out;

public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException{

resp.setContentType("text/html");
out=resp.getWriter();

out.println("<HTML><BODY>");
out.println("this is good");
out.println("<bgsound SRC=\"moonlight3.midi\" LOOP=infinite>");
out.println("</BODY></HTML>");
}
}


CODE FOR IN.HTML........
------------------------------
<HTML>
<BODY>
this is good
<bgsound SRC="moonlight3.midi" LOOP=infinite>
</BODY>
</HTML>

The audio file is moonlight3.midi

Thanks in advance for ur help.

Reply With Quote
  #2  
Old March 23rd, 2003, 07:03 PM
Nemi Nemi is offline
Clueless llama
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Feb 2001
Location: Lincoln, NE. USA
Posts: 2,353 Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 2 Days 12 h 35 m 19 sec
Reputation Power: 111
The most likely reason is the relative path you are using. When you use a relative path (a document-relative path in this case), the web browser makes an absolute path and then requests the info.

(I am assuming that moonlight3.midi is located in the same folder as in.html.) When the src attribute for the bgsound tag is parsed for the in.html file, it makes a url something like this:
Code:
<bgsound SRC="moonlight3.midi" LOOP=infinite>

gets turned into

http://localhost:8080/vegdeli2/moonlight3.midi
----------------
When it turns src attribute into a url for the servlet it makes this:

http://localhost:8080/vegdeli2/servlet/moonlight3.midi

As you can see, it is now requesting a servlet named moonlight3.midi. The easiest way to fix this is to use a root-relative path for the src attribute. Since you are in a web app you will need to get the contextpath and append it to the front of the link like this:
Code:
out.println("<bgsound SRC=\"" + request.getContextPath() + "/moonlight3.midi\" LOOP=infinite>");
Look at the outputted html when you get it in your browser. It should read:
Code:
<bgsound SRC="/vegdeli2/moonlight3.midi" LOOP=infinite>

Last edited by Nemi : March 23rd, 2003 at 07:05 PM.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesJava Help > Problems in servlet responding with an audio file


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT