ajax取歌词(*歌曲地址是中文的会出错)

 取歌词(歌曲地址是中文的会出错)

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">在线音乐播放演示</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=(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=" 全 选 " onClick="AllSelect()">
      <input type="button" name="Reverse" value=" 反 选 " onClick="reverseSelect()">
      <input type="reset" name="Reset" value=" 重 置 ">
      <input type="submit" name="Submit" value=" 播 放 ">
      <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:#99FFCC;}
.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 #99CCFF;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 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("选了我,我要播放了!!!");
           String id=request.getParameter("name"+i);
             sid=id+",";
             strid+=sid;
          }
        }
            System.out.println("strid:"+strid);
        if(strid.trim().equals("")||strid.trim()=="")
        {
         System.out.println("狗屁都不用播放");
        }
        else
        {
          String hql="from Music where id in("+strid.substring(0,strid.length()-1)+")";
        
          List mylist= dbo.findSQLHibernate(hql,1);
  
     
     %>


 <!--播放器 开始-->
 

<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()   // 上一曲
 {     
 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.documentElement;
        //alert(this.req.responseText);       //检查一下返回值
     //  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="0xffffff">
                        <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>
                ---连播列表---
                <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()">上一曲</button>
 <button onclick="PlayMusic()">下一曲</button> 

 <!--播放器 结束-->
    <!--歌词 开始-->
  <textarea cols="20" rows="10" name="lyric" id="lyric">
  </textarea>
   <!--歌词 结束-->
  </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+"'";   //是按照歌曲的地址来找歌,所有url不能相同
  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 = (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>

附件: musichoust中文乱码版.rar

ajax中文问题
  var strValue = music.value;    //歌曲的路径
        alert(strValue);          //    E:/music/张敬轩-分手前的雨天.mp3
        var url = 'getLyric.jsp';
        var strParams = 'q=' + strValue;  //传值
        //发送 
      var loader1 = new
        net.ContentLoader(url,FillDropDown,null,
                    "POST",strParams);

getLyric.jsp
//取值
String strQuery  =new String(request.getParameter("q").getBytes("iso-8859-1"),"GB2312");//出乱码

了...

AJAX只支持UTF-8?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值