首页 星云 工具 资源 星选 资讯 热门工具
:

PDF转图片 完全免费 小红书视频下载 无水印 抖音视频下载 无水印 数字星空

基于Websocket的在线聊天源码

后端 6.8MB 22 需要积分: 1
立即下载

资源介绍:

本人不擅长前端,jsp页面可能不适合所有分辨率,但是核心功能都在后台代码上,希望大家可以弄懂源码,写出性能更强的聊天功能!
package com.chat.controller; import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; import java.sql.Date; import java.util.ArrayList; import java.util.List; import net.sf.json.JSONArray; import org.hibernate.Query; import org.hibernate.Session; import org.hibernate.Transaction; import com.chat.common.MyHibernateSessionFactory; import com.chat.entity.ChatRecord; import com.chat.entity.Evaluate; import com.chat.entity.Relation; import com.chat.entity.User; public class UserDAOImpl implements UserDAO { //用户登录 @Override public List usersLogin(User u) { Transaction transaction = null; Session session = null; try { String hql = "from User where username=? and password=?"; session = MyHibernateSessionFactory.getSessionFactory().getCurrentSession(); transaction = session.beginTransaction();//开始事务 Query query = session.createQuery(hql); query.setParameter(0,u.getUsername()); query.setParameter(1, u.getPassword()); List list = query.list(); transaction.commit(); return list; } catch (Exception e) { e.printStackTrace(); return null; }finally{ MyHibernateSessionFactory.close(session); MyHibernateSessionFactory.close(transaction); } } public boolean changeLoginStatus(String uid,int status){ Transaction transaction = null; Session session = null; try { String hql = "update User u set u.status=? where u.id=?"; session = MyHibernateSessionFactory.getSessionFactory().getCurrentSession(); transaction = session.beginTransaction(); Query query = session.createQuery(hql); query.setParameter(0,status); query.setParameter(1, uid); int i = query.executeUpdate(); transaction.commit(); if(i==1){ return true; }else{ return false; } } catch (Exception e) { e.printStackTrace(); transaction.rollback(); return false; }finally{ MyHibernateSessionFactory.close(session); MyHibernateSessionFactory.close(transaction); } } @Override public boolean UsersRegister(User u) { Transaction transaction = null; Session session = null; try { session = MyHibernateSessionFactory.getSessionFactory().getCurrentSession(); transaction = session.beginTransaction();//开始事务 session.save(u); transaction.commit(); return true; } catch (Exception e) { e.printStackTrace(); transaction.rollback(); return false; }finally{ MyHibernateSessionFactory.close(session); MyHibernateSessionFactory.close(transaction); } } @Override public boolean makeImpress(String content, String id) { return false; } /* * (non-Javadoc) * 返回值:1代表添加成功,2代表已经是好友,0代表添加失败 * @see com.chat.controller.UserDAO#addFriend(java.lang.String, java.lang.String) */ @Override public int addFriend(String fid,String mid) { Transaction transaction = null; Session session = null; //首先判断是否是好友关系 int r = isFriendShip(mid, fid); if(r==1){ Relation relation = new Relation(); relation.setAdded_id(fid); relation.setAdder_id(mid); relation.setStatus(1); relation.setTime(new Date(System.currentTimeMillis())); try { session = MyHibernateSessionFactory.getSessionFactory().getCurrentSession(); transaction = session.beginTransaction();//开始事务 session.save(relation); transaction.commit(); return 1;//添加成功 } catch (Exception e) { e.printStackTrace(); transaction.rollback(); return 0;//添加失败 }finally{ MyHibernateSessionFactory.close(session); MyHibernateSessionFactory.close(transaction); } }else if(r==2){//以前是好友关系,中间删除过,表中还有记录,只要修改状态为1即可 try { String hql = "update Relation set status=1 where(adder_id=? and added_id=?) or (added_id=? and adder_id=?)"; session = MyHibernateSessionFactory.getSessionFactory().getCurrentSession(); transaction = session.beginTransaction();//开始事务 Query query = session.createQuery(hql); query.setParameter(0,fid); query.setParameter(1,mid); query.setParameter(2,fid); query.setParameter(3,mid); int i = query.executeUpdate(); transaction.commit(); return 1;//添加成功 } catch (Exception e) { e.printStackTrace(); transaction.rollback(); return 0;//添加失败 }finally{ MyHibernateSessionFactory.close(session); MyHibernateSessionFactory.close(transaction); } }else{ return 2;//已经是好友关系 } } //判断是否是好友关系 public int isFriendShip(String mid,String fid){ Transaction transaction = null; Session session = null; try { String hql = "from Relation where (adder_id=? and added_id=?) or (added_id=? and adder_id=?)"; session = MyHibernateSessionFactory.getSessionFactory().getCurrentSession(); transaction = session.beginTransaction();//开始事务 Query query = session.createQuery(hql); query.setParameter(0,mid); query.setParameter(1,fid); query.setParameter(2,mid); query.setParameter(3,fid); Relation relation = (Relation)query.uniqueResult(); transaction.commit(); if(relation==null){ return 1;//不是好友关系 }else if(relation.getStatus()==0){ return 2;//以前是好友关系,中间删除 }else{ return 3;//已经是好友关系 } } catch (Exception e) { e.printStackTrace(); return 0;//抛异常就显示时好友关系,后序添加操作就不会执行 }finally{ MyHibernateSessionFactory.close(session); MyHibernateSessionFactory.close(transaction); } } @Override public boolean deleteFriend(String mid,String fid,int status) { Transaction transaction = null; Session session = null; String hql= "update Relation set status=? where (adder_id=? and added_id=?) or (added_id=? and adder_id=?)"; try { session = MyHibernateSessionFactory.getSessionFactory().getCurrentSession(); transaction = session.beginTransaction(); Query query = session.createQuery(hql); query.setParameter(0, status); query.setParameter(1,mid); query.setParameter(2, fid); query.setParameter(3,mid); query.setParameter(4, fid); int i = query.executeUpdate(); transaction.commit(); if(i==1){ return true; }else{ return false; } } catch (Exception e) { e.printStackTrace(); return false; }finally{ MyHibernateSessionFactory.close(session); MyHibernateSessionFactory.close(transaction); } } //查找联系人 @Override public User searchFriend(String username) { Transaction transaction = null; Session session = null; try { String hql = "from User where username=?"; session = MyHibernateSessionFactory.getSessionFactory().getCurrentSession(); transaction = session.beginTransaction();//开始事务 Query query = session.createQuery(hql); query.setParameter(0,username); User user = (User)query.uniqueResult(); transaction.commit(); return user; } catch (Exception e) { e.printStackTrace(); transaction.rollback(); return null; }finally{ MyHibernateSessionFactory.close(session); MyHibernateSessionFactory.close(transaction); } } @Override public List selectAllOnLineFriend(String id,int status) { Session session = null; Transaction transaction = null; String sql = null; if(status==1){ //查询在线好友 sql = "select id,username,password,img,status from user where status=1 and id in(" +"select adder_id from relation where added_id="+id+" and status=1" +" union " +"select added_id from relation where adder_id="+id+" and status=1" + ")"; } if(status==0){ //查询所有好友(包括离线�

资源文件列表:

onLineChat.zip 大约有134个文件
  1. onLineChat/
  2. onLineChat/.classpath 2.93KB
  3. onLineChat/.myhibernatedata 353B
  4. onLineChat/.project 1.3KB
  5. onLineChat/.settings/
  6. onLineChat/.settings/.jsdtscope 522B
  7. onLineChat/.settings/com.genuitec.eclipse.core.prefs 104B
  8. onLineChat/.settings/com.genuitec.runtime.libraries.xml 357B
  9. onLineChat/.settings/org.eclipse.core.resources.prefs 102B
  10. onLineChat/.settings/org.eclipse.jdt.core.prefs 598B
  11. onLineChat/.settings/org.eclipse.wst.common.component 489B
  12. onLineChat/.settings/org.eclipse.wst.common.project.facet.core.xml 515B
  13. onLineChat/.settings/org.eclipse.wst.jsdt.ui.superType.container 49B
  14. onLineChat/.settings/org.eclipse.wst.jsdt.ui.superType.name 6B
  15. onLineChat/src/
  16. onLineChat/src/com/
  17. onLineChat/src/com/chat/
  18. onLineChat/src/com/chat/common/
  19. onLineChat/src/com/chat/common/HTMLFilter.java 2.11KB
  20. onLineChat/src/com/chat/common/JsonUtil.java 6.4KB
  21. onLineChat/src/com/chat/common/MyHibernateSessionFactory.java 1.13KB
  22. onLineChat/src/com/chat/controller/
  23. onLineChat/src/com/chat/controller/UserDAO.java 1.36KB
  24. onLineChat/src/com/chat/controller/UserDAOImpl.java 15.82KB
  25. onLineChat/src/com/chat/entity/
  26. onLineChat/src/com/chat/entity/chatrecord.hbm.xml 898B
  27. onLineChat/src/com/chat/entity/ChatRecord.java 1.11KB
  28. onLineChat/src/com/chat/entity/evaluate.hbm.xml 794B
  29. onLineChat/src/com/chat/entity/Evaluate.java 984B
  30. onLineChat/src/com/chat/entity/relation.hbm.xml 871B
  31. onLineChat/src/com/chat/entity/Relation.java 1.19KB
  32. onLineChat/src/com/chat/entity/user.hbm.xml 868B
  33. onLineChat/src/com/chat/entity/User.java 1.15KB
  34. onLineChat/src/com/chat/service/
  35. onLineChat/src/com/chat/service/DownloadAction.java 320B
  36. onLineChat/src/com/chat/service/SuperAction.java 1.13KB
  37. onLineChat/src/com/chat/service/UserAction.java 5.93KB
  38. onLineChat/src/com/chat/servlet/
  39. onLineChat/src/com/chat/servlet/DownloadChatRecords.java 2.12KB
  40. onLineChat/src/com/chat/servlet/MySessionListener.java 1.37KB
  41. onLineChat/src/hibernate.cfg.xml 1.27KB
  42. onLineChat/src/struts.xml 2.16KB
  43. onLineChat/src/websocket/
  44. onLineChat/src/websocket/chat/
  45. onLineChat/src/websocket/chat/ChatAnnotation.java 4.43KB
  46. onLineChat/src/websocket/chat/GetHttpSessionConfigurator.java 629B
  47. onLineChat/WebRoot/
  48. onLineChat/WebRoot/css/
  49. onLineChat/WebRoot/css/bootstrap.min.css 97.22KB
  50. onLineChat/WebRoot/css/index_style.css 7.31KB
  51. onLineChat/WebRoot/css/style.css 39.03KB
  52. onLineChat/WebRoot/images/
  53. onLineChat/WebRoot/images/bg.jpg 19.28KB
  54. onLineChat/WebRoot/images/city.jpg 159.6KB
  55. onLineChat/WebRoot/images/class.jpg 31.15KB
  56. onLineChat/WebRoot/images/contact-no.png 2.87KB
  57. onLineChat/WebRoot/images/contact.png 2.91KB
  58. onLineChat/WebRoot/images/default.png 75.44KB
  59. onLineChat/WebRoot/images/eclipse.jpg 13.54KB
  60. onLineChat/WebRoot/images/file.png 2.91KB
  61. onLineChat/WebRoot/images/head-img.png 11.24KB
  62. onLineChat/WebRoot/images/jay.png 171.25KB
  63. onLineChat/WebRoot/images/laughter.png 3.26KB
  64. onLineChat/WebRoot/images/man-no.png 3.09KB
  65. onLineChat/WebRoot/images/man.png 3.11KB
  66. onLineChat/WebRoot/images/ourjay.png 3.27KB
  67. onLineChat/WebRoot/images/screen.png 3.27KB
  68. onLineChat/WebRoot/images/search.png 3.07KB
  69. onLineChat/WebRoot/images/weixin-no.png 3.15KB
  70. onLineChat/WebRoot/images/weixin.png 3.11KB
  71. onLineChat/WebRoot/index.jsp 20.8KB
  72. onLineChat/WebRoot/js/
  73. onLineChat/WebRoot/js/jquery-1.12.0.min.js 95.08KB
  74. onLineChat/WebRoot/login.jsp 2.15KB
  75. onLineChat/WebRoot/META-INF/
  76. onLineChat/WebRoot/META-INF/MANIFEST.MF 39B
  77. onLineChat/WebRoot/records/
  78. onLineChat/WebRoot/register.jsp 2.13KB
  79. onLineChat/WebRoot/WEB-INF/
  80. onLineChat/WebRoot/WEB-INF/classes/
  81. onLineChat/WebRoot/WEB-INF/classes/com/
  82. onLineChat/WebRoot/WEB-INF/classes/com/chat/
  83. onLineChat/WebRoot/WEB-INF/classes/com/chat/common/
  84. onLineChat/WebRoot/WEB-INF/classes/com/chat/common/HTMLFilter.class 1.07KB
  85. onLineChat/WebRoot/WEB-INF/classes/com/chat/common/JsonUtil.class 5.33KB
  86. onLineChat/WebRoot/WEB-INF/classes/com/chat/common/MyHibernateSessionFactory.class 1.52KB
  87. onLineChat/WebRoot/WEB-INF/classes/com/chat/controller/
  88. onLineChat/WebRoot/WEB-INF/classes/com/chat/controller/UserDAO.class 982B
  89. onLineChat/WebRoot/WEB-INF/classes/com/chat/controller/UserDAOImpl.class 13.14KB
  90. onLineChat/WebRoot/WEB-INF/classes/com/chat/entity/
  91. onLineChat/WebRoot/WEB-INF/classes/com/chat/entity/ChatRecord.class 1.59KB
  92. onLineChat/WebRoot/WEB-INF/classes/com/chat/entity/chatrecord.hbm.xml 898B
  93. onLineChat/WebRoot/WEB-INF/classes/com/chat/entity/Evaluate.class 1.32KB
  94. onLineChat/WebRoot/WEB-INF/classes/com/chat/entity/evaluate.hbm.xml 794B
  95. onLineChat/WebRoot/WEB-INF/classes/com/chat/entity/Relation.class 1.99KB
  96. onLineChat/WebRoot/WEB-INF/classes/com/chat/entity/relation.hbm.xml 871B
  97. onLineChat/WebRoot/WEB-INF/classes/com/chat/entity/User.class 1.87KB
  98. onLineChat/WebRoot/WEB-INF/classes/com/chat/entity/user.hbm.xml 868B
  99. onLineChat/WebRoot/WEB-INF/classes/com/chat/service/
  100. onLineChat/WebRoot/WEB-INF/classes/com/chat/service/DownloadAction.class 578B
  101. onLineChat/WebRoot/WEB-INF/classes/com/chat/service/SuperAction.class 1.27KB
  102. onLineChat/WebRoot/WEB-INF/classes/com/chat/service/UserAction.class 6.35KB
  103. onLineChat/WebRoot/WEB-INF/classes/com/chat/servlet/
  104. onLineChat/WebRoot/WEB-INF/classes/com/chat/servlet/DownloadChatRecords.class 3.39KB
  105. onLineChat/WebRoot/WEB-INF/classes/com/chat/servlet/MySessionListener.class 1.86KB
  106. onLineChat/WebRoot/WEB-INF/classes/hibernate.cfg.xml 1.27KB
  107. onLineChat/WebRoot/WEB-INF/classes/struts.xml 2.16KB
  108. onLineChat/WebRoot/WEB-INF/classes/websocket/
  109. onLineChat/WebRoot/WEB-INF/classes/websocket/chat/
  110. onLineChat/WebRoot/WEB-INF/classes/websocket/chat/ChatAnnotation.class 5.09KB
  111. onLineChat/WebRoot/WEB-INF/classes/websocket/chat/GetHttpSessionConfigurator.class 1.26KB
  112. onLineChat/WebRoot/WEB-INF/lib/
  113. onLineChat/WebRoot/WEB-INF/lib/asm-5.1.jar 52.21KB
  114. onLineChat/WebRoot/WEB-INF/lib/asm-commons-5.1.jar 46.09KB
  115. onLineChat/WebRoot/WEB-INF/lib/asm-tree-5.1.jar 28.45KB
  116. onLineChat/WebRoot/WEB-INF/lib/commons-beanutils-1.7.0.jar 184.25KB
  117. onLineChat/WebRoot/WEB-INF/lib/commons-collections-3.2.1.jar 561.9KB
  118. onLineChat/WebRoot/WEB-INF/lib/commons-fileupload-1.3.2.jar 68.63KB
  119. onLineChat/WebRoot/WEB-INF/lib/commons-io-2.4.jar 180.8KB
  120. onLineChat/WebRoot/WEB-INF/lib/commons-lang-2.4.jar 255.67KB
  121. onLineChat/WebRoot/WEB-INF/lib/commons-lang3-3.4.jar 424.49KB
  122. onLineChat/WebRoot/WEB-INF/lib/commons-logging-1.1.3.jar 60.6KB
  123. onLineChat/WebRoot/WEB-INF/lib/ezmorph-1.0.3.jar 76KB
  124. onLineChat/WebRoot/WEB-INF/lib/freemarker-2.3.23.jar 1.29MB
  125. onLineChat/WebRoot/WEB-INF/lib/javassist-3.20.0-GA.jar 732.99KB
  126. onLineChat/WebRoot/WEB-INF/lib/json-lib-2.2.3-jdk15.jar 145.01KB
  127. onLineChat/WebRoot/WEB-INF/lib/log4j-api-2.7.jar 213.87KB
  128. onLineChat/WebRoot/WEB-INF/lib/mysql-connector-java-5.1.7-bin.jar 693.28KB
  129. onLineChat/WebRoot/WEB-INF/lib/ognl-3.1.12.jar 230.13KB
  130. onLineChat/WebRoot/WEB-INF/lib/struts2-core-2.5.10.1.jar 1.52MB
  131. onLineChat/WebRoot/WEB-INF/lib/struts2-json-plugin-2.5.10.1.jar 75.12KB
  132. onLineChat/WebRoot/WEB-INF/lib/tomcat-juli.jar 37.31KB
  133. onLineChat/WebRoot/WEB-INF/lib/websocket-api.jar 35.42KB
  134. onLineChat/WebRoot/WEB-INF/web.xml 1.28KB
0评论
提交 加载更多评论
其他资源 n9糗事百科
n9 的 糗事百科程序,部分代码copy自塞班版。不适用于其它meego,因为使用了nokia的组件
hibernate jar包+api
hibernate jar包+api
skyfire s60 覆盖文件 prefs
skyfire浏览器出现cannot provide service in your country at this time 使用方法 http://blog.csdn.net/abu406/archive/2010/04/26/5531725.aspx
生成带logo的二维码
这是可以生成二维码和带logo的二维码的一个demo,有需要的童鞋可以下载参考
【神经网络与深度学习】MNIST数据集介绍,并使用卷积神经网络训练手写数字识别模型——**附完整代码**和**训练好的模型文件**——直接用
使用卷积神经网络训练模型,具体介绍,参看我写的这篇文章:https://blog.csdn.net/weixin_45954454/article/details/114455209。
c++考试
c++考试c++考试c++考试c++考试c++考试c++考试c++考试
spring-framework-4.0.1.RELEASE-dist.zip
官方2014-1-28发布的spring-framework-4.0.1.RELEASE-dist.zip
PID控制器matlab仿真.zip
博文 :PID控制器——MATLAB/Simulink仿真以及性能比较与分析,介绍的最新升级版框架的simulink文件,本资源包含MATLAB2015a到2020a的11个版本的文件,应该说比较全了