首页 > 代码库 > 将歌词传入页面

将歌词传入页面

package sps.lrc.service;import java.io.File;import java.io.IOException;import java.util.ArrayList;import java.util.Collection;import java.util.LinkedHashMap;import java.util.List;import java.util.Map;import org.apache.commons.io.FileUtils;import org.apache.commons.lang3.StringUtils;import sps.lrc.content.Action;public class LrcService {    public List<Map<String, String>> searchFile(String contextPath) throws IOException {        StringBuffer sb = new StringBuffer();        sb.append(contextPath);        sb.append(Action.LRC);        sb.append(Action.BACKSLASH);        sb.append(Action.FILE);        String[] srr = { Action.LRC };        Collection<File> files = FileUtils.listFiles(new File(sb.toString()), srr, true);        List<Map<String, String>> contentList = new ArrayList<Map<String, String>>();        for (File file : files) {            Map<String, String> contentMap = new LinkedHashMap<String, String>();            List<String> contents = FileUtils.readLines(file);            for (String content : contents) {                contentMap.put(StringUtils.substringBetween(content, Action.LEFT_BRACKET, Action.RIGHT_BRACKET),                        StringUtils.substringAfter(content, Action.RIGHT_BRACKET));            }            contentList.add(contentMap);        }        return contentList;    }}

lrcAction

package sps.lrc.action;import java.io.IOException;import java.util.HashMap;import java.util.List;import java.util.Map;import sps.basic.action.BasicAction;import sps.basic.content.Content;import sps.lrc.content.Action;import sps.lrc.service.LrcService;public class LrcAction extends BasicAction {    private LrcService lrcService;    private Map<String, Object> jsonMap;    public LrcAction() {        jsonMap = new HashMap<String, Object>();    }    public String lrc() throws IOException {        // 查询所有目录lrc        List<Map<String, String>> content = lrcService.searchFile(getContextPath());        jsonMap.put(Action.LRCJSON, content);        return Content.JSON;    }    public void setLrcService(LrcService lrcService) {        this.lrcService = lrcService;    }    public void setJsonMap(Map<String, Object> jsonMap) {        this.jsonMap = jsonMap;    }    public Map<String, Object> getJsonMap() {        return jsonMap;    }}

 

jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %><%@ taglib prefix="s" uri="/struts-tags" %><html><head><title>Simple jsp page</title><script src="/nanoha_sps/js/jquery-2.1.1.js"></script><script type="text/javascript">    $.post(lrc/lrc.action,function(data){        var lrcs = data.jsonMap.lrcJson;        for(var i in lrcs){            for(var key in lrcs[i] ){                $(#id).after(<h5>+key+:&nbsp;+lrcs[i][key]+</h5>);            }        }    });</script></head><body>    <h3>welcome</h3>    <h4 id="id"></h4></body></html>

 /lrc/file/First Love.lrc

[00:03.20]First Love[00:05.85]演唱:宇多田光[00:08.49][00:21.63]最后(さいご)のキスは [00:28.20]タバコのflavorがした [00:32.08]苦(にが)くてせつない香(かお)り [00:39.29][00:43.18]明日(あした)の 今顷(いまごろ)には [00:48.39]あなたはどこにいるんだろう [00:55.41]谁(だれ)を想(おも)ってるんだろう [01:01.87][01:04.95]You are always gonna be my love [01:08.68]いつか谁(だれ)かとまた恋(こい)に落(お)ちても [01:15.63]I‘ll remember to love [01:18.37]You taught me how [01:20.92]You are always gonna be the one [01:24.77]今(いま)はまだ悲(かな)しいlove song [01:31.70]新(あたら)しい歌(うた) 歌(うた)えるまで [01:38.75][01:52.60]立(た)ち止(ど)まる时间(じかん)が [01:58.31]动(うご)き出(だ)そうとしてる [02:03.34]忘(わす)れたくないことばかり [02:13.76]明日(あした)の今顷(いまごろ)には [02:19.03]私(わたし)はきっと泣(な)いてる [02:26.02]あなたを想(おも)ってるんだろう [02:33.19][02:35.71]You will always be inside my heart [02:39.37]いつもあなただけの场所(ばしょ)があるから [02:46.34]I hope that I have a place in your heart too [02:51.32]Now and forever you are still the one [02:55.41]今(いま)はまだ悲(かな)しいlove song [03:02.41]新(あたら)しい歌(うた) 歌(うた)えるまで [03:08.98][03:12.96]You are always gonna be my love [03:16.73]いつか谁(だれ)かとまた恋(こい)に落(お)ちても [03:23.67]I‘ll remember to love [03:26.38]You taught me how [03:28.99]You are always gonna be the one [03:34.33]まだ悲(かな)しいlove song [03:41.65]Now and forever[03:44.53]

 

将歌词传入页面