📄 jukebox.java
字号:
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
public class Jukebox extends HttpServlet {
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
Song cancionA = new Song("Panchai Nirame" , "2:15" , "Tamil Pop" ,
"Alai Payuthey (2000)" , "A", "http://www.raaga.com/channels/tamil/movie/T0000209.html" ,
false );
Song cancionB = new Song("Bombay (Children of Combodia)" , "2:38", "Jazz", "Fred Anderson Quartet/1" , "B" ,
"http://www.epitonic.com/artists/fredandersonquartet.html#tracks" , false) ;
Song cancionC = new Song("A Dios Le Pido" , "1:50" , "Latin Pop" , "Juanes : Un Dia Normal/1" , "C" ,
"http://es.artists.mp3s.com/artist_song/2515/2515448.html" , false );
Vector lista = new Vector();
lista.add(cancionA);
lista.add(cancionB);
lista.add(cancionC);
for(int i = 0; i < lista.size(); i++)
{
String a = request.getParameter(((Song)lista.elementAt(i)).getId());
if(a != null){
((Song)lista.elementAt(i)).getSelected(true);
}
}
displayHtml(lista, response);
}
public void displayHtml(Vector lista, HttpServletResponse response)
throws IOException
{
response.setContentType("text/html");
PrintWriter printwriter = response.getWriter();
HtmlPage htmlpage = new HtmlPage();
htmlpage.setTitle("Tocadiscos");
htmlpage.setBackgroundColor("#9966FF");
htmlpage.addText("<H1>Tocadiscos</H1>");
htmlpage.addText("<FORM action='/servlet/Jukebox' method='post'>");
htmlpage.addText("<H4>Escoge tus rolas</H4>");
HtmlTable htmltable = new HtmlTable(10);
htmltable.startRow();
htmltable.addCell("<B>Titulo</B>");
htmltable.addCell("<B>Duracion(min)</B>");
htmltable.addCell("<B>Categoria</B>");
htmltable.addCell("<B>Album/Pista</B>");
htmltable.endRow();
for(int i = 0; i < lista.size(); i++)
{
htmltable.startRow();
String a = "<INPUT type='checkbox' name='" + ((Song)lista.elementAt(i)).getId() + "' value='" + ((Song)lista.elementAt(i)).getTitle() + "'";
if(((Song)lista.elementAt(i)).getSelected())
a = a + " checked>";
else
a = a + ">";
a = a + ((Song)lista.elementAt(i)).getTitle();
htmltable.addCell(a);
htmltable.addCell(((Song)lista.elementAt(i)).getDuration());
htmltable.addCell(((Song)lista.elementAt(i)).getCategory());
htmltable.addCell(((Song)lista.elementAt(i)).getAlbumTrack());
htmltable.addCell("<A href='" + ((Song)lista.elementAt(i)).getLink() + "'>Play</A>");
htmltable.endRow();
}
htmlpage.addText(htmltable.buildHtml());
htmlpage.addText("<BR><BR><BR><BR>");
htmlpage.addText("<INPUT type='submit' name='UserRequest' value='My Playlist'>");
htmlpage.addText("<BR><BR><BR><BR>");
htmlpage.addText("<TEXTAREA name='playList' rows='10' cols='80' readonly>");
for(int j = 0; j < lista.size(); j++)
if(((Song)lista.elementAt(j)).getSelected())
htmlpage.addText(((Song)lista.elementAt(j)).getTitle() + "\t" + ((Song)lista.elementAt(j)).getDuration() + "\t" + ((Song)lista.elementAt(j)).getCategory() + "\n" + ((Song)lista.elementAt(j)).getAlbumTrack() + "\n\n");
htmlpage.addText("</TEXTAREA>");
htmlpage.addText("</FORM>");
printwriter.print(htmlpage.buildHtml());
printwriter.flush();
printwriter.close();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -