音乐播放器web服务器

  • r7_492990
    了解作者
  • 1007KB
    文件大小
  • rar
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-03-31 08:46
    上传日期
此代码主要用于web服务器端,服务器功能主要有验证登陆者的登陆姓名、登陆密码是否正确,只有有权限授予的管理员才能进入服务器进行具体的操作。进入服务器后,为了给管理员方便的操作体验,管理员通过网页便可以实现查看、修改、增加、删除音乐信息,再点击确定后这些信息会全部上传至服务器,从而避免了管理用通过sql语句进行数据库操作的麻烦过程。根据数据库内的信息量大小,在管理员浏览信息时可以选择通过“滚轮”在一个页面内浏览所有的信息,也可以进行在信息量巨大的时候进行分也查看,此外管理员在查看信息的时候可以根据需求在页面内直接输入mp3文件名称实现直接搜索功能从而迅速进行信息定位。
ServerExample.rar
内容介绍
package controller; import java.io.File; import java.io.IOException; import java.io.PrintWriter; import java.util.List; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.jspsmart.upload.SmartFile; import com.jspsmart.upload.SmartUpload; import com.jspsmart.upload.SmartUploadException; import po.UploadMsg; import vo.PageBean; import biz.MsgBiz; import bizimpl.MsgBizImpl; /** * Servlet implementation class BookController */ public class MsgController extends HttpServlet { private static final long serialVersionUID = 1L; /** * @see HttpServlet#HttpServlet() */ public MsgController() { super(); // TODO Auto-generated constructor stub } /** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse * response) */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub doPost(request, response); } /** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse * response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // 设置字符集 request.setCharacterEncoding("utf-8"); response.setCharacterEncoding("utf-8"); response.setContentType("text/html;charset=utf-8"); PrintWriter out = response.getWriter(); String option = request.getParameter("option"); // 查询所有 if (option.equals("getall")) { MsgBiz msgBiz = new MsgBizImpl(); List<UploadMsg> UpMsgs = msgBiz.getAllMsgs(); request.setAttribute("UpMsgs", UpMsgs); // 请求转发 request.getRequestDispatcher("msgshow.jsp").forward(request, response); } // 添加图书 if (option.equals("add")) { String realLrcFileName = null; String realMusicFileName = null; String realPhoto1FileName = null; String realPhoto2FileName = null; String realPhoto3FileName = null; String musicFileName = null; String lrcFileName = null; String photo1FileName = null; String photo2FileName = null; String photo3FileName = null; // 准备文件的存储目录 String musicPath = getServletContext().getRealPath("serverMusic"); String lrcPath = getServletContext().getRealPath("serverLrc"); String photoPath = getServletContext().getRealPath("serverPhoto"); File musicFilePath = new File(musicPath); File lrcFilePath = new File(lrcPath); File photoFilePath = new File(photoPath); if (!musicFilePath.exists()) { musicFilePath.mkdir(); } if (!lrcFilePath.exists()) { lrcFilePath.mkdir(); } if (!photoFilePath.exists()) { photoFilePath.mkdir(); } // 实例化上传组件 SmartUpload su = new SmartUpload("utf-8"); // 初始化组件 su.initialize(getServletConfig(), request, response); // 上传 try { su.upload(); // 提取上传文件 SmartFile musicFile = su.getFiles().getFile(0); SmartFile lrcFile = su.getFiles().getFile(1); SmartFile photo1File = su.getFiles().getFile(2); SmartFile photo2File = su.getFiles().getFile(3); SmartFile photo3File = su.getFiles().getFile(4); // 准备另存的文件名 musicFileName = System.currentTimeMillis() + "." + musicFile.getFileExt(); lrcFileName = System.currentTimeMillis() + "." + lrcFile.getFileExt(); photo1FileName = System.currentTimeMillis() + "_a" + "." + photo1File.getFileExt(); photo2FileName = System.currentTimeMillis() + "_b" + "." + photo2File.getFileExt(); photo3FileName = System.currentTimeMillis() + "_c" + "." + photo3File.getFileExt(); // 提取即将存入数据库内对应音乐的文件名 realMusicFileName = musicFile.getFileName(); realLrcFileName = lrcFile.getFileName(); realPhoto1FileName = photo1File.getFileName(); realPhoto2FileName = photo2File.getFileName(); realPhoto3FileName = photo3File.getFileName(); // 另存文件到指定目录 musicFile.saveAs(musicPath + "/" + musicFileName); lrcFile.saveAs(lrcPath + "/" + lrcFileName); photo1File.saveAs(photoPath + "/" + photo1FileName); photo2File.saveAs(photoPath + "/" + photo2FileName); photo3File.saveAs(photoPath + "/" + photo3FileName); // 提示用户 } catch (SmartUploadException e) { // TODO Auto-generated catch block out.println("<script>alert('文件传输失败!');history.back();</script>"); } // 提取音乐名与歌手名10.0.2.2:8080/ServerExample/serverMusic/ String singerName = su.getRequest().getParameter("singername"); String urlStr_mp3 = "http://192.168.158.1:8080/ServerExample/serverMusic/" + musicFileName; String urlStr_lrc = "http://192.168.158.1:8080/ServerExample/serverLrc/" + lrcFileName; String urlStr_photo1 = "http://192.168.158.1:8080/ServerExample/serverPhoto/" + photo1FileName; String urlStr_photo2 = "http://192.168.158.1:8080/ServerExample/serverPhoto/" + photo2FileName; String urlStr_photo3 = "http://192.168.158.1:8080/ServerExample/serverPhoto/" + photo3FileName; UploadMsg upMsg = new UploadMsg(); upMsg.setLrcName(realLrcFileName); upMsg.setMusicName(realMusicFileName); upMsg.setPhotoName1(realPhoto1FileName); upMsg.setPhotoName2(realPhoto2FileName); upMsg.setPhotoName3(realPhoto3FileName); upMsg.setSingerName(singerName); upMsg.setUrlStr_lrc(urlStr_lrc); upMsg.setUrlStr_mp3(urlStr_mp3); upMsg.setUrlStr_photo1(urlStr_photo1); upMsg.setUrlStr_photo2(urlStr_photo2); upMsg.setUrlStr_photo3(urlStr_photo3); // 调用biz完成添加 MsgBiz msgBiz = new MsgBizImpl(); boolean flag = msgBiz.addMusic(upMsg); if (flag) { out.println("<script>alert('添加成功!');location.href='index.jsp';</script>"); } else { out.println("<script>alert('添加失败!');history.back();</script>"); } } // 删除图书 if (option.equals("delete")) { int uid = Integer.parseInt(request.getParameter("uid")); MsgBiz msgBiz = new MsgBizImpl(); boolean flag = msgBiz.removeOneUploadMsg(uid); if (flag) { out.println("<script>alert('删除成功!');location.href='index.jsp';</script>"); } else { out.println("<script>alert('删除失败!');location.href='index.jsp';</script>"); } } // 获取单本图书 if (option.equals("getone")) { int uid = Integer.parseInt(request.getParameter("uid")); MsgBiz msgBiz = new MsgBizImpl(); UploadMsg UpMsg = msgBiz.getOneUpMsg(uid); request.setAttribute("UpMsg", UpMsg); request.getRequestDispatcher("msgup.jsp") .forward(request, response); } if (option.equals("search")) { String musicName = request.getParameter("musicname"); MsgBiz msgBiz = new MsgBizImpl(); List<UploadMsg> UpMsg1 = msgBiz.getOneUpMsgByName(musicName); request.setAttribute("UpMsgs1", UpMsg1); request.getRequestDispatcher("searchmsg.jsp").forward(request, response); } // 更新图书 if (option.equals("update")) { // 提取表单元素 int uid = Integer.parseInt(request.getParameter("uid")); String realLrcFileName = null; String realMusicFileName = null; String realPhoto1FileName = null; String realPhoto2FileName = null; String realPhoto3FileName = null; String musicFileName = null; String lrcFileName = null; String photo1FileName = null; String photo2FileName = null; String photo3FileName = null; // 准备文件的存储目录 String musicPath = getServletContext().getRealPath("serverMusic"); String lrcPath = getServletContext().getRealPath("serverLrc"); String photoPath = getServletContext().ge
评论
    相关推荐