Ajax lyrics (* errors may occur when the song address is Chinese)

Source: Internet
Author: User

Take the lyrics (errors may occur when the song address is Chinese)

Play. jsp
<% @ Page Language = "Java" Import = "Java. util. *" contenttype = "text/html; charset = gb2312" %>
<% @ Page import = "com. pp. DB. *" %>
<% @ Page import = "My. Bean. *" %>
<! Doctype HTML public "-// W3C // dtd html 4.01 transitional // en"
Http://www.w3.org/TR/html4/loose.dtd>
<HTML>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = GBK">
<Title> index </title>
</Head>
<Script language = "JavaScript" type = "text/JavaScript">

Function reverseselect ()
{

For (VAR I = 0; I <songlist. elements. length; I ++)
If (songlist. elements [I]. Checked = true)
Songlist. elements [I]. Checked = false;
Else
Songlist. elements [I]. Checked = true;
}
Function allselect ()
{
For (VAR I = 0; I <songlist. elements. length; I ++)
Songlist. elements [I]. Checked = true;
}
</SCRIPT>
<Body>
<H2 align = "center"> <em> <strong> <font color = "# ff0000"> online music playback demonstration </font> </strong> </em> </H2>
<Form name = "songlist" method = "Post" Action = "process. jsp">
<Div id = "layer1" style = "position: absolute; width: 783px; Height: 154px; Z-index: 1; left:-5px; top: 141px;">
<Table width = "780" border = "0" cellspacing = "0" cellpadding = "5">
<%
Dboperate DBO = new dboperate ();
DBO. setlength (10 );
String hql = "from music order by orders ";
List mylist = DBO. findsqlhibernate (hql, 1 );
Int n = mylist. Size ();
For (INT I = 0; I <mylist. Size (); I ++)
{
Music = (music) mylist. Get (I );

%>
<Tr>
<TD width = "714"> <ul> <li> <% = new string (music. getname (). getbytes ("iso-8859-1"), "gb2312") %> </LI> </ul> </TD>
<TD width = "25"> <input type = "checkbox" name = "name <% = I %>" value = "<% = music. GETID () %> "> </TD>
</Tr>
<%
}
%>
</Table>
</Div>
<Input type = "button" name = "all" value = "select all" onclick = "allselect ()">
<Input type = "button" name = "reverse" value = "invert" onclick = "reverseselect ()">
<Input type = "reset" name = "reset" value = "reset">
<Input type = "Submit" name = "Submit" value = "broadcast">
<Input type = "hidden" name = "size" value = "<% = n %>">
</Form>

 

</Body>
</Html>

 

Process. jsp
<% @ Page Language = "Java" Import = "Java. util. *" contenttype = "text/html; charset = gb2312" %>
<% @ Page import = "com. pp. DB. *" %>
<% @ Page import = "My. Bean. *" %>
<% @ Page import = "com. jetsum. util. *" %>
<%
String Path = request. getcontextpath ();
String basepath = request. getscheme () + ": //" + request. getservername () + ":" + request. getserverport () + path + "/";
%>

<! Doctype HTML public "-// W3C // dtd html 4.01 transitional // en">
<HTML>
<Head>
<Base href = "<% = basepath %>">

<Title> my JSP 'process. jsp 'starting page </title>

