WebSocket获取的登录用户的信息

WebSocket怎么获取放在session里的登录用户的信息?求指教

7个回答

你上面提到的其实并不是乱码,而是urlencode编码之后的字符序列。你可以使用以下代码进行解码:

 String decodeStr = URLDecoder.decode(queryStr, "utf-8");

解码之后再做分析。

qq_31531483
名字都被占用了啊 非常谢谢你,已经完美解决了!
大约 4 年之前 回复

1.首先你要区分是HttpSession还是Websocket会话session。
2.HttpSession这里不讲,我想说的Websocket的会话session。你可以在websocket服务器端维护一个
Map map = new HashMap();
其中Session可以在每个Websocket通信的回调函数中作为参数传入,会话会帮你维护这整个session,会话期间整个session不会改变。UserInfo可以通过传入的Session为key操作
map获取。因为是全局的map,所以在访问的时候一定要注意互斥访问,记得加锁哦。

u011489205
ai2018 回复一米阳光三寸暖: 使用String name = URLDecoder.decode(queryStr, "utf-8");解码queryString()获取的字符串
大约 4 年之前 回复
u011489205
ai2018 回复一米阳光三寸暖: 看我下面推荐的方案
大约 4 年之前 回复
qq_31531483
名字都被占用了啊 可是我应该怎么在打开管道的时候把前台的用户信息传过来呢?打开的时候不是会触发onopen事件吗?然后我想把前台登录的用户传到onopen事件里作处理,我在建立握手连接的时候直接在路径后面加的“?”传值,去onopen方法参数的session里取,session.getQueryString,得到了一个字符串,如果用户名是英文可以,但是如果是中文就会是乱码,好像也不是乱码,就像是把用户名加密了一样,类似于这种:%C%E%T... 。不知道是什么的原因
大约 4 年之前 回复

在服务器类上加上一下注解

 @ServerEndpoint(value = "/websocket/signalmonitor/{nickname}")

start方法入参格式如下:

 @OnOpen
    public void start(@PathParam("nickname")String nickname, Session session) {
    }

前段调用参数如下:

 Chat.initialize = function() {
        if (window.location.protocol == 'http:') {
            Chat.connect('ws://' + window.location.host
                    + '/websocket/websocket/signalmonitor/tony');
        } else {
            Chat.connect('wss://' + window.location.host
                    + '/websocket/websocket/signalmonitor/tony');
        }
    };

基于路径的参数传递,服务器接受到的就是tony。

u011489205
ai2018 回复一米阳光三寸暖: 那得看你前台传递的参数是什么编码呀,有可能是ISO-8859-1呢或者gbk,视情况改变编解码参数
大约 4 年之前 回复
qq_31531483
名字都被占用了啊 这个我之前试过了,中文还是显示乱码
大约 4 年之前 回复

这个需要客户端服务器端配合,服务器端有用户信息,客户端去连接获取。用你使用的语言+web socket去google,就会有代码的。

"Map map = new HashMap();"

 Map<Session, UserInfo> connectmap = new HashMap<>();//session 是Websocket会话,UserInfo 是你自己的用户信息bean,当然也可以是map

