日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > java >内容正文

java

Javaweb网易云音乐

發(fā)布時間:2023/12/10 java 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Javaweb网易云音乐 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

來啦來啦,一個星期中最終要的時刻來了,基于Tomcat服務(wù)器上的網(wǎng)易云項目來了。小編這都幾天沒更新,是因為小編是一個在校的學(xué)生,目前在武漢一家Java培訓(xùn)機(jī)構(gòu)培訓(xùn),想來的可以找小編免費(fèi)介紹,聽說最近幾天報名有優(yōu)惠,python&Java都可以找小編了解,好了廣告打完了我們直接進(jìn)入主題吧!!!!!!!!!!!!!!!!

小編還是一樣給出項目的結(jié)構(gòu)圖,大家可以瞅一眼

小編也是一個學(xué)生,所以呢前端頁面是偷我們培訓(xùn)機(jī)構(gòu)的,感覺挺好的,其次呢?小編使用的技術(shù)是Java做后端,html+css做的前端,腳本則是JS,數(shù)據(jù)庫當(dāng)然是mysql,其他沒有了,小編寫的代碼有點多,可以給后臺代碼給各位看看,可能比較菜,里面也有點功能沒寫完,歡迎各位大佬指導(dǎo).

登錄后臺LongServlet.java?

package com.wxsc.controller;import com.wxsc.dao.*; import com.wxsc.pojo.US; import com.wxsc.pojo.User; import com.wxsc.pojo.song;import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import java.io.IOException; import java.util.List;/*** @author 張宗臣* @version 1.0* @date 2021/12/6 0006 10:07*/ @WebServlet("/login") public class LoginServlet extends HttpServlet {@Overrideprotected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {// 設(shè)置編碼req.setCharacterEncoding("utf-8");resp.setContentType("text/html;charset=utf-8");// 獲取請求參數(shù)String username = req.getParameter("username");String pwd = req.getParameter("password");// dao層userDao userDao = new UserDaoImpl();// 用戶User u = userDao.Login(username,pwd);USDao usDao = new USDaoLmpl();//用戶--歌曲SongDao songDao = new SongDaoLmpl();// 歌曲// 如果登陸成功,用戶的信息綁定到會話// 獲得當(dāng)前用戶的歌曲信息if (u!=null){HttpSession session = req.getSession();session.setAttribute("user",u);// 查詢用戶的歌曲// 先獲得當(dāng)前用戶的歌曲id集合List<Integer> ids = usDao.findByUid(u.getId());// 再根據(jù)id集合獲得歌曲集合List<song> songs = songDao.findBySidList(ids);System.out.println(songs);session.setAttribute("songs",songs);req.getRequestDispatcher("main.jsp").forward(req,resp);}else {resp.sendRedirect("login.html");}} }

?添加歌曲的后臺 AddSongServlet.java

package com.wxsc.controller;import com.wxsc.dao.SongDao; import com.wxsc.dao.SongDaoLmpl; import com.wxsc.pojo.song;import javax.servlet.ServletException; import javax.servlet.annotation.MultipartConfig; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.Part; import javax.sound.midi.Soundbank; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.sql.Timestamp; import java.util.Date;/*** @author 張宗臣* @version 1.0* @date 2021/12/5 0005 17:05* 上傳歌曲的Servlet*/ //識別上下文件的注解 @MultipartConfig @WebServlet("/addSong") public class AddSongServlet extends HttpServlet {@Overrideprotected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {//設(shè)置編碼req.setCharacterEncoding("utf-8");resp.setContentType("text/html;charset=utf-8");// 上傳文件,獲得文件上傳的信息[fileName-value location-value upLocadTime-value,size-value] 返回一個不完整的songsong s = uploadFile(req);// 獲得歌手 專輯,風(fēng)格String singer = req.getParameter("singer");s.setSinger(singer);String album = req.getParameter("album");s.setAlbum(album);String style = req.getParameter("style");s.setStyle(style);System.out.println(singer+album+style);// 訪問數(shù)據(jù)庫,添加到數(shù)據(jù)庫中SongDao songDao = new SongDaoLmpl();songDao.addSong(s);// 添加成功頁面req.getRequestDispatcher("index.jsp").forward(req,resp);}private song uploadFile(HttpServletRequest req) throws IOException, ServletException {// 獲得請求頭的封裝的Part對象----->封裝請求文件的信息// Content-Disposition :form-data;name = file ;filename="程辰 - 好像在愛你.mp3"Part part = req.getPart("file");// part本質(zhì)自己不能獲取文件名,但可以的到文件頭//可以通過 請求頭的信息,進(jìn)而獲取上傳文件的信息,進(jìn)而截取String message = part.getHeader("Content-Disposition");// subString(最后一個等號加上7 剛好是文件名,到文件的末尾的位置) 函數(shù)是取前不取后String fileName = message.substring(message.lastIndexOf("=")+7,message.length()-1);System.out.println(fileName);// 獲得輸入流InputStream in = part.getInputStream();// 構(gòu)建輸出流String location = "D:\\Wyy_Music"+ File.separator+fileName;FileOutputStream fos = new FileOutputStream(location);//IO操作byte[] b = new byte[1024];int len = 0;while ((len = in.read())!=-1){fos.write(b,0,len);}//關(guān)閉in.close();fos.close();// 上傳時間Timestamp uploadTime = new Timestamp(System.currentTimeMillis());File file = new File(location);long size = file.length();song s = new song();s.setSize(size);s.setUploadTime(uploadTime);s.setLocation(location);s.setName(fileName.substring(0,fileName.lastIndexOf(".")));return s;}}

刪除的后臺代碼 DeleteServlet.java

package com.wxsc.controller;import com.alibaba.fastjson.JSON; import com.wxsc.dao.SongDao; import com.wxsc.dao.SongDaoLmpl; import com.wxsc.dao.USDao; import com.wxsc.dao.USDaoLmpl; import com.wxsc.pojo.US; import com.wxsc.pojo.User; import com.wxsc.pojo.song;import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import java.io.IOException; import java.util.List;/*** @author 張宗臣* @version 1.0* @date 2021/12/7 0007 19:22*/ @WebServlet("/deleteSong") public class DeleteServlet extends HttpServlet {@Overrideprotected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {// 設(shè)置編碼req.setCharacterEncoding("utf-8");resp.setContentType("text/html;charset=utf-8");// 獲得請求參數(shù)int id = Integer.parseInt(req.getParameter("sid"));// daoSongDao songDao = new SongDaoLmpl();USDao usDao = new USDaoLmpl();boolean flag = songDao.deleteById(id);if (flag){HttpSession session = req.getSession();User u = (User) session.getAttribute("user");// 重新綁定會話里面的歌曲信息,因為歌曲發(fā)生了更新List<Integer> ids = usDao.findByUid(u.getId());// 根據(jù)歌曲id集合獲得歌曲對象集合List<song> songs = songDao.findBySidList(ids);session.setAttribute("songs",songs);// 轉(zhuǎn)發(fā)resp.getWriter().println(JSON.toJSONString(true));}else {resp.getWriter().println(JSON.toJSONString(false));}} }

還有的代碼小編就不意譯為ctrl c v了想要的可以聯(lián)系小編qq:3265857641或者微信Q3265857641小編第一時間給你解答,當(dāng)然小編也為你們準(zhǔn)備好了網(wǎng)盤鏈接,

鏈接:https://pan.baidu.com/s/1F7GdCAYANheYp5IoU9G9Pg?提取碼:ns4q

但是小編感覺可以加一下小編,不會還可以第一時間為你解答,或者你對Java十分熱愛亦或者你對自己的控制力不相信,可以詢問小編,小編可以給你安排免費(fèi)的VIP試聽課,不滿意不報名

總結(jié)

以上是生活随笔為你收集整理的Javaweb网易云音乐的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。