<SCRIPT type = "text/JavaScript" src = "net. js"> </SCRIPT>
<Style type = "text/CSS">
Body, TD, Th {
Font-size: 12px;
}
. A1 {background-color: #99 ffcc ;}
. A2 {background-color: # ffffff ;}
A: visited {color: #000000; text-Decoration: none; font-size: 9pt ;}
A: link {text-Decoration: none; color: #000000; font-size: 9pt ;}
A: hover {text-Decoration: underline; font-size: 9pt; color: # ff0000 ;}
# Showlist {display: none1; Border: 1px solid #99 CCFF; position: absolute; float: Left; top: 21px; Z-index: 20; left: 0px; width: 214px; filter: alpha (opacity = 0 );}
# Playlist {Height: 272px; overflow-Y: Scroll ;}
# Manage {position: absolute; float: Left; top: 21px; Z-index: 20; left: 223px; filter: alpha (opacity = 0 );}
/* A: visited {font-size: 9pt; color: #996600 ;}*/
</Style>
</Head>

<Body onload = "playmusic ()">
<%
Dboperate DBO = new dboperate ();
Music = new music ();
Int size = 0;

String SID = "";
String Strid = "";
If (request. getparameter ("size ")! = NULL)
{
Size = pubfunc. parseint (request. getparameter ("size "));
}
For (INT I = 0; I <size; I ++)
{

If (request. getparameter ("name" + I )! = NULL)
{
// System. Out. println ("select me, I want to play !!! ");
String id = request. getparameter ("name" + I );
SID = ID + ",";
Strid + = Sid;
}
}
System. Out. println ("Strid:" + Strid );
If (Strid. Trim (). Equals ("") | Strid. Trim () = "")
{
System. Out. println ("Don't play shit ");
}
Else
{
String hql = "from music where ID in (" + Strid. substring (0, Strid. Length ()-1) + ")";

List mylist = DBO. findsqlhibernate (hql, 1 );


%>

<! -- Start player -->
 

<Script language = "JavaScript" for = "mediaplayerobject" event = "playstatechange (newstate)">
Switch (newstate)
{
Case 1:
// Alert ("");
Break;
Case 2:
// Alert ("paused ");
Break;
Case 3:
// Alert ("playing ");
Break;
Case 8:
// Alert ("STOPPED ");
SetTimeout ("playmusic ();", 1000); break;
Default:
// Alert (newstate. tostring ());
Break;
}

</SCRIPT>
<Script language = "JavaScript">
Function playmusic ()
{
VaR player = Document. getelementbyid ("mediaplayerobject ");
VaR Index = playlistselect. selectedindex + 1;
If (index> playlistselect. Options. Length-1)
{
Index = 0;
}
Playlistselect. selectedindex = index;
Player. url = playlistselect. Options [Index]. value;
// Alert (player. url );
Player. Controls. Play ();
Filllyric (playlistselect, lyric );
}

Function playlast () // previous Qu
{
VaR player = Document. getelementbyid ("mediaplayerobject ");
VaR Index = playlistselect. selectedindex-1;
If (index <0)
{
Index = playlistselect. Options. Length-1;
}
Playlistselect. selectedindex = index;
Player. url = playlistselect. Options [Index]. value;
// Alert (player. url );
Player. Controls. Play ();
Filllyric (playlistselect, lyric );
}
Function filllyric (oelem, otarget ){
// Alert ("strat Ajax ");
VaR strvalue = oelem. Options [oelem. selectedindex]. value;
Alert (strvalue );
VaR url = 'getlyric. jsp ';
VaR strparams = 'q = '+ strvalue +
"& E =" + otarget. Name;
VaR loader1 = new
Net. contentloader (URL, filldropdown, null,
"Post", strparams );
}
Function filldropdown (){
// Alert ("back ");
VaR xmldoc = this.req.responsexml.doc umentelement;
// Alert (this. Req. responsetext); // check the returned value
// Alert (xmldoc );
VaR xsel = xmldoc. getelementsbytagname ("selectelement") [0];
// Alert (xsel );
VaR strfname = xsel. childnodes [0]. firstchild. nodevalue;
VaR strename = xsel. childnodes [1]. firstchild. nodevalue;
// Alert ("strfname" + strfname );
// Alert ("strename" + strename );
VaR strtext = xsel. childnodes [1]. firstchild. nodevalue;
Document. getelementbyid (strfname). value = strename;
}
</SCRIPT>
</Head>
<Body onload = "playmusic ()">
<Object ID = "mediaplayerobject" classid = "CLSID: 6bf52a52-394a-11d3-b153-00c04f79faa6" style = "width: 300px; Height: 63 PX;">
<Param name = "displaybackcolor" value = "0 xffffff">
<Param name = "displayforecolor" value = "16777215">
<Param name = "rate" value = "1">
<Param name = "balance" value = "0">
<Param name = "currentposition" value = "0">
<Param name = "defaultframe" value>
<Param name = "playcount" value = "1">
<Param name = "autostart" value = "-1">
<Param name = "currentmarker" value = "0">
<Param name = "invokeurls" value = "-1">
<Param name = "baseurl">
<Param name = "volume" value = "75">
<Param name = "mute" value = "0">
<Param name = "uimode" value = "full">
<Param name = "stretchtofit" value = "-1">
<Param name = "windowlessvideo" value = "0">
<Param name = "enabled" value = "-1">
<Param name = "enablecontextmenu" value = "-1">
<Param name = "fullscreen" value = "0">
<Param name = "samistyle">
<Param name = "samilang">
<Param name = "samifilename">
<Param name = "captioningid">
<Param name = "enableerrordialogs" value = "0">
</Object>

<Br>
--- Caster list ---
<Br>
<Select multiple = "multiple" id = "playlistselect">
<%
For (INT I = 0; I <mylist. Size (); I ++)
{
Music = (music) mylist. Get (I );
%>
<Option value = "<% = new string (music. geturl (). getbytes ("iso-8859-1"), "gb2312") %> "> <% = new string (music. getname (). getbytes ("iso-8859-1"), "gb2312") %> </option>
<%
}
}
%>

</SELECT>
<Br>
<Button onclick = "playlast ()"> last curve </button>
<Button onclick = "playmusic ()"> next song </button>

<! -- End of player -->
<! -- Start with the lyrics -->
<Textarea Cols = "20" rows = "10" name = "Lyric" id = "Lyric">
</Textarea>
<! -- The lyrics are over -->
</Body>
</Html>

Getlyric. jsp
<% @ Page Language = "Java" Import = "Java. util. *, java. SQL. *, java. Io. *" pageencoding = "gb2312" %>
<JSP: Directive. Page import = "com. pp. DB. dboperate, my. Bean. *"/>
<%
String Path = request. getcontextpath ();
String basepath = request. getscheme () + ": //" + request. getservername () + ":" + request. getserverport () + path + "/";
%>

<! Doctype HTML public "-// W3C // dtd html 4.01 transitional // en">
<HTML>
<Head>
<Base href = "<% = basepath %>">
<Title> my JSP 'doublecomboxml. jsp 'starting page </title>
<Meta http-equiv = "Pragma" content = "no-Cache">
<Meta http-equiv = "cache-control" content = "no-Cache">
<Meta http-equiv = "expires" content = "0">
<Meta http-equiv = "keywords" content = "keyword1, keyword2, keyword3">
<Meta http-equiv = "Description" content = "this is my page">
<! --
<LINK rel = "stylesheet" type = "text/CSS" href = "styles.css">
-->

</Head>

<Body>
<%
Request. setcharacterencoding ("gb2312 ");
String strquery = new string (request. getparameter ("Q"). getbytes ("iso-8859-1"), "gb2312 ");
// String strquery = request. getparameter ("Q ");
String strelem = request. getparameter ("e ");
System. Out. println ("strquery" + strquery );
Dboperate DBO = new dboperate ();
String hqlmusic = "from music where url = '" + strquery + "'"; // you can find a song based on the song address. All URLs cannot be the same.
System. Out. println ("hqlmusic" + hqlmusic );
List listmusic = DBO. findsqlhibernate (hqlmusic, 1 );
Stringbuilder strxml = new stringbuilder ("<? XML version = '1. 0'?> ");
If (listmusic. Size ()> 0)
{
Music = (music) listmusic. Get (0 );
Strxml. append ("<selectchoice> ");
Strxml. append ("<selectelement> ");
Strxml. append ("<formname>" + strelem + "</formname> ");
Strxml. append ("<formelem>" + music. getlyric () + "</formelem> ");
Strxml. append ("</selectelement> ");
Strxml. append ("</selectchoice> ");
}
Response. setcontenttype ("text/XML ");
Printwriter out2 = response. getwriter ();
Out2.write (strxml. tostring ());
Out2.close ();
%>
</Body>
</Html>

Attachment: musichoustchinese garbled version .rar

Ajax Chinese problems
VaR strvalue = music. value; // path of the song
Alert (strvalue); // E:/music/Zhang jingxuan-yu tianyao
VaR url = 'getlyric. jsp ';
VaR strparams = 'q = '+ strvalue; // pass the value
// Send
VaR loader1 = new
Net. contentloader (URL, filldropdown, null,
"Post", strparams );

Getlyric. jsp
// Value
String strquery = new string (request. getparameter ("Q"). getbytes ("iso-8859-1"), "gb2312"); // garbled out

...

Ajax only supports UTF-8?

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.