Websocket里面通过注解以及方法也是可以获取到http协议的session的

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
websocket 聊天室,怎么实时显示在线的用户
有源码最好,各位大神。讲讲思路也可以,谢谢啦……我在登陆的时候,设置了session.setattribute,但是jsp页面获取的时候,只能显示之前的用户,后面登陆的就不会显示
如何知道spring websocket消息是否发送成功
spring boot: 1.3.3.RELEASE 现在服务端使用 SimpMessagingTemplate convertAndSendTouser() 推送消息给客户端,如何知道消息是否推送成功? 或者我想知道,如何获取所有用户的订阅信息?因为知道所有用户的订阅,就可以有针对的推送消息给指定用户。 假如客户端连上websocket后,客户端马上断网了,此时服务器往客户端推消息,为何没有报错?
websocket移动端无效但是电脑端正常
用websocket做了个聊天功能,在电脑端可以正常使用。但在手机端却不能使用。就是在手机端登陆的时候获取不到用户的id.
Websocket通过注解连不上service
用了好的办法就是死活打印不出来service里面的值,使用别的controller可以打印出来service里面的东西 package com.xinhaiwang.controller; import java.io.IOException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.HashMap; import java.util.Map; import java.util.concurrent.CopyOnWriteArraySet; import javax.servlet.http.HttpServletRequest; import javax.websocket.CloseReason; import javax.websocket.OnClose; import javax.websocket.OnError; import javax.websocket.OnMessage; import javax.websocket.OnOpen; import javax.websocket.Session; import javax.websocket.server.ServerEndpoint; import org.springframework.beans.factory.annotation.Autowired; import com.xinhaiwang.service.MklService; @ServerEndpoint("/echo") public class Websocket { @Autowired private MklService mklservice; /*private MklService mklservice=(MklService) ContextLoader.getCurrentWebApplicationContext().getBean("mklservice");*/ //concurrent包的线程安全Set,用来存放每个客户端对应的MyWebSocket对象。若要实现服务端与单一客户端通信的话,可以使用Map来存放,其中Key可以为用户标识 private static CopyOnWriteArraySet<Websocket> webSocketSet = new CopyOnWriteArraySet<Websocket>(); //与某个客户端的连接会话,需要通过它来给客户端发送数据 private Session session; @OnOpen public void onOpen(Session session) throws IOException { System.out.println("onOpen"); this.session = session; webSocketSet.add(this); //加入set中 System.out.println("有新连接加入!"); //以下代码省略... } @OnMessage public String onMessage(String message) throws Exception { System.out.println("onMessage"); System.out.println("验证连通性:"); /* DmzController dmz = new DmzController(); System.out.println(dmz.mkl()); mklservice.getCount();*/ //向前端传送消息 return "77777"; //以下代码省略... } /*@OnMessage(maxMessageSize=6) public void receiveMessage(String message) { System.out.println("receiveMessage"); System.out.println("来自客户端的消息:" + message); //以下代码省略... }*/ @OnError public void onError(Throwable t) { System.err.println("onError"); //以下代码省略... } @OnClose public void onClose(Session session, CloseReason reason) { System.err.println("onClose"); //以下代码省略... } public void sendMessage(String message) throws IOException{ //调用写好的方法向前端发起请求并一块传值 this.session.getBasicRemote().sendText(message); //this.session.getAsyncRemote().sendText(message); } /** * 获取数组 * @throws Exception */ public String getbean() throws Exception{ System.out.println("进入到自定义方法"); //判断时间 Map<String, Object>map = new HashMap<>(); SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式 String now = df.format(new Date()); String time = "2017-11-19 11:00:00"; System.out.println("获取当前系统时间"+now);// new Date()为获取当前系统时间 System.out.println("获取自定义时间"+time);//获取自定义时间 /*System.out.println("总条数"+service.getCount());*/ String sjh[] = new String[10]; map.put("data", sjh); //判断是否到抽奖时间 System.out.println("判断时间:"+!now.equals(time)); mklservice.getCount(); System.out.println("获取总条数"+mklservice.getCount()); /*if(!now.equals(time)){ //查到中奖的手机号做成数组(加个 判断数组.length是否等于十) for (int i = 0; i < 10; i++) { //生成随机数作为id boolean a = true; Integer x=(int)(Math.random()*100); while (a) { System.out.println("随机数:"+x); Integer id = mklservice.getCount(); System.out.println("总条数"+id); if(id<x){ a = true; }else{ a = false; Mkl mkl = mklservice.getbean(x); sjh[i]=mkl.getPhone(); mkl.setYuliu1("1"); } } } map.put("data", sjh); }*/ return ""; } }
关于WebSocket的问题 为什么浏览器关闭后会出一下异常
错误信息 ```java.net.SocketException: Software caused connection abort: recv failed at java.net.SocketInputStream.socketRead0(Native Method) at java.net.SocketInputStream.read(SocketInputStream.java:129) at java.net.SocketInputStream.read(SocketInputStream.java:90) at test.UserSocket.run(UserSocket.java:43) java.net.SocketException: Software caused connection abort: recv failed at java.net.SocketInputStream.socketRead0(Native Method) at java.net.SocketInputStream.read(SocketInputStream.java:129) at java.net.SocketInputStream.read(SocketInputStream.java:90) at test.UserSocket.run(UserSocket.java:43) ``` 这是一个WebScoket 的小测试。我开了3个浏览器测试正常后,关闭其中一个就会这个异常以下是我的代码麻烦各位大神给看看 ``` package test; import java.io.IOException; import java.net.ServerSocket; import java.net.Socket; import java.util.ArrayList; import java.util.List; import sun.applet.Main; public class ServerSocketTest { public static List<Socket> clientSocket = new ArrayList<Socket>(); public ServerSocketTest() throws IOException{ ServerSocket ss = new ServerSocket(30000); System.out.println("服务器启动等待客户端连接"); while(true){ Socket s =ss.accept();//等待客户端连接 clientSocket.add(s); System.out.println("客户端总人数"+clientSocket.size()); //为新用户启动线程 new UserSocket(s).start(); } } public static void main(String[] args) throws IOException { new ServerSocketTest(); } } ``` 下面是线程代码 ``` package test; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.net.Socket; import java.net.SocketException; import java.security.MessageDigest; import java.util.Iterator; import java.util.regex.Matcher; import java.util.regex.Pattern; import sun.misc.BASE64Encoder; public class UserSocket extends Thread{ private Socket socket; public UserSocket(Socket socke){ this.socket = socke; } @Override public void run() { try { InputStream is = socket.getInputStream();//获取用户输入流 OutputStream ops = socket.getOutputStream();//获取用户输出流 byte[] buff = new byte[1024];//字节 String red = ""; //用了存放客户端请求过来的内容(客户端信息) // 读取数据,此时建立与wabSocket的握手 int count = is.read(buff);//读取客户端请求内容的长度 if(count > 0){ //客户端请求数据转化字符串 red = new String(buff,0,count); //获取WebSocket的值 String seckey = getSecWebSocketKey(red); String response = "HTTP/1.1 101 Switching Protocols\r\nUpgrade: " + "websocket\r\nConnection: Upgrade\r\nSec-WebSocket-Accept: " + getSecWebSocketAccept(seckey) + "\r\n\r\n"; //推送向客户端 ops.write(response.getBytes("utf-8")); int hasRedad = 0; // 不断读取WebSocket发送过来的数据 System.out.println("while循环前,等待前端推送数据。。。。。。。。。。。。"); while((hasRedad = is.read(buff))>0){//判断循环读取 System.out.println("后台接收到值,进入While循环处理"); /* * 因为WebSocket发送过来的数据遁寻了一定的协议格式, 其中第3~6个字节是数据掩码, * 从第七个字节开始才是真正的有效数据。 因此程序使用第3~6个字节对后面的数据进行了处理 */ for (int i = 0; i < hasRedad - 6; i++) { buff[i + 6] = (byte) (buff[i % 4 + 2] ^ buff[i + 6]); } //获得从浏览器发送过来的数据 String pushMsg = new String(buff,6,hasRedad - 6, "utf-8");//第一个值要读取的字节,从第几个开始读取,字符串的总长度,字符集 //便利Socket集合,向每个Socket对象发送信息 for (Iterator<Socket> it = ServerSocketTest.clientSocket.iterator();it.hasNext(); ) { try { Socket s = it.next(); byte[] pushHead = new byte[2]; pushHead[0] = buff[0]; pushHead[1] = (byte) pushMsg.getBytes("utf-8").length; //发送前两个字节 s.getOutputStream().write(pushHead); //发送有效数据 s.getOutputStream().write(pushMsg.getBytes("utf-8")); } catch (SocketException e) { //如果捕获到异常将其从集合中删除 // 如果捕捉到异常,表明该Socket已经关闭 it.remove(); } } } } } catch (IOException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); }finally{ try { socket.close(); } catch (IOException e) { e.printStackTrace(); } } } // 获取WebSocket请求的Seckey private String getSecWebSocketKey(String req) { // 构建正则表达式,获取Sec-WebSocket-Key:后面的内容 Pattern p = Pattern.compile("^(Sec-WebSocket-Key:).+", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE); Matcher m = p.matcher(req); if (m.find()) { // 提取Sec-WebSocket-Key String foundstring = m.group(); return foundstring.split(":")[1].trim(); } else { return null; } } // 根据WebSocket请求的Seckey计算SecAccept private String getSecWebSocketAccept(String key) throws Exception { String guid = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"; key += guid; MessageDigest md = MessageDigest.getInstance("SHA-1"); md.update(key.getBytes("ISO-8859-1"), 0, key.length()); byte[] shalHash = md.digest(); BASE64Encoder encoder = new BASE64Encoder(); return encoder.encode(shalHash); } } ``` 刚才又调试了几次,发现了一些新的东西。 同时开启多个页面进行程序测试。当其中一个页面关闭时,这个页面向后台发送了一条数据,后台接收后处理并发送给其他页面。但是这个页面关闭了,本线程下发送给其他页面的信息全部发送失败。由于发送信息发送不出去,本线程就在此处 ``` } catch (SocketException e) { //如果捕获到异常将其从集合中删除 // 如果捕捉到异常,表明该Socket已经关闭 it.remove(); } ``` 把其他的Socket对象全部删除了,导致所有的Socket对象连接都断开了。求教大神们有没有什么靠谱的解决办法
webSocket客户端报302,不知道哪里写错了。
请看下面代码: ``` <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <!doctype html> <html> <head> <meta charset="UTF-8" content="text/html"> <meta name="Keywords" content=""> <meta name="Description" content=""> <title>基于Java服务端消息主动推送技术</title> <style type="text/css"> *{ margin:0; padding:0; } body{ background:url("image/bg.jpg") no-repeat; background-size:cover; } .chatbox{ width:700px; height:500px; margin:100px auto; font-size:12px; font-family:"微软雅黑"; color:#666; } h1{ text-align:center; font-size:30px; color:green; text-shadow:5px 10px 10px #111; } .chatbox .c_info{ text-align:left; line-height:46px; } .inputText{ height:30px; border:0; outline:none; text-indent:1em; font-size:14px; font-family:"微软雅黑"; color:#61B52D; border: 1px solid #61B52D; } .btn{ width:80px; text-indent:0; background:#9AD02D; color:#fff; margin-left: 10px; } .chatbox .c_message{ width:97%; height:300px; overflow:auto; border:1px solid yellow; font-size:24px; color:#9DA791; padding-left:20px; box-shadow:2px 10px 10px #111; /* background: #EAF9BE; */ } .chatbox .c_send{ margin-top: 10px; } </style> </head> <body> <div class="chatbox"> <h1>基于Java服务端消息主动推送技术</h1> <div class="c_info"> 服务器地址:<input type="text" value="localhost:8080/webSocket" id="addr" class="inputText" style="width:350px"/> 用户名:<input type="text" value="Yinwq" id="userName" class="inputText"/> <input type="button" id="con" class="inputText btn" value="连接" /> </div> <div class="c_message"> </div> <div class="c_send"> <input type="text" id="sendText" class="inputText" style="width:592px" /> <input type="button" id="sendBtn" class="inputText btn" value="发送" /> </div> </div> </body> <!-- 引入jquery类库 --> <script type="text/javascript" src="js/jquery-1.11.2.min.js"></script> <script type="text/javascript"> var connected = false; var ws; $(function(){ $(".c_send").hide(); //1.判断浏览器是否支持webSocket if(window.WebSocket || window.MozWebSocket){ printMsg("您的浏览器支持WebSocket,您可以尝试连接到聊天服务器!" , "OK"); }else{ printMsg("您的浏览器不支持WebSocket,您可以换其他浏览器!" , "ERROR"); $("#con").attr("disabled","true"); } }) //打印信息 function printMsg(msg,msgType){ if(msgType == "OK"){ msg = "<span style='color:green'>"+msg+"</span>"; } if(msgType == "ERROR"){ msg = "<span style='color:red'>"+msg+"</span>" } $(".c_message").append(msg + "<br/>"); } //点击连接的时候触发事件 $("#con").click(function(){ if(connected){ //已连接 ws.send("["+$("#userName").val()+"]离开了聊天室"); connected = false; ws.close(); }else{//没有连接 printMsg("正在准备连接,请稍等!", ""); var url = "ws://"+ $("#addr").val(); if("WebSocket" in window){ //ws = new WebSocket(url); ws = new WebSocket('ws://localhost:8080/webSocket'); }else if ("MozWebSocket" in window) { ws = new MozWebSocket(url); } //连接成功后设置连接状态 connected = true; $("#con").val("断开"); //注册事件 ws.onopen = function(event){ openWs(event); }; ws.onmessage = function(event){ msgWs(event); }; ws.onclose = function(event){ closeWs(event); }; ws.onerror = function(event){ errorWs(event); }; } }); //打开socket function openWs(event){ printMsg("连接已建立...!", "OK"); //建立连接的时候 ws.send("["+$("#userName")+"]进入了聊天室"); $(".c_send").show(); }; //接收消息 function msgWs(event){ printMsg(evnet.data); }; //关闭连接 function closeWs(event){ $("#con").val("连接"); //隐藏发送div $(".c_send").hide(); }; //产生错误 function errorWs(event){ printMsg("与服务器连接错误.." , "ERROR"); }; //点击发送触发事件 $("#sendBtn").click(function(){ //获取发送内容 var text = $("#sendText").val(); ws.send($("#userName").val() + "说:" + text); $("#sendText").val("");//清空发送框 }); </script> </html> ``` 浏览器报错 ![图片说明](https://img-ask.csdn.net/upload/201601/11/1452477841_505407.png) ![图片说明](https://img-ask.csdn.net/upload/201601/11/1452477853_561170.png)
java WebSocket 相关 前端已经接收到值了,为什么后台代码还是会出异常呀
java Web Socket 初学者 最近遇到了一个问题 ,就是在后台向前端推送数据时前台页面明明接收到了值,但是后台代码还是会出异常这是为什么! 下面是我写的代码 这个是主线程代码 ``` package test; import java.net.ServerSocket; import java.net.Socket; import java.util.ArrayList; import java.util.List; public class ChatServer { // 记录所有客户端的Socket public static List<Socket> clientSocket = new ArrayList<Socket>(); public ChatServer() throws Exception { // 创建ServerSocket,准备接受客户端连接 ServerSocket ss = new ServerSocket(30000); while (true) { System.out.println(clientSocket.size()); // 接收客户端连接 Socket socket = ss.accept(); // 将客户端Socket添加到clientSocket集合中 clientSocket.add(socket); // 启动线程 new ServerThread(socket).start(); } } public static void main(String[] args) throws Exception { new ChatServer(); } } ``` 下面是线程内代码 ``` package test; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.net.Socket; import java.security.MessageDigest; import java.util.Iterator; import java.util.regex.Matcher; import java.util.regex.Pattern; import sun.misc.BASE64Encoder; public class ServerThread extends Thread{ private Socket socket; public ServerThread(Socket socket) { this.socket = socket; } private int as = 0; @SuppressWarnings("finally") public void run() { System.out.println("为用户:" + socket.getInetAddress().getHostName() + "开启线程"); try { // 得到Socket对应的输入流 InputStream is = socket.getInputStream(); // 得到Socket对应的输出流 OutputStream out = socket.getOutputStream(); byte[] buff = new byte[1024]; String req = ""; // 读取数据,此时建立与wabSocket的握手 int count = is.read(buff); // 如果读取的数据长度>0 if (count > 0) { // 将读取的数据转化为字符串 req = new String(buff, 0, count); // System.out.println("握手请求:" + req);// req = 客户端信息 // 获取WebSocket的值 String seckey = getSecWebSocketKey(req); String response = "HTTP/1.1 101 Switching Protocols\r\nUpgrade: " + "websocket\r\nConnection: Upgrade\r\nSec-WebSocket-Accept: " + getSecWebSocketAccept(seckey) + "\r\n\r\n"; System.out.println("secAccept = " + getSecWebSocketAccept(seckey)); //推送客户端 out.write(response.getBytes("utf-8")); int hasRedad = 0; // 不断读取WebSocket发送过来的数据 System.out.println("while循环前,等待前端推送数据。。。。。。。。。。。。"); while ((hasRedad = is.read(buff)) > 0) { //必须这么写 System.out.println("接收到客户端" + socket.getInetAddress().getHostName() + "字节数:" + hasRedad); /* * 因为WebSocket发送过来的数据遁寻了一定的协议格式, 其中第3~6个字节是数据掩码, * 从第七个字节开始才是真正的有效数据。 因此程序使用第3~6个字节对后面的数据进行了处理 */ for (int i = 0; i < hasRedad - 6; i++) { buff[i+6] = (byte)(buff[i%4+2]^ buff[i+6]); } //获得从浏览器发送过来的数据 String pushMsg = new String(buff, 6, hasRedad-6, "utf-8"); //遍历Socket集合,依次向每个Socket发送数据 int a=1; for(Iterator<Socket> it = ChatServer.clientSocket.iterator();it.hasNext();){ //获得集合中的Socket对象 System.out.println("Socket集合中有:"+ChatServer.clientSocket.size()+"个对象等待发送信息"); Socket s = it.next(); //发送数据时,第一个字节必须与读到的第一个字节相同 byte[] pushHead = new byte[2]; pushHead[0] = buff[0]; //发送数据时,第二个字节记录 发送数据的长度 pushHead[1] = (byte)pushMsg.getBytes("utf-8").length; try { System.out.println("web推送前"); System.out.println("Socket 的InputStream值:"+is.available()); System.out.println("web推送中........"); //发送前两个字节 s.getOutputStream().write(pushHead); //发送有效数据 s.getOutputStream().write(pushMsg.getBytes("utf-8")); } catch (Exception e) { System.out.println("向前端推送数据后发生了异常"); e.printStackTrace(); }finally{ //如果s.getInputStream().available() == 0,表明该Scoket已经关闭 //将该Socket从Socket集合中删除 System.out.println("从集合中删除该Socket对象"); ChatServer.clientSocket.remove(s); a=2; break; } } System.out.println("WEB 推送后"); if(a==2){ break; } } } } catch (Exception e) { System.out.println("有一个Socket对象关闭了,该对象线程结束"); }finally{ try { //关闭Socket System.out.println("关闭该Socket对象"); socket.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } // 获取WebSocket请求的Seckey private String getSecWebSocketKey(String req) { // 构建正则表达式,获取Sec-WebSocket-Key:后面的内容 Pattern p = Pattern.compile("^(Sec-WebSocket-Key:).+",Pattern.CASE_INSENSITIVE | Pattern.MULTILINE); Matcher m = p.matcher(req); if (m.find()) { // 提取Sec-WebSocket-Key String foundstring = m.group(); return foundstring.split(":")[1].trim(); } else { return null; } } // 根据WebSocket请求的Seckey计算SecAccept private String getSecWebSocketAccept(String key) throws Exception { String guid = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"; key += guid; MessageDigest md = MessageDigest.getInstance("SHA-1"); md.update(key.getBytes("ISO-8859-1"), 0, key.length()); byte[] shalHash = md.digest(); BASE64Encoder encoder = new BASE64Encoder(); return encoder.encode(shalHash); } } ``` 没有错误信息,不报错的 但是就是程序走不了了
有关PHP处理POST请求,如何向客户端返回数据
客户端ajax调用 服务器通过 POST 全局变量 获取POST参数处理了请求后,如何将结果返回给客户端 有说用websocket,请问怎么获得用户端的ip和端口呢?而且用户ip是局域网怎么办
javaweb小项目,在写完登录功能时设置断点查看程序运行状况时得到的结果和直接运行得到的结果不一样???
初学者今天打算自己写一下小项目,写完登录功能后运行了没什么问题。 但是设置断点之后打算一步步看运行过程,发生了诡异的事情,因为之前用断点查看运行过程没出现过这样的事,首先正常启动得到正常的结果,加了断点走却得不到一样的结果。 程序正常运行大概流程就是在login.html填上用户名和密码发送请求给LoginServlet调用service,service调dao执行sql查询是否有这个用户。 事务处理用了动态代理,dao层的实现类也依靠mybatis的动态代理,只写sql语句。 一般我发现问题后都会上网查,但是这个加不加断点影响结果的事情查了一下午都没有找到解决办法,我设置了两个点,34行(断点1)和46行(断点2)。 我发现把 断点1 设置在获取动态代理对象agent(图里第35行代码)那一句代码之前,直走断点1不跳过,那么37行得到的emp对象会是null,也就是找不到这个用户。 明明输入了正确的用户名和密码,而且不走断点直接运行是可以验证通过的。 接下来更诡异的是,我选择走断点的方式,但是我走到断点1的时候,选择跳过断点1,居然得到了emp这个对象,然后验证成功。 这到底咋回事阿???? 下面第一张图是跳过断点1 第二张图是走断点1 ![这是跳过断点1](https://img-ask.csdn.net/upload/201912/04/1575390954_130758.png) ![这是走断点1](https://img-ask.csdn.net/upload/201912/04/1575390974_195779.png) 试了一下跟着断点走到动态代理类的时候报了反射异常InvocationTargetException,应该是动态代理类写错了? ![图片说明](https://img-ask.csdn.net/upload/201912/04/1575436234_560327.png) ``` java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at com.cdx.psms.utils.TransactionInvocationHandler.invoke(TransactionInvocationHandler.java:29) at com.sun.proxy.$Proxy6.login(Unknown Source) at com.cdx.psms.controller.LoginServlet.doPost(LoginServlet.java:41) at javax.servlet.http.HttpServlet.service(HttpServlet.java:660) at javax.servlet.http.HttpServlet.service(HttpServlet.java:741) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:526) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:678) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343) at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408) at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:861) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1579) at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:748) Caused by: org.apache.ibatis.exceptions.PersistenceException: ### Error querying database. Cause: org.apache.ibatis.executor.ExecutorException: Executor was closed. ### Cause: org.apache.ibatis.executor.ExecutorException: Executor was closed. at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30) at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:149) at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:140) at org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:147) at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:80) at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:57) at com.sun.proxy.$Proxy5.login(Unknown Source) at com.cdx.psms.service.EmpServiceImpl.login(EmpServiceImpl.java:17) ... 31 more Caused by: org.apache.ibatis.executor.ExecutorException: Executor was closed. at org.apache.ibatis.executor.BaseExecutor.createCacheKey(BaseExecutor.java:197) at org.apache.ibatis.executor.CachingExecutor.createCacheKey(CachingExecutor.java:146) at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:82) at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:147) ... 37 more ``` public class EmpServiceImpl implements EmpService { private EmpDao empDao = SqlSessionUtil.getSession().getMapper(EmpDao.class); @Override public Emp login(String username,String password) { Emp emp = new Emp(); emp.setUsername(username); emp.setPassword(password); emp = empDao.login(emp); return emp; } } ``` ```
现在是一些关键操作要记录操作日志,但是在insert的时候,偶然会出现插入失败的问题.现在找不到问题所在?
执行代码 ``` HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); SsOperLog ssOperLogEntity = new SsOperLog(); ssOperLogEntity.setOperNo(Long.valueOf(IdGenarater.nextStringValue()));//操作流水号 UserInfo users = Util.getSessionUserInfo(request);//登录用户 if (users == null) {//用户还未登录 String workCode = request.getParameter("workCode"); String urlString = request.getHeader("host"); //根据域名获取部门编号 String deptCode = loginService.getDeptCodeByDomainName(urlString); users = loginService.selectByUserIdAndPassword(workCode, null, deptCode); if (users == null) { return point.proceed(); } } ssOperLogEntity.setDeptCode(users.getDeptCode());//用户机构 ssOperLogEntity.setOperId(Long.valueOf(users.getOperId()));//用户id ssOperLogEntity.setOperName(users.getOperName());//操作员 ssOperLogEntity.setDeptName(users.getDeptName()); ssOperLogEntity.setOperDate(new Date(System.currentTimeMillis()));//操作日期 ssOperLogEntity.setOperTime(new Date(System.currentTimeMillis()));//操作时间 String rquestName = getMthodRemark(point);//操作名称(对应注解里面的remark信息) String operType = getMthodOperType(point);//操作类型(对应注解里面的opertype信息) String processMethod = point.getSignature().getName();//请求处理方法名 ssOperLogEntity.setReruestId(request.getRequestURI());//请求url ssOperLogEntity.setRquestName(rquestName); if(operType.length()>1){ //获取大类类型 ssOperLogEntity.setCategories(operType.substring(0,1)); } ssOperLogEntity.setProcessMethod(processMethod); ssOperLogEntity.setOperType(operType); ssOperLogEntity.setLocalAddress(request.getRemoteAddr()); if (!"/aa/login/checkLogin.do".equals(request.getRequestURI())) { String requestParams = JSONObject.toJSONString(request.getParameterMap()); ssOperLogEntity.setRequestParams(requestParams); }//请求参数 Object[] method_param = null; Object object; try { method_param = point.getArgs(); //获取方法参数 object = point.proceed(); } catch (Exception e) { ssOperLogEntity.setOperState(OperateStatusEnum.FAIL.getCode());//操作失败 ssOperLogEntity.setExceptionMesg(e.getMessage()); if (e.getMessage() == null) { ssOperLogEntity.setExceptionMesg(e.toString()); } mongoTemplate.insert(ssOperLogEntity); // ssOperLogMapper.insert(ssOperLogEntity); throw e; } ssOperLogEntity.setOperState(OperateStatusEnum.SUCC.getCode());//操作成功 mongoTemplate.insert(ssOperLogEntity); // 这里报错 // ssOperLogMapper.insert(ssOperLogEntity); return object; } ``` 异常信息:appserver-b4 等同于ip地址 ``` org.springframework.dao.DataAccessResourceFailureException: Operation on server appserver-b4:27017 failed; nested exception is com.mongodb.MongoException$Network: Operation on server appserver-b4:27017 failed at org.springframework.data.mongodb.core.MongoExceptionTranslator.translateExceptionIfPossible(MongoExceptionTranslator.java:77) ~[spring-data-mongodb-1.10.15.RELEASE.jar:na] at org.springframework.data.mongodb.core.MongoTemplate.potentiallyConvertRuntimeException(MongoTemplate.java:2128) ~[spring-data-mongodb-1.10.15.RELEASE.jar:na] at org.springframework.data.mongodb.core.MongoTemplate.execute(MongoTemplate.java:461) ~[spring-data-mongodb-1.10.15.RELEASE.jar:na] at org.springframework.data.mongodb.core.MongoTemplate.insertDBObject(MongoTemplate.java:1026) ~[spring-data-mongodb-1.10.15.RELEASE.jar:na] at org.springframework.data.mongodb.core.MongoTemplate.doInsert(MongoTemplate.java:835) ~[spring-data-mongodb-1.10.15.RELEASE.jar:na] at org.springframework.data.mongodb.core.MongoTemplate.insert(MongoTemplate.java:776) ~[spring-data-mongodb-1.10.15.RELEASE.jar:na] at org.springframework.data.mongodb.core.MongoTemplate.insert(MongoTemplate.java:767) ~[spring-data-mongodb-1.10.15.RELEASE.jar:na] at com.wx.app.ygp.service.log.LogService.doBefore(LogService.java:115) ~[classes/:na] at sun.reflect.GeneratedMethodAccessor867.invoke(Unknown Source) ~[na:na] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_162] at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_162] at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:621) ~[spring-aop-4.2.3.RELEASE.jar:4.2.3.RELEASE] at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:610) ~[spring-aop-4.2.3.RELEASE.jar:4.2.3.RELEASE] at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:68) ~[spring-aop-4.2.3.RELEASE.jar:4.2.3.RELEASE] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:168) ~[spring-aop-4.2.3.RELEASE.jar:4.2.3.RELEASE] at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92) ~[spring-aop-4.2.3.RELEASE.jar:4.2.3.RELEASE] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.2.3.RELEASE.jar:4.2.3.RELEASE] at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:654) ~[spring-aop-4.2.3.RELEASE.jar:4.2.3.RELEASE] at com.wx.app.ygp.action.system.LoginController$$EnhancerBySpringCGLIB$$3d4c3a49.checkLogin(<generated>) ~[classes/:na] at sun.reflect.GeneratedMethodAccessor1317.invoke(Unknown Source) ~[na:na] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_162] at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_162] at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:222) ~[spring-web-4.2.3.RELEASE.jar:4.2.3.RELEASE] at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137) ~[spring-web-4.2.3.RELEASE.jar:4.2.3.RELEASE] at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110) ~[spring-webmvc-4.2.3.RELEASE.jar:4.2.3.RELEASE] at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:814) ~[spring-webmvc-4.2.3.RELEASE.jar:4.2.3.RELEASE] at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:737) ~[spring-webmvc-4.2.3.RELEASE.jar:4.2.3.RELEASE] at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85) ~[spring-webmvc-4.2.3.RELEASE.jar:4.2.3.RELEASE] at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959) [spring-webmvc-4.2.3.RELEASE.jar:4.2.3.RELEASE] at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893) [spring-webmvc-4.2.3.RELEASE.jar:4.2.3.RELEASE] at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970) [spring-webmvc-4.2.3.RELEASE.jar:4.2.3.RELEASE] at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872) [spring-webmvc-4.2.3.RELEASE.jar:4.2.3.RELEASE] at javax.servlet.http.HttpServlet.service(HttpServlet.java:648) [servlet-api.jar:na] at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846) [spring-webmvc-4.2.3.RELEASE.jar:4.2.3.RELEASE] at javax.servlet.http.HttpServlet.service(HttpServlet.java:729) [servlet-api.jar:na] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292) [catalina.jar:8.0.44] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) [catalina.jar:8.0.44] at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) [tomcat-websocket.jar:8.0.44] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240) [catalina.jar:8.0.44] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) [catalina.jar:8.0.44] at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:121) [spring-web-4.2.3.RELEASE.jar:4.2.3.RELEASE] at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.2.3.RELEASE.jar:4.2.3.RELEASE] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240) [catalina.jar:8.0.44] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) [catalina.jar:8.0.44] at org.springframework.session.web.http.SessionRepositoryFilter.doFilterInternal(SessionRepositoryFilter.java:167) [spring-session-1.3.1.RELEASE.jar:na] at org.springframework.session.web.http.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:80) [spring-session-1.3.1.RELEASE.jar:na] at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346) [spring-web-4.2.3.RELEASE.jar:4.2.3.RELEASE] at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:262) [spring-web-4.2.3.RELEASE.jar:4.2.3.RELEASE] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240) [catalina.jar:8.0.44] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) [catalina.jar:8.0.44] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212) [catalina.jar:8.0.44] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:94) [catalina.jar:8.0.44] at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:504) [catalina.jar:8.0.44] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141) [catalina.jar:8.0.44] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) [catalina.jar:8.0.44] at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:620) [catalina.jar:8.0.44] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88) [catalina.jar:8.0.44] at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:502) [catalina.jar:8.0.44] at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1132) [tomcat-coyote.jar:8.0.44] at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:684) [tomcat-coyote.jar:8.0.44] at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1533) [tomcat-coyote.jar:8.0.44] at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1489) [tomcat-coyote.jar:8.0.44] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_162] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_162] at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-util.jar:8.0.44] at java.lang.Thread.run(Thread.java:748) [na:1.8.0_162] Caused by: com.mongodb.MongoException$Network: Operation on server appserver-b4:27017 failed at com.mongodb.DBTCPConnector.doOperation(DBTCPConnector.java:215) ~[mongo-java-driver-2.14.3.jar:na] at com.mongodb.DBCollectionImpl.writeWithCommandProtocol(DBCollectionImpl.java:567) ~[mongo-java-driver-2.14.3.jar:na] at com.mongodb.DBCollectionImpl.insertWithCommandProtocol(DBCollectionImpl.java:528) ~[mongo-java-driver-2.14.3.jar:na] at com.mongodb.DBCollectionImpl.insertImpl(DBCollectionImpl.java:206) ~[mongo-java-driver-2.14.3.jar:na] at com.mongodb.DBCollection.insert(DBCollection.java:176) ~[mongo-java-driver-2.14.3.jar:na] at com.mongodb.DBCollection.insert(DBCollection.java:93) ~[mongo-java-driver-2.14.3.jar:na] at com.mongodb.DBCollection.insert(DBCollection.java:78) ~[mongo-java-driver-2.14.3.jar:na] at com.mongodb.DBCollection.insert(DBCollection.java:120) ~[mongo-java-driver-2.14.3.jar:na] at org.springframework.data.mongodb.core.MongoTemplate$9.doInCollection(MongoTemplate.java:1031) ~[spring-data-mongodb-1.10.15.RELEASE.jar:na] at org.springframework.data.mongodb.core.MongoTemplate.execute(MongoTemplate.java:459) ~[spring-data-mongodb-1.10.15.RELEASE.jar:na] ... 63 common frames omitted Caused by: java.net.SocketException: Broken pipe (Write failed) at java.net.SocketOutputStream.socketWrite0(Native Method) ~[na:1.8.0_162] at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:111) ~[na:1.8.0_162] at java.net.SocketOutputStream.write(SocketOutputStream.java:155) ~[na:1.8.0_162] at org.bson.io.PoolOutputBuffer.pipe(PoolOutputBuffer.java:153) ~[mongo-java-driver-2.14.3.jar:na] at com.mongodb.DBCollectionImpl.sendWriteCommandMessage(DBCollectionImpl.java:639) ~[mongo-java-driver-2.14.3.jar:na] at com.mongodb.DBCollectionImpl.access$300(DBCollectionImpl.java:50) ~[mongo-java-driver-2.14.3.jar:na] at com.mongodb.DBCollectionImpl$4.execute(DBCollectionImpl.java:576) ~[mongo-java-driver-2.14.3.jar:na] at com.mongodb.DBCollectionImpl$4.execute(DBCollectionImpl.java:567) ~[mongo-java-driver-2.14.3.jar:na] at com.mongodb.DBPort.doOperation(DBPort.java:187) ~[mongo-java-driver-2.14.3.jar:na] at com.mongodb.DBTCPConnector.doOperation(DBTCPConnector.java:208) ~[mongo-java-driver-2.14.3.jar:na] ... 72 common frames omitted ``` 配置MongoDB文件: ``` mongo.hostport=127.0.0.1:27017 mongo.connectionsPerHost=100 mongo.threadsAllowedToBlockForConnectionMultiplier=6 mongo.dataName=ygp mongo.username=ygp mongo.password=ygp_admin mongo.connectTimeout=60000 mongo.maxWaitTime=120000 mongo.autoConnectRetry=true mongo.socketKeepAlive=true mongo.socketTimeout=1500 mongo.slaveOk=true <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:mongo="http://www.springframework.org/schema/data/mongo" xsi:schemaLocation="http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/data/mongo http://www.springframework.org/schema/data/mongo/spring-mongo-1.0.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"> <!--设置用户验证--> <bean id="userCredentials" class="org.springframework.data.authentication.UserCredentials"> <constructor-arg name="username" value="${mongo.username}" /> <constructor-arg name="password" value="${mongo.password}" /> </bean> <!-- 定义mongo对象,对应的是mongodb官方jar包中的Mongo,replica-set设置集群副本的ip地址和端口 --> <mongo:mongo id="mongo" replica-set="${mongo.hostport}"> <!-- 一些连接属性的设置 --> <mongo:options connections-per-host="${mongo.connectionsPerHost}" threads-allowed-to-block-for-connection-multiplier="${mongo.threadsAllowedToBlockForConnectionMultiplier}" connect-timeout="${mongo.connectTimeout}" max-wait-time="${mongo.maxWaitTime}" auto-connect-retry="${mongo.autoConnectRetry}" socket-keep-alive="${mongo.socketKeepAlive}" socket-timeout="${mongo.socketTimeout}" slave-ok="${mongo.slaveOk}" write-number="1" write-timeout="0" write-fsync="true" /> </mongo:mongo> <!-- mongo的工厂,通过它来取得mongo实例,dbname为mongodb的数据库名,没有的话会自动创建 --> <bean id="mongoDbFactory" class="org.springframework.data.mongodb.core.SimpleMongoDbFactory"> <constructor-arg ref="mongo" /> <constructor-arg value="${mongo.dataName}" /> <constructor-arg ref="userCredentials" /> </bean> <bean id="mappingContext" class="org.springframework.data.mongodb.core.mapping.MongoMappingContext" /> <!--排除 _class --> <bean id="defaultMongoTypeMapper" class="org.springframework.data.mongodb.core.convert.DefaultMongoTypeMapper"> <constructor-arg name="typeKey"> <null /> </constructor-arg> </bean> <!-- collection的映射 --> <bean id="mappingMongoConverter" class="org.springframework.data.mongodb.core.convert.MappingMongoConverter"> <constructor-arg name="mongoDbFactory" ref="mongoDbFactory" /> <constructor-arg name="mappingContext" ref="mappingContext" /> <property name="typeMapper" ref="defaultMongoTypeMapper" /> </bean> <!-- mongodb的主要操作对象,所有对mongodb的增删改查的操作都是通过它完成 --> <bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate"> <constructor-arg name="mongoDbFactory" ref="mongoDbFactory" /> <constructor-arg name="mongoConverter" ref="mappingMongoConverter" /> </bean> </beans> ```
webrtc理论上是看了个大概可是不知怎么着手?
我已经大概在webrtc中文网看了一下内容: 在webrtc中SDP是用于交互多媒体流信息的最小不接去除单位 _____________________________________________________________________________ webrtc是先定位两个人的位置,然后两个人都跳到同一个链接里面进行数据互通。信令结束以后,就不需要web服务器在中间传递数据。 编解编码器的功能是压缩和解压音频和视频数据。 还有实现设备间的信息互通,可能需要中继TURN服务器,因为可能因为对方的防火墙和NAT和限制了(隐藏了IP地址或者)用于通信的洞,所以只好在通话的时候进行ICE协商。就是发起者这边发了一个offer,有关怎么找到要准备进行通话的小伙伴的方法。然后,将这个数据给到服务器,然后服务器再给到那个小伙伴,然后那个小伙伴就可以通过设备找到发起人,然后就可以开始设备之间的互通,而不需要服务器在中间传递数据。 webrtc 三大API getUserMedia PeerConnection Data Channel getUserMedia 应用: #为用户文件档案拍照 #录制语音数据,并将数据发送到语音转文字引擎 #为用户录制语音或者视频,而且在掉包的情况下能保证语音及视频的质量不下滑 webrtc实例 https://www.jianshu.com/p/57fd3b5d2f80 Peer Connection #生成并传递SDP (不是通过网络本身传递,而是生成他们并处理输入的消息) #对音视频进行压缩和解压 #通过回声消除算法处理语音 #丢包隐藏,数据重传,抖动缓存区,估计宽带等功能 Data Channel #信息传输的通道,设置通道是否可靠,设置可靠则可以自动重传。 #通道设计类似于websocketAPI界别的通道,所以可以用websocket的想法去看待它。 #通道设计类似于在websocketAPI级别上工作,所以可以用websocket的思考法式对待它。 想要一个webrtc的应用的实现方法,有以下几点: 1.客户端 2.信道 3.NAT 4.媒体 1.客户端 浏览器端使用javasrcipt进行开发,或者用框架,或者很多人都是直接从github上开始的。 如果是软件的话,应该挑选合适的sdk。 如果是pc,则使用psdn或者嵌入式的方法进行开发。 如果是pc的话,则可以用Electron进行完成,说着用嵌入式的方式完成。 2.信道 你需要一个新到服务器,当然也可以不要。在用之前,你必须检查你的服务器是否有信道机制用于 非webrtc上。如果有,你可以在这些机制上搭载sdp消息和其他webrtc信令。 3.NAT 一下是你不应该做的: #不用trun服务器 #不用公共服务器 #不用stun公共服务器 #所有服务都在同一个服务器上实现 #不要一上来就想布置世界级的全球服务网络。 以下是你应该做的: #部署stun和turn在同一进程 #stun和turn应该在同一个服务器上部署,而且要部署到同一进程中。 #用coturn,几乎所有人都在使用。 #你也可以从其他公司获取NAT服务,例如XirSys和T willio也是不错的选择。 4.媒体 如果你使用pstn或者视频会议,音频或者更高级的功能,建议使用一个媒体服务器。 现在市面和商业服务器有很多,他们在很很多方面是有区别的。 现在开源和商业的服务器有很多,他们在很多方面都是有区别的。 webrtc使用领域前瞻 1.机器学习和人工智能 2.在线学习 3.在线医疗 4.社交媒体 webrtc打洞就是将交换数据双方ip,port和nat信息通过信令服务器进行交互,然后双方各自获得对方的信息后就进行穿透,stun对p2p依然后有问题,所以还需要用到ICE。然后libjingle就是ICE思想的具体实现。 _____________________________________________________________________________ 但是我不知道怎么着手去弄,信令服务器我查了,没有说买信令服务器的,都是说配置的。所以我不知怎么做了?希望有哪位老师指点一下。感激不尽!
window.location.href()跳转后刷新页面session失效
ajax中,成功请求后跳转页面,可以获取到session中的user的userName,刷新之后页面报错,我怀疑是不是刷新之后session失效了。有没有知道为什么和怎么办的。代码如下: ``` function login(){ $.ajax({ type : "POST", url : "login.action", data : $("#login").serialize(), cache:false, async:false, success : function(msg) { if(msg == "登陆成功") window.location.href="studentMain.jsp" <%String userName = ((UserInfo)request.getSession().getAttribute("user")).getName(); %> <nav class="navbar navbar-inverse navbar-fixed-top"> <div class="container-fluid"> <div class="navbar-header"> <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar"> <span class="sr-only">Toggle navigation</span> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button> <a class="navbar-brand" ">test</a> </div> <div id="navbar" class="navbar-collapse collapse"> <ul class="nav navbar-nav navbar-right"> <li><a class="navbar-brand" ">当前用户:<%=userName %></a></li> 错误信息:org.apache.jasper.JasperException: An exception occurred processing JSP page /studentMain.jsp at line 40 37: </head> 38: 39: <body> 40: <%String userName = ((UserInfo)request.getSession().getAttribute("user")).getName(); %> 41: <nav class="navbar navbar-inverse navbar-fixed-top"> 42: <div class="container-fluid"> 43: <div class="navbar-header"> Stacktrace: org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:574) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:476) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340) javax.servlet.http.HttpServlet.service(HttpServlet.java:729) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:88) ```
pyhon服务器如何用websocke实现服务器和html5的通信(代码已实现成功连接客户端服务端)?
服务端代码 #coding=gbk #coding=utf-8 #-*- coding: UTF-8 -* import struct import socket import re import time #ws握手响应头 import hashlib import base64 from multiprocessing import Process #HTML_ROOT_DIR = r"C:\Users\lenovo\Desktop\html" def write_msg(message): data=struct.pack('B',129)#写入第一个字节 msg_len=len(message)#写入包长度 if(msg_len<=125): data+=struct.pack('B',msg_len) elif(mas_len<=2**16-1): data+=struct.pack('!BH',126,msg_len) elif(mas_len<=2**64-1): data+=struct.pack('!BQ',127,msg_len) else: pass data+=bytes(message,encoding="utf-8") return data def handle_client(client_socket): """ 处理客户端请求 """ # 获取客户端请求数据 #获得key request_data = client_socket.recv(1024) print(request_data) webpage_regex=re.compile('''.*Sec-WebSocket-Key:(.*)''',re.IGNORECASE) key=webpage_regex.findall(request_data.decode("utf-8")) keyy='' try: print(key[0]) keyy=key[0] keyy=keyy.strip() print(keyy) except: pass # 打开文件,读取内容 try: file = open(r"C:\html\shouji\测试\客户端原生socket.html", "rb") except IOError: response_start_line = "HTTP/1.1 404 Not Found\r\n" response_headers = "Server: My server\r\n" response_body = "The file is not found!" response = response_start_line + response_headers + "\r\n" + response_body client_socket.send(bytes(response, "utf-8")) client_socket.close() else: file_data = file.read() file.close() if(keyy==''): response_start_line = "HTTP/1.1 200 OK\r\n" response_headers = "Server: My server\r\n" response_body = file_data.decode("utf-8") response = response_start_line + response_headers + "\r\n" + response_body client_socket.send(bytes(response, "utf-8")) client_socket.close() print('https响应已发送') else: magic = '258EAFA5-E914-47DA-95CA-C5AB0DC85B11' sha1 = hashlib.sha1() sha1.update((keyy+magic).encode("utf8")) keyy=base64.b64encode(sha1.digest()) print('dddddd',base64.b64encode(sha1.digest())) keyy=keyy.decode("utf8") print('***********************',keyy) response_start_line = "HTTP/1.1 101 Switching Protocols\r\n" response_headers = "Upgrade: websocket\r\nConnection: Upgrade\r\nSec-WebSocket-Accept:"+keyy+"\r\n" response_body = file_data.decode("utf-8") response = response_start_line + response_headers + "\r\n" #+ response_body client_socket.send(bytes(response, "utf-8")) print('ws响应已发送') while(1): time.sleep(5) client_socket.send(bytes('dddd', "utf-8")) #client_socket.send( write_msg('www.baidu.com')) print('发送了一次') # 关闭客户端连接 #client_socket.close() if __name__ == "__main__": server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) server_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) server_socket.bind(("0.0.0.0", 8000)) server_socket.listen(128) while True: client_socket, client_address = server_socket.accept() print("[%s, %s]用户连接上了" % client_address) handle_client_process = Process(target=handle_client, args=(client_socket,)) handle_client_process.start() #client_socket.close() 客户端代码: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title></title> </head> <body> <h2 id="t">史p 芬</h2> <script type="text/javascript" charset="utf-8"> var ws = new WebSocket("ws://127.0.0.1:8000/"); //document.write(Date()); ws.onopen = function(e) { // Check the protocol chosen by the server //console.log(echoSocket.protocol); alert('连接上了') document.write(Date()); //ws.send('已经连接') } // 接受文本消息的事件处理实例: ws.onmessage = function(e) { alert('接受到消息') if(typeof e.data === "string"){ console.log("String message received", e, e.data); } else { console.log("Other message received", e, e.data); } }; ws.onclose = function(e) { alert('连接关闭') console.log("Connection closed", e); }; </script> </body> </html>
dbutils插入数据到mysql数据库报莫名其妙地NullpointerException
web层 public class BaseServlet extends HttpServlet { @Override protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try { //获取子类字节码对象 Class clazz = this.getClass(); System.out.println(this); //获取method方法名参数,作为获取方法对象的参数 String m = request.getParameter("method"); if(m==null){ m="index"; } System.out.println(m); //获取方法对象 Method method = clazz.getMethod(m, HttpServletRequest.class, HttpServletResponse.class); //让方法执行,返回值为请求转发路径 String s = (String) method.invoke(this, request, response); System.out.println(s); //判断次路径是否为空,不为空请求转发到次路径 if(s != null){ request.getRequestDispatcher(s).forward(request, response); } } catch (Exception e) { e.printStackTrace(); throw new RuntimeException(); } } public class OrderServlet extends BaseServlet { /** * 生成订单 * @param request * @param response * @return * @throws Exception */ public String add(HttpServletRequest request, HttpServletResponse response) throws Exception { //0判断用户是否登录 User user = (User) request.getSession().getAttribute("user"); if(user == null) { request.setAttribute("msg", "请先登录~~~~~"); return "/jsp/msg.jsp"; } //1封装数据 Order order = new Order(); //1.1 封装订单id order.setOid(UUIDUtils.getId()); //1.2封装订单时间 order.setOrderTime(new Date()); //1.3封装订单金额 //获取session中的购物车 Cart cart = (Cart) request.getSession().getAttribute("cart"); order.setTotal(cart.getTotalPrice()); //1.4封装订单项 //从购物车中获取购物车项,遍历购物车中的购物车项,得到每个订单项中的数据 for (CartItem cartItem : cart.getCartItem()) { OrderItem oi = new OrderItem(); //设置订单项id oi.setItemid(UUIDUtils.getId()); //设置订单项包含的商品 oi.setProduct(cartItem.getProduct()); //设置包含于那个订单 oi.setOrder(order); //设置订单项中的商品数 oi.setCount(cartItem.getCount()); //设置定单项的小计 oi.setSubTotal(cartItem.getSubTotal()); //添加订单项到order对 象中 order.getItems().add(oi); } //1.5设置用户 order.setUser(user); //调用service,完成对订单的添加 OrderService os = (OrderService) BeanFactory.getBean("OrderService"); os.add(order); //将order对象放入request域 request.setAttribute("order", order); //将以前的购物车中的东西,即将以前的从购物车清除了 request.getSession().removeAttribute("cart"); //请求转发到订单详情页面 return "/jsp/order_info.jsp"; } } service层 public interface OrderService { void add(Order order) throws Exception; } public class OrderServiceImpl implements OrderService { /** * 将订单数据添加到数据库中 * @throws Exception */ @Override public void add(Order order) throws Exception{ try { //1对者两个添加要加入事务 DataSourceUtils.startTransaction(); //2在order添加一条数据 OrderDao od = (OrderDao) BeanFactory.getBean("OrderDao"); od.add2Order(order); //在orderitem中添加n条数据 for (OrderItem oi : order.getItems()) { od.add2OrderItem(oi); } //提交事务 DataSourceUtils.commitAndClose(); } catch (Exception e) { e.printStackTrace(); //事务回滚 DataSourceUtils.rollbackAndClose(); throw e; } } } dao层 public interface OrderDao { void add2Order(Order order) throws Exception; void add2OrderItem(OrderItem oi) throws Exception; } public class OrderDaoImpl implements OrderDao{ /** * 添加一条订单 */ @Override public void add2Order(Order order) throws SQLException { QueryRunner qr = new QueryRunner(); String sql = "insert into order values(?, ?, ?, ?, ?, ?, ?, ?)"; qr.update(DataSourceUtils.getConnection(), sql, order.getOid(), order.getOrderTime(), order.getTotal(), order.getState(), order.getAddress(), order.getName(), order.getPhone(), order.getUser().getUid()); } /** * 添加一条订单项 */ @Override public void add2OrderItem(OrderItem oi) throws SQLException { QueryRunner qr = new QueryRunner(); String sql = "insert into orderitem values(?, ?, ?, ?, ?)"; qr.update(DataSourceUtils.getConnection(),sql, oi.getItemid(), oi.getCount(), oi.getSubTotal(), oi.getProduct().getPid(), oi.getOrder().getOid()); } } 出错后jsp页面显示不出,所报异常 java.lang.NullPointerException at com.mysql.jdbc.ResultSetMetaData.getField(ResultSetMetaData.java:397) at com.mysql.jdbc.ResultSetMetaData.getColumnType(ResultSetMetaData.java:275) at com.mysql.jdbc.MysqlParameterMetadata.getParameterType(MysqlParameterMetadata.java:80) at org.apache.commons.dbutils.AbstractQueryRunner.fillStatement(AbstractQueryRunner.java:197) at org.apache.commons.dbutils.QueryRunner.update(QueryRunner.java:485) at org.apache.commons.dbutils.QueryRunner.update(QueryRunner.java:402) at com.local.dao.OrderDaoImpl.add2Order(OrderDaoImpl.java:19) at com.local.service.OrderServiceImpl.add(OrderServiceImpl.java:28) at com.local.web.servlet.OrderServlet.add(OrderServlet.java:82) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at com.local.web.servlet.BaseServlet.service(BaseServlet.java:36) at javax.servlet.http.HttpServlet.service(HttpServlet.java:727) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at com.local.web.filter.EncodingFilter.doFilter(EncodingFilter.java:36) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:315) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source) java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at com.local.web.servlet.BaseServlet.service(BaseServlet.java:36) at javax.servlet.http.HttpServlet.service(HttpServlet.java:727) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at com.local.web.filter.EncodingFilter.doFilter(EncodingFilter.java:36) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:315) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source) Caused by: java.lang.NullPointerException at com.mysql.jdbc.ResultSetMetaData.getField(ResultSetMetaData.java:397) at com.mysql.jdbc.ResultSetMetaData.getColumnType(ResultSetMetaData.java:275) at com.mysql.jdbc.MysqlParameterMetadata.getParameterType(MysqlParameterMetadata.java:80) at org.apache.commons.dbutils.AbstractQueryRunner.fillStatement(AbstractQueryRunner.java:197) at org.apache.commons.dbutils.QueryRunner.update(QueryRunner.java:485) at org.apache.commons.dbutils.QueryRunner.update(QueryRunner.java:402) at com.local.dao.OrderDaoImpl.add2Order(OrderDaoImpl.java:19) at com.local.service.OrderServiceImpl.add(OrderServiceImpl.java:28) at com.local.web.servlet.OrderServlet.add(OrderServlet.java:82) ... 28 more 七月 08, 2017 12:01:24 下午 org.apache.catalina.core.StandardWrapperValve invoke 严重: Servlet.service() for servlet [OrderServlet] in context with path [/store] threw exception java.lang.RuntimeException at com.local.web.servlet.BaseServlet.service(BaseServlet.java:44) at javax.servlet.http.HttpServlet.service(HttpServlet.java:727) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at com.local.web.filter.EncodingFilter.doFilter(EncodingFilter.java:36) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:315) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source) com.local.web.servlet.OrderServlet@8bc0b9 add 我用debug方式看了看了下order在dao用dbutils插入时的数据,数据是封装进去的,就name,address,phone,三项没有封装。并已经接图。以前在mysql中插入数据页是可以插入空数值的, 为何会报NullPointerException,困扰了好些时候了,各位大神有时间的话帮着看一下呀!
java发Email 异常 连接失败
代码大致如下 //发邮件 Properties pros = new Properties(); pros.load(this.getClass().getClassLoader().getResourceAsStream("email_template.properties")); String host = pros.getProperty("host");//获取主机 String uname = pros.getProperty("uname");//获取用户名 String pwd = pros.getProperty("pwd");//获取密码 String from = pros.getProperty("from");//获取发件人 String to = email;; String subject = pros.getProperty("subject");//主题 String content = pros.getProperty("content");//邮件内容 content = MessageFormat.format(content, form.getCode());//替换激活码 Session session = MailUtils.createSession(host, uname, pwd);//得到session Mail mail = new Mail(from, to, subject, content);//创建邮件对象 try { MailUtils.send(session, mail); } catch (MessagingException e) { // TODO Auto-generated catch block throw new RuntimeException(e); } 抛出500异常 严重: Servlet.service() for servlet [UserServlet] in context with path [/bookstore] threw exception java.lang.RuntimeException: java.lang.reflect.InvocationTargetException at cn.itcast.servlet.BaseServlet.service(BaseServlet.java:61) at javax.servlet.http.HttpServlet.service(HttpServlet.java:729) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:617) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:668) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1521) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1478) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:745) Caused by: java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at cn.itcast.servlet.BaseServlet.service(BaseServlet.java:45) ... 22 more Caused by: java.lang.RuntimeException: javax.mail.AuthenticationFailedException: failed to connect at cn.itcast.bookstore.user.web.servlet.UserServlet.regist(UserServlet.java:111) ... 27 more Caused by: javax.mail.AuthenticationFailedException: failed to connect at javax.mail.Service.connect(Service.java:322) at javax.mail.Service.connect(Service.java:172) at javax.mail.Service.connect(Service.java:121) at javax.mail.Transport.send0(Transport.java:190) at javax.mail.Transport.send(Transport.java:120) at cn.itcast.mail.MailUtils.send(MailUtils.java:91) at cn.itcast.bookstore.user.web.servlet.UserServlet.regist(UserServlet.java:108) ... 27 more 代码把传智的赋值过来也是一样 大概意思就是 链接失败 邮箱也开通了stmp服务 求大神解答
int类型转换成User对象类型报错问题
想询问一下大佬们,出现了Integer转换成User对象报错的问题代码如下 ``` private void UserUpdate(HttpServletRequest req, HttpServletResponse resp) throws IOException { //获取数据 String pwd=req.getParameter("pwd"); //从session中获取用户信息//下面的User的转换出了问题 User u=(User) req.getSession().getAttribute("servlet"); int uid=u.getUid(); //调用service处理 int index=us.Update(pwd,uid); System.out.println("index="+index); if(index>0){ //获取session对象 HttpSession hs=req.getSession(); hs.setAttribute("pwd","true"); //重定向到登录页面 resp.sendRedirect("/Login.jsp"); } —————————————————————————————————————————————————————— : Servlet.service() for servlet [servlet] in context with path [/New] threw exception java.lang.ClassCastException: java.lang.Integer cannot be cast to com.cwj.pojo.User at com.cwj.servlet.UserServlet.UserUpdate(UserServlet.java:88) at com.cwj.servlet.UserServlet.service(UserServlet.java:41) at javax.servlet.http.HttpServlet.service(HttpServlet.java:731) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.logging.log4j.core.web.Log4jServletFilter.doFilter(Log4jServletFilter.java:66) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:110) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:494) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:1025) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:445) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1137) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:637) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:319) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:748) ```
org.apache.ibatis.reflection.ReflectionException:
这个报错什么意思? 十二月 23, 2016 9:31:15 上午 org.apache.catalina.core.StandardWrapperValve invoke 严重: Servlet.service() for servlet [spring-dispatcher] in context with path [/JFWorkingHourSystem] threw exception [Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'page' in 'class java.lang.Long'] with root cause org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'page' in 'class java.lang.Long' at org.apache.ibatis.reflection.Reflector.getGetInvoker(Reflector.java:377) at org.apache.ibatis.reflection.MetaClass.getGetInvoker(MetaClass.java:167) at org.apache.ibatis.reflection.wrapper.BeanWrapper.getBeanProperty(BeanWrapper.java:149) at org.apache.ibatis.reflection.wrapper.BeanWrapper.get(BeanWrapper.java:45) at org.apache.ibatis.reflection.MetaObject.getValue(MetaObject.java:113) at org.apache.ibatis.scripting.xmltags.DynamicContext$ContextMap.get(DynamicContext.java:94) at org.apache.ibatis.scripting.xmltags.DynamicContext$ContextAccessor.getProperty(DynamicContext.java:113) at ognl.OgnlRuntime.getProperty(OgnlRuntime.java:2317) at ognl.ASTProperty.getValueBody(ASTProperty.java:114) at ognl.SimpleNode.evaluateGetValueBody(SimpleNode.java:212) at ognl.SimpleNode.getValue(SimpleNode.java:258) at ognl.ASTNotEq.getValueBody(ASTNotEq.java:50) at ognl.SimpleNode.evaluateGetValueBody(SimpleNode.java:212) at ognl.SimpleNode.getValue(SimpleNode.java:258) at ognl.Ognl.getValue(Ognl.java:494) at ognl.Ognl.getValue(Ognl.java:644) at ognl.Ognl.getValue(Ognl.java:619) at org.apache.ibatis.scripting.xmltags.OgnlCache.getValue(OgnlCache.java:45) at org.apache.ibatis.scripting.xmltags.ExpressionEvaluator.evaluateBoolean(ExpressionEvaluator.java:29) at org.apache.ibatis.scripting.xmltags.IfSqlNode.apply(IfSqlNode.java:30) at org.apache.ibatis.scripting.xmltags.MixedSqlNode.apply(MixedSqlNode.java:29) at org.apache.ibatis.scripting.xmltags.DynamicSqlSource.getBoundSql(DynamicSqlSource.java:37) at org.apache.ibatis.mapping.MappedStatement.getBoundSql(MappedStatement.java:275) at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:79) at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:104) at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:98) at org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:62) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:358) at com.sun.proxy.$Proxy19.selectOne(Unknown Source) at org.mybatis.spring.SqlSessionTemplate.selectOne(SqlSessionTemplate.java:163) at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:63) at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:43) at com.sun.proxy.$Proxy30.selectByPrimaryKey(Unknown Source) at com.bjhnd.Service.TiZhiCeDingJiYunDongChuFang.Impl.JiBenXinXiServiceImpl.GetJiBenXinXi(JiBenXinXiServiceImpl.java:41) at com.bjhnd.Actions.TiZhiCeDingJiYunDongChuFang.JiBenXinXiAction.GetJiBenXinXi(JiBenXinXiAction.java:22) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:215) at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132) at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:749) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:689) at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:83) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:938) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:870) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961) at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:863) at javax.servlet.http.HttpServlet.service(HttpServlet.java:648) at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837) at javax.servlet.http.HttpServlet.service(HttpServlet.java:729) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.logging.log4j.core.web.Log4jServletFilter.doFilter(Log4jServletFilter.java:66) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:617) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:668) at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2503) at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2492) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:745)![图片说明](https://img-ask.csdn.net/upload/201612/23/1482457163_773794.png) 我想要获取当前新用户的ID,查询他的信息。
shiro添加了sessionDAO如果不进登陆页面就会报错,不能进行拦截跳转
``` 严重: Servlet.service() for servlet [com.hhwy.fweb.framework.mvc.MainDispather] in context with path [/security] threw exception [javax.servlet.ServletException: java.lang.IllegalStateException: Cannot create a session after the response has been committed] with root cause java.lang.IllegalStateException: Cannot create a session after the response has been committed at org.apache.catalina.connector.Request.doGetSession(Request.java:3030) at org.apache.catalina.connector.Request.getSession(Request.java:2468) at org.apache.catalina.connector.RequestFacade.getSession(RequestFacade.java:896) at javax.servlet.http.HttpServletRequestWrapper.getSession(HttpServletRequestWrapper.java:231) at org.apache.catalina.core.ApplicationHttpRequest.getSession(ApplicationHttpRequest.java:571) at org.apache.catalina.core.ApplicationHttpRequest.getSession(ApplicationHttpRequest.java:542) at javax.servlet.http.HttpServletRequestWrapper.getSession(HttpServletRequestWrapper.java:240) at javax.servlet.http.HttpServletRequestWrapper.getSession(HttpServletRequestWrapper.java:240) at org.apache.jasper.runtime.PageContextImpl.initialize(PageContextImpl.java:137) at org.apache.jasper.runtime.JspFactoryImpl.internalGetPageContext(JspFactoryImpl.java:109) at org.apache.jasper.runtime.JspFactoryImpl.getPageContext(JspFactoryImpl.java:60) at org.apache.jsp.WEB_002dINF.classes.META_002dINF.resources.WEB_002dINF.jsp.ac.index_jsp._jspService(index_jsp.java:100) at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) at javax.servlet.http.HttpServlet.service(HttpServlet.java:742) at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:476) at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:386) at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:330) at javax.servlet.http.HttpServlet.service(HttpServlet.java:742) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:728) at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:591) at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:527) at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:162) at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:314) at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1325) at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1069) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1008) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:925) at com.hhwy.fweb.framework.mvc.MainDispather.doService(MainDispather.java:95) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:978) at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:870) at javax.servlet.http.HttpServlet.service(HttpServlet.java:635) at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:855) at javax.servlet.http.HttpServlet.service(HttpServlet.java:742) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at com.hhwy.fweb.framework.mvc.filter.LandFilter.doFilter(LandFilter.java:42) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at com.hhwy.fweb.framework.mvc.filter.CommonFilter.doFilter(CommonFilter.java:32) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:493) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81) at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:650) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342) at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:800) at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:806) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1498) at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:745) ``` 下面是session的配置 ``` <bean id="sessionDAO" class="org.apache.shiro.session.mgt.eis.MemorySessionDAO"/> <bean id="sessionManager" class="org.apache.shiro.web.session.mgt.DefaultWebSessionManager"> <property name="sessionDAO" ref="sessionDAO"/> </bean> <bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager"> <property name="realm" ref="acRealm"></property> <property name="rememberMeManager" ref="rememberMeManager" /> <!-- 定义要使用的缓存管理器 --> <property name="cacheManager" ref="shiroCacheManager"/> <property name="sessionManager" ref="sessionManager" /> </bean> ``` 而且为什么登陆进去之后通过sessionDAO.getActiveSessions获取在线用户,会获取到很多个session(只有我一个人登陆),不关闭浏览器多次退出登陆和登陆还会增加session,求大神解答 重点是上面的错误怎么解决啊,大神们TAT
大学四年自学走来,这些私藏的实用工具/学习网站我贡献出来了
大学四年,看课本是不可能一直看课本的了,对于学习,特别是自学,善于搜索网上的一些资源来辅助,还是非常有必要的,下面我就把这几年私藏的各种资源,网站贡献出来给你们。主要有:电子书搜索、实用工具、在线视频学习网站、非视频学习网站、软件下载、面试/求职必备网站。 注意:文中提到的所有资源,文末我都给你整理好了,你们只管拿去,如果觉得不错,转发、分享就是最大的支持了。 一、电子书搜索 对于大部分程序员...
【JSON解析】浅谈JSONObject的使用
简介 在程序开发过程中,在参数传递,函数返回值等方面,越来越多的使用JSON。JSON(JavaScript Object Notation)是一种轻量级的数据交换格式,同时也易于机器解析和生成、易于理解、阅读和撰写,而且Json采用完全独立于语言的文本格式,这使得Json成为理想的数据交换语言。 JSON建构于两种结构: “名称/值”对的集合(A Collection of name/va...
程序员请照顾好自己,周末病魔差点一套带走我。
程序员在一个周末的时间,得了重病,差点当场去世,还好及时挽救回来了。
卸载 x 雷某度!GitHub 标星 1.5w+,从此我只用这款全能高速下载工具!
作者 | Rocky0429 来源 | Python空间 大家好,我是 Rocky0429,一个喜欢在网上收集各种资源的蒟蒻… 网上资源眼花缭乱,下载的方式也同样千奇百怪,比如 BT 下载,磁力链接,网盘资源等等等等,下个资源可真不容易,不一样的方式要用不同的下载软件,因此某比较有名的 x 雷和某度网盘成了我经常使用的工具。 作为一个没有钱的穷鬼,某度网盘几十 kb 的下载速度让我...
只因接了一个电话,程序员被骗 30 万!
今天想给大家说一个刚刚发生在我身边的一起真实的诈骗经历,我的朋友因此被骗走30万。注:为了保护当事人隐私,部分情节进行了修改。1平安夜突来的电话开始以为就像普通的诈骗一样,想办法让你把钱...
我一个37岁的程序员朋友
周末了,人一旦没有点事情干,心里就瞎想,而且跟几个老男人坐在一起,更容易瞎想,我自己现在也是 30 岁了,也是无时无刻在担心自己的职业生涯,担心丢掉工作没有收入,担心身体机能下降,担心突...
python自动下载图片
近日闲来无事,总有一种无形的力量萦绕在朕身边,让朕精神涣散,昏昏欲睡。 可是,像朕这么有职业操守的社畜怎么能在上班期间睡瞌睡呢,我不禁陷入了沉思。。。。 突然旁边的IOS同事问:‘嘿,兄弟,我发现一个网站的图片很有意思啊,能不能帮我保存下来提升我的开发灵感?’ 作为一个坚强的社畜怎么能说自己不行呢,当时朕就不假思索的答应:‘oh, It’s simple. Wait for me for a ...
一名大专同学的四个问题
【前言】   收到一封来信,赶上各种事情拖了几日,利用今天要放下工作的时机,做个回复。   2020年到了,就以这一封信,作为开年标志吧。 【正文】   您好,我是一名现在有很多困惑的大二学生。有一些问题想要向您请教。   先说一下我的基本情况,高考失利,不想复读,来到广州一所大专读计算机应用技术专业。学校是偏艺术类的,计算机专业没有实验室更不用说工作室了。而且学校的学风也不好。但我很想在计算机领...
复习一周,京东+百度一面,不小心都拿了Offer
京东和百度一面都问了啥,面试官百般刁难,可惜我全会。
Java 14 都快来了,为什么还有这么多人固守Java 8?
从Java 9开始,Java版本的发布就让人眼花缭乱了。每隔6个月,都会冒出一个新版本出来,Java 10 , Java 11, Java 12, Java 13, 到2020年3月份,...
达摩院十大科技趋势发布:2020 非同小可!
【CSDN编者按】1月2日,阿里巴巴发布《达摩院2020十大科技趋势》,十大科技趋势分别是:人工智能从感知智能向认知智能演进;计算存储一体化突破AI算力瓶颈;工业互联网的超融合;机器间大规模协作成为可能;模块化降低芯片设计门槛;规模化生产级区块链应用将走入大众;量子计算进入攻坚期;新材料推动半导体器件革新;保护数据隐私的AI技术将加速落地;云成为IT技术创新的中心 。 新的画卷,正在徐徐展开。...
轻松搭建基于 SpringBoot + Vue 的 Web 商城应用
首先介绍下在本文出现的几个比较重要的概念: 函数计算(Function Compute): 函数计算是一个事件驱动的服务,通过函数计算,用户无需管理服务器等运行情况,只需编写代码并上传。函数计算准备计算资源,并以弹性伸缩的方式运行用户代码,而用户只需根据实际代码运行所消耗的资源进行付费。Fun: Fun 是一个用于支持 Serverless 应用部署的工具,能帮助您便捷地管理函数计算、API ...
讲真,这两个IDE插件,可以让你写出质量杠杠的代码
周末躺在床上看《拯救大兵瑞恩》 周末在闲逛的时候,发现了两个优秀的 IDE 插件,据说可以提高代码的质量,我就安装了一下,试了试以后发现,确实很不错,就推荐给大家。 01、Alibaba Java 代码规范插件 《阿里巴巴 Java 开发手册》,相信大家都不会感到陌生,其 IDEA 插件的下载次数据说达到了 80 万次,我今天又贡献了一次。嘿嘿。 该项目的插件地址: https://github....
Python+OpenCV实时图像处理
目录 1、导入库文件 2、设计GUI 3、调用摄像头 4、实时图像处理 4.1、阈值二值化 4.2、边缘检测 4.3、轮廓检测 4.4、高斯滤波 4.5、色彩转换 4.6、调节对比度 5、退出系统 初学OpenCV图像处理的小伙伴肯定对什么高斯函数、滤波处理、阈值二值化等特性非常头疼,这里给各位分享一个小项目,可通过摄像头实时动态查看各类图像处理的特点,也可对各位调参、测试...
2020年一线城市程序员工资大调查
人才需求 一线城市共发布岗位38115个,招聘120827人。 其中 beijing 22805 guangzhou 25081 shanghai 39614 shenzhen 33327 工资分布 2020年中国一线城市程序员的平均工资为16285元,工资中位数为14583元,其中95%的人的工资位于5000到20000元之间。 和往年数据比较: yea...
为什么猝死的都是程序员,基本上不见产品经理猝死呢?
相信大家时不时听到程序员猝死的消息,但是基本上听不到产品经理猝死的消息,这是为什么呢? 我们先百度搜一下:程序员猝死,出现将近700多万条搜索结果: 搜索一下:产品经理猝死,只有400万条的搜索结果,从搜索结果数量上来看,程序员猝死的搜索结果就比产品经理猝死的搜索结果高了一倍,而且从下图可以看到,首页里面的五条搜索结果,其实只有两条才是符合条件。 所以程序员猝死的概率真的比产品经理大,并不是错...
害怕面试被问HashMap?这一篇就搞定了!
声明:本文以jdk1.8为主! 搞定HashMap 作为一个Java从业者,面试的时候肯定会被问到过HashMap,因为对于HashMap来说,可以说是Java集合中的精髓了,如果你觉得自己对它掌握的还不够好,我想今天这篇文章会非常适合你,至少,看了今天这篇文章,以后不怕面试被问HashMap了 其实在我学习HashMap的过程中,我个人觉得HashMap还是挺复杂的,如果真的想把它搞得明明白...
毕业5年,我问遍了身边的大佬,总结了他们的学习方法
我问了身边10个大佬,总结了他们的学习方法,原来成功都是有迹可循的。
python爬取百部电影数据,我分析出了一个残酷的真相
2019年就这么匆匆过去了,就在前几天国家电影局发布了2019年中国电影市场数据,数据显示去年总票房为642.66亿元,同比增长5.4%;国产电影总票房411.75亿元,同比增长8.65%,市场占比 64.07%;城市院线观影人次17.27亿,同比增长0.64%。 看上去似乎是一片大好对不对?不过作为一名严谨求实的数据分析师,我从官方数据中看出了一点端倪:国产票房增幅都已经高达8.65%了,为什...
推荐10个堪称神器的学习网站
每天都会收到很多读者的私信,问我:“二哥,有什么推荐的学习网站吗?最近很浮躁,手头的一些网站都看烦了,想看看二哥这里有什么新鲜货。” 今天一早做了个恶梦,梦到被老板辞退了。虽然说在我们公司,只有我辞退老板的份,没有老板辞退我这一说,但是还是被吓得 4 点多都起来了。(主要是因为我掌握着公司所有的核心源码,哈哈哈) 既然 4 点多起来,就得好好利用起来。于是我就挑选了 10 个堪称神器的学习网站,推...
这些软件太强了,Windows必装!尤其程序员!
Windows可谓是大多数人的生产力工具,集娱乐办公于一体,虽然在程序员这个群体中都说苹果是信仰,但是大部分不都是从Windows过来的,而且现在依然有很多的程序员用Windows。 所以,今天我就把我私藏的Windows必装的软件分享给大家,如果有一个你没有用过甚至没有听过,那你就赚了????,这可都是提升你幸福感的高效率生产力工具哦! 走起!???? NO、1 ScreenToGif 屏幕,摄像头和白板...
阿里面试,面试官没想到一个ArrayList,我都能跟他扯半小时
我是真的没想到,面试官会这样问我ArrayList。
曾经优秀的人,怎么就突然不优秀了。
职场上有很多辛酸事,很多合伙人出局的故事,很多技术骨干被裁员的故事。说来模板都类似,曾经是名校毕业,曾经是优秀员工,曾经被领导表扬,曾经业绩突出,然而突然有一天,因为种种原因,被裁员了,...
大学四年因为知道了这32个网站,我成了别人眼中的大神!
依稀记得,毕业那天,我们导员发给我毕业证的时候对我说“你可是咱们系的风云人物啊”,哎呀,别提当时多开心啦????,嗯,我们导员是所有导员中最帅的一个,真的???? 不过,导员说的是实话,很多人都叫我大神的,为啥,因为我知道这32个网站啊,你说强不强????,这次是绝对的干货,看好啦,走起来! PS:每个网站都是学计算机混互联网必须知道的,真的牛杯,我就不过多介绍了,大家自行探索,觉得没用的,尽管留言吐槽吧???? 社...
良心推荐,我珍藏的一些Chrome插件
上次搬家的时候,发了一个朋友圈,附带的照片中不小心暴露了自己的 Chrome 浏览器插件之多,于是就有小伙伴评论说分享一下我觉得还不错的浏览器插件。 我下面就把我日常工作和学习中经常用到的一些 Chrome 浏览器插件分享给大家,随便一个都能提高你的“生活品质”和工作效率。 Markdown Here Markdown Here 可以让你更愉快的写邮件,由于支持 Markdown 直接转电子邮...
【程序人生】程序员接私活常用平台汇总
00. 目录 文章目录00. 目录01. 前言02. 程序员客栈03. 码市04. 猪八戒网05. 开源众包06. 智城外包网07. 实现网08. 猿急送09. 人人开发10. 开发邦11. 电鸭社区12. 快码13. 英选14. Upwork15. Freelancer16. Dribbble17. Remoteok18. Toptal19. AngelList20. Topcoder21. ...
看完这篇HTTP,跟面试官扯皮就没问题了
我是一名程序员,我的主要编程语言是 Java,我更是一名 Web 开发人员,所以我必须要了解 HTTP,所以本篇文章就来带你从 HTTP 入门到进阶,看完让你有一种恍然大悟、醍醐灌顶的感觉。 最初在有网络之前,我们的电脑都是单机的,单机系统是孤立的,我还记得 05 年前那会儿家里有个电脑,想打电脑游戏还得两个人在一个电脑上玩儿,及其不方便。我就想为什么家里人不让上网,我的同学 xxx 家里有网,每...
史上最全的IDEA快捷键总结
现在Idea成了主流开发工具,这篇博客对其使用的快捷键做了总结,希望对大家的开发工作有所帮助。
阿里程序员写了一个新手都写不出的低级bug,被骂惨了。
这种新手都不会范的错,居然被一个工作好几年的小伙子写出来,差点被当场开除了。
谁是华为扫地僧?
是的,华为也有扫地僧!2020年2月11-12日,“养在深闺人不知”的华为2012实验室扫地僧们,将在华为开发者大会2020(Cloud)上,和大家见面。到时,你可以和扫地僧们,吃一个洋...
Idea 中最常用的10款插件(提高开发效率),一定要学会使用!
学习使用一些插件,可以提高开发效率。对于我们开发人员很有帮助。这篇博客介绍了开发中使用的插件。
立即提问