package com.action;
import java.io.*;
import java.util.List;
import java.util.StringTokenizer;
import org.apache.struts.action.*;
import com.dao.SongDAO;
import com.model.SongForm;
import com.model.SongTypeForm;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import com.tools.MyPagination;
import com.tools.StringUtils;
public class SongAction extends Action {
private SongDAO songDAO = null;
MyPagination pagination = null;
StringUtils su=new StringUtils();
public SongAction() {
this.songDAO = new SongDAO();
}
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
String action = request.getParameter("action");
// System.out.println("\nscrip*********************action="+action);
if ("main".equals(action)) {
return main(mapping, form, request, response); // 前台首页
} else if ("songQuery".equals(action)) {
return songQuery(mapping, form, request, response); // 查询歌曲信息
} else if ("tryListen".equals(action)) {
return tryListen(mapping, form, request, response); // 查询试听歌曲信息
} else if ("continuePlay".equals(action)) {
return continuePlay(mapping, form, request, response); // 进行歌曲连播
} else if ("songSort".equals(action)) {
return songSort(mapping, form, request, response); // 歌曲排行(试听和下载)
} else if ("navigation".equals(action)) {
return navigation(mapping, form, request, response); // 查询导航栏信息
} else if ("search".equals(action)) {
return search(mapping, form, request, response); // 按条件查询歌曲
} else if ("download".equals(action)) {
return download(mapping, form, request, response); // 文件下载
} else if ("songType".equals(action)) {
return songType(mapping, form, request, response); // 查询歌曲类别
} else if ("adm_search".equals(action)) {
return adm_search(mapping, form, request, response); // 后台查询歌曲信息
} else if ("add".equals(action)){
return adm_add(mapping,form,request,response); //添加歌曲信息
} else if ("checkMusic".equals(action)){
return checkMusic(mapping,form,request,response); //检测歌曲是否已经添加
} else if ("del".equals(action)) {
return del(mapping, form, request, response); // 删除歌曲信息
} else {
request.setAttribute("error", "操作失败!");
return mapping.findForward("error");
}
}
// 主页中的新歌速递
public ActionForward main(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
List<SongTypeForm> list = songDAO.queryType(); // 获取歌曲类别
int songTypeId = 0;
String[][] typeName = new String[6][2];
for (int i = 0; i < list.size(); i++) {
songTypeId = list.get(i).getId();
typeName[i][0] = String.valueOf(list.get(i).getId());
typeName[i][1] = list.get(i).getTypeName();
request.setAttribute("newSongList" + i, songDAO
.query("WHERE songType=" + songTypeId
+ " ORDER BY upTime DESC",5)); // 获取最新上传的5首歌曲
}
request.setAttribute("typeArray", typeName); // 保存类别信息数组到Request中
return mapping.findForward("main");
}
// 歌曲排行
public ActionForward songSort(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
String type = request.getParameter("sortType"); //获取表示是试听排行还是下载排行的参数值
if ("hits".equals(type)) {
request.setAttribute("sortType", songDAO
.query(" ORDER BY hits DESC",8)); // 获取试听排行信息
} else if ("download".equals(type)) {
request.setAttribute("sortType", songDAO
.query(" ORDER BY download DESC",8)); // 获取下载排行信息
}
request.setAttribute("sortTypeName", type);
RequestDispatcher requestDispatcher = request
.getRequestDispatcher("/songSort.jsp"); //将页面重定向到歌曲排行榜页面
try {
requestDispatcher.include(request, response); // 此处不能使用forward()方法
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
// 获取导航栏信息
public ActionForward navigation(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
request.setAttribute("navigation", songDAO.queryType()); // 获取歌曲类别信息
RequestDispatcher requestDispatcher = request
.getRequestDispatcher("/navigation.jsp");
try {
requestDispatcher.include(request, response); // 此处不能使用forward()方法
} catch (ServletException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
// 查找歌曲列表
public ActionForward songQuery(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
String strPage = (String) request.getParameter("Page");
int songType = Integer.parseInt(request.getParameter("songType_more")); // 要查看的歌曲类别
int Page = 1;
List<SongForm> list = null;
if (strPage == null) {
pagination = new MyPagination();
list = songDAO.query(" WHERE s.songType=" + songType
+ " ORDER BY s.upTime DESC"); // 获取歌曲信息
int pagesize = 2; // 指定每页显示的记录数
list = pagination.getInitPage(list, Page, pagesize); // 初始化分页信息
request.getSession().setAttribute("pagination", pagination);
} else {
pagination = (MyPagination) request.getSession().getAttribute(
"pagination");
Page = pagination.getPage(strPage);
list = pagination.getAppointPage(Page); // 获取指定页数据
}
if (list.size() > 0) {
request.setAttribute("typeName", list.get(0).getSongType()); // 获取歌曲类别
request.setAttribute("typeID", list.get(0).getSongTypeId()); // 获取歌曲类别ID
}
request.setAttribute("songList", list); // 保存当前页的歌曲信息
request.setAttribute("Page", Page); // 保存的当前页码
return mapping.findForward("songQuery");
}
// 按条件查询歌曲
public ActionForward search(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
String strPage = (String) request.getParameter("Page");
int songType = Integer.parseInt(request.getParameter("songType_more")); // 要查看的歌曲类别
String fieldName = request.getParameter("fieldName"); // 获取查询依据
String key = request.getParameter("key"); // 获取查询关键字
System.out.println("获取的查询条件:" + key + fieldName + songType);
String condition = "";
String fieldName_cn = "";
if (songType > 0 && fieldName != null) {
condition = " WHERE s.songType=" + songType + " AND s." + fieldName
+ " LIKE '%" + key + "%' ORDER BY s.upTime DESC";
} else if (songType > 0) {
condition = " WHERE s.songType=" + songType
+ " ORDER BY s.upTime DESC";
} else if (fieldName != null) {
condition = " WHERE s." + fieldName + " LIKE '%" + key
+ "%' ORDER BY s.upTime DESC";
} else {
condition = " ORDER BY s.upTime DESC";
}
if ("songName".equals(fieldName)) {
fieldName_cn = "歌曲名";
} else if ("specialName".equals(fieldName)) {
fieldName_cn = "专辑";
} else if ("singer".equals(fieldName)) {
fieldName_cn = "歌手";
}
int Page = 1;
List<SongForm> list = null;
if (strPage == null) {
pagination = new MyPagination();
list = songDAO.query(condition); // 获取歌曲信息
int pagesize = 2; // 指定每页显示的记录数
list = pagination.getInitPage(list, Page, pagesize); // 初始化分页信息
request.getSession().setAttribute("pagination", pagination);
} else {
pagination = (MyPagination) request.getSession().getAttribute(
"pagination");
Page = pagination.getPage(strPage);
list = pagination.getAppointPage(Page); // 获取指定页数据
}
if (list.size() > 0) {
if (songType > 0) {
// request.set
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
B-在线音乐模块.zip (82个子文件)
在线音乐模块.DOC 3.37MB
源程序
top.jsp 153B
music.baiduyun.uploading.cfg 2KB
WEB-INF
validator-rules.xml 13KB
struts-bean.tld 9KB
classes
com
action
ManagerAction.class 2KB
SongAction.class 14KB
SelfRequestProcessor.class 925B
yourcompany
struts
ApplicationResources.properties 94B
model
SongForm.class 4KB
ManagerForm.class 967B
SongTypeForm.class 784B
dao
SongDAO.class 7KB
ManagerDAO.class 2KB
tools
ConnDB.class 4KB
StringUtils.class 968B
MyPagination.class 3KB
connDB.properties 428B
lib
struts-html.tld 72KB
.struts-config.mex 5KB
struts-config.xml 2KB
web.xml 1KB
struts-logic.tld 14KB
lib.baiduyun.uploading.cfg 2KB
struts-tiles.tld 8KB
struts-nested.tld 70KB
delok.jsp 486B
logout.jsp 380B
upFile.jsp 1KB
login_ok.jsp 351B
CSS
style.css 3KB
error.jsp 762B
index.jsp 125B
adm_main.jsp 4KB
adm_copyright.jsp 481B
newSongList.jsp 3KB
search.jsp 756B
src
com
action
SongAction.java 19KB
SelfRequestProcessor.java 527B
ManagerAction.java 2KB
yourcompany
struts
ApplicationResources.properties 94B
model
SongForm.java 3KB
ManagerForm.java 571B
SongTypeForm.java 441B
dao
SongDAO.java 7KB
ManagerDAO.java 1KB
tools
StringUtils.java 754B
ConnDB.java 4KB
MyPagination.java 2KB
connDB.properties 428B
images
main_title.jpg 16KB
title_ico.gif 46B
navigateion_oa.gif 1KB
tryListen.bmp 2KB
btn_bg.gif 501B
upFile_bg.gif 6KB
newWindow_title.gif 808B
tryListen.gif 241B
top_bg.jpg 13KB
ad.jpg 18KB
navigation_bg.gif 291B
right.jsp 2KB
searchResult.jsp 5KB
addok.jsp 442B
upLrcFile_deal.jsp 941B
navigation.jsp 939B
upFile_deal.jsp 1KB
music
adm_search.jsp 1001B
main.jsp 4KB
songList.jsp 5KB
continuePlay.jsp 8KB
checkMusic.jsp 741B
copyright.jsp 468B
upLrcFile.jsp 1KB
login.jsp 2KB
tryListen.jsp 7KB
adm_add.jsp 4KB
Database
db_onLineMusic_Log.LDF 1024KB
db_onLineMusic_Data.MDF 1024KB
songSort.jsp 2KB
download.jsp 770B
程序使用说明书.doc 641KB
共 82 条
- 1
资源评论
- lls152014-11-22不错!很适合初学者使用
- kk88232015-04-02资源很不错,很详细,有帮助的。
Mr_Dink_Null
- 粉丝: 0
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 多机调度问题贪心算法:理论探索与实践应用.zip
- 探索tecreate:软件开发的未来之星.zip
- 打标机项目C#源码连接扫码
- 基于SSM的房屋租赁系统的设计与实现
- xyctf:从入门到精通的实用指南.zip
- mmqrcode1714153659780.png
- Screenshot_2024-04-27-06-08-58-486_com.baidu.xin.aiqicha.jpg
- 基于Javaweb+Tomcat+MySQL的大学生公寓管理系统+sql文件.zip
- 实训作业基于javaweb的订单管理系统源码+数据库+实训报告.zip
- 多机调度问题贪心算法基于最小堆和贪心算法求解多机调度问题.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功