Java的捕获异常问题 try finally

public class Test {

/**
 * @param args add by zxx ,Dec 9, 2008
 */
public static void main(String[] args) {
    // TODO Auto-generated method stub
    System.out.println(new Test().test());
}

static int test()
{
    int x = 1;
    try
    {
        return x;
    }
    finally
    {
        ++x;
    }
}

}
运行结果是:1

不是说finally在return之前执行吗?

5个回答

finally是先执行,但是返回的是之前x,因为x作为返回值已经放在计算栈上了。所以不要在finally写side effect的代码

…你自己试过也应该知道,try里面有return,则finally会在return后执行。

Java中try-catch-finally(或者try-finally)结构的执行顺序是:

try块先执行,如果抛出异常,相应catch块执行,finally块总是最后执行

题中代码执行顺序如下:

1 进入try块
2 设置函数返回值为1
3 进入Finally块
4 自增x.
5 退出函数,并返回之前设置的返回值1

return语句也是表达式语句,其值(即函数的返回值)在第2步已经确定。

Java在执行finally之前,会记录try或者catch分支中需要返回值的地址,然后执行finally分支,最后才是return那个地址的值。
所以,Java编译器会建议不要在finally里面操作返回值,因为会对影响真实的返回值的。

自己Debug看,就知道了嘛,最终如二楼所说!

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
Java异常处理中居然有个try-finally????

一般都是try-catch,或者try-catch-finally,突然发现还有try 后面直接跟finally?????,这种try-finally有什么适用场景呢????

java 异常 try catch throw

java 中 try {throw1...}catch {throw2...}finally{throw3...}, 请帮忙解释一下上述简易代码如何执行

Java关于在catch中抛出一个异常给外围函数却捕获不到的问题

先给出一串代码: package javaException; public class TestException { public TestException(){ } boolean testEx()throws Exception{ boolean ret=true; try{ ret=testEx1(); } catch(Exception e){ System.out.println("testEx, catch exception"); ret=false; throw e; } finally{ System.out.println("testEx, finally:return value:"+ret); return ret; } } boolean testEx1()throws Exception{ boolean ret=true; try{ ret=testEx2(); if(!ret){ return false; } System.out.println("testEx1, at the end of try"); return ret; } catch(Exception e){ System.out.println("testEx1, catch exception"); ret=false; throw e; } finally{ System.out.println("testEx1, finally:return value:"+ret); return ret; } } boolean testEx2()throws Exception{ boolean ret=true; try{ int b=12; int c; for(int i=2;i>=-2;i--){ c=b/i; System.out.println("i="+i); } return true; } catch(Exception e){ System.out.println("testEx2, catch exception"); ret=false; throw e; } finally { System.out.println("testEx2, finally:return value="+ret); return ret; } } public static void main(String[] args) { // TODO Auto-generated method stub TestException testException1=new TestException(); try{ testException1.testEx(); } catch(Exception e){ e.printStackTrace(); } } } 对于函数testEx2()中catch块中抛出的异常,testEx1()函数却捕获不到,这是为什么呢? 我想过一种可能:testEx1()中将testEx2()的返回值赋值给ret,即 ret=testEx2(),而testEx2()中抛出的异常在这个过程中被过滤掉了。因为如果我直接把testEx2()放在testEx1()中,而不是通过ret=testEx2()的方式,那么这个异常是能够被捕获的。 求证各位大佬!!!

java中的try-catch-finally中的问题

就是在java中,比如要求两个数的余数的简单例子。 public class task2 { public static void main(String args[]) { Scanner s=new Scanner(System.in); int a,b,c; try { while(true) { a=s.nextInt(); b=s.nextInt(); c=a%b; System.out.println("余数为:"+c); } } catch (Exception e) { System.out.println("输入有误,请重新输入,只能输入数字,并且除数不能为0"); } } } 这样只能是在输入正确的情况下,不断地输入,如果捕获了异常,就不能继续输入, 不要说while()放外面,因为while()循环的是数据,而不是一直捕获异常~~ 求大神帮助~~~

java中mysql的异常 ,求助

异常如下: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'sum(money,time,nature)value(50000.0,'2019-11-08 15:15:46','购买车位')' at line 1 at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) at java.lang.reflect.Constructor.newInstance(Unknown Source) at com.mysql.jdbc.Util.handleNewInstance(Util.java:425) at com.mysql.jdbc.Util.getInstance(Util.java:408) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:944) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3933) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3869) at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2524) at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2675) at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2465) at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1912) at com.mysql.jdbc.PreparedStatement.executeUpdateInternal(PreparedStatement.java:2133) at com.mysql.jdbc.PreparedStatement.executeUpdateInternal(PreparedStatement.java:2067) at com.mysql.jdbc.PreparedStatement.executeLargeUpdate(PreparedStatement.java:5175) at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2052) at shujuku.insert_money.<init>(insert_money.java:26) at car_people.pe_add$1.actionPerformed(pe_add.java:182) at javax.swing.AbstractButton.fireActionPerformed(Unknown Source) at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source) at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source) at javax.swing.DefaultButtonModel.setPressed(Unknown Source) at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source) at java.awt.Component.processMouseEvent(Unknown Source) at javax.swing.JComponent.processMouseEvent(Unknown Source) at java.awt.Component.processEvent(Unknown Source) at java.awt.Container.processEvent(Unknown Source) at java.awt.Component.dispatchEventImpl(Unknown Source) at java.awt.Container.dispatchEventImpl(Unknown Source) at java.awt.Component.dispatchEvent(Unknown Source) at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source) at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source) at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source) at java.awt.Container.dispatchEventImpl(Unknown Source) at java.awt.Window.dispatchEventImpl(Unknown Source) at java.awt.Component.dispatchEvent(Unknown Source) at java.awt.EventQueue.dispatchEventImpl(Unknown Source) at java.awt.EventQueue.access$500(Unknown Source) at java.awt.EventQueue$3.run(Unknown Source) at java.awt.EventQueue$3.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source) at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source) at java.awt.EventQueue$4.run(Unknown Source) at java.awt.EventQueue$4.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source) at java.awt.EventQueue.dispatchEvent(Unknown Source) at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source) at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source) at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.run(Unknown Source) 源代码: package shujuku; import java.sql.*; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; public class insert_money { String sq5 = "insert into sum(money,time,nature)"+"value(?,?,?)"; Calendar calendar = Calendar.getInstance(); long int_time_js = calendar.getTimeInMillis(); Date aaaaa = calendar.getTime(); SimpleDateFormat sdf3 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String in_time, xingzi; double mm; public insert_money(double money,String sss) { Connection conn = new shujuku().getConnection(); mm = money; xingzi = sss; in_time = sdf3.format(aaaaa); try { PreparedStatement ps = conn.prepareStatement(sq5); ps.setDouble(1,mm); ps.setString(2,in_time); ps.setString(3,xingzi); ps.executeUpdate(); ps.close(); }catch (Exception e1) { e1.printStackTrace(); }finally{ // 关闭数据库连接 shujuku.closeConnection(conn); } } }

java多线程终止执行,没有执行ffinally

在一个线程的run方法中,有 try{ 处理1 }catch(Exception e){ 处理2 }ffinally{ 处理3 } 处理1调用了别的方法A,在生产环境中发现这个方法A在循环中抛了三次网络连接超时错误,A中也捕获了异常,记录了日志,但是就到此处,就发现线程没有执行后面的动作了,ffinally中的处理3也没有执行(通过日志)

jsp过滤器异常捕获不到的问题

项目采用struts2,java原生sql ,在action中定义如下方法: //添加客户 public String addGuest() throws Exception{ XsKhxx xsKhxx=new XsKhxx(); xsKhxx.setKhbh(this.khbh); xsKhxx.setXm(this.xm); xsKhxx.setXb(this.xb); xsKhxx.setNl(this.nl); //添加客户成功后返回客户编号 String khbh=this.xsKhxxService.saveGuest(xsKhxx); // int i=9/0;//会抛出异常来测试过滤器的捕获 this.result.setSuccess(true); this.result.setMsg(khbh); return SUCCESS; }; 过滤器中 //过滤事务 public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { try { chain.doFilter(request, response);//我的理解这里应该有异常发生 Connection connection = ConnectionUtil.getCurrentConnection(); if (connection != null) { //if (!connection.getAutoCommit()) { connection.commit(); //} System.out.println("正在手动提交事务 "); } } catch (Exception e) { System.out.println("出现异常了");//为什么这里根本不会执行,也就是说上面的try没有捕获异常。明明有异常,这是为什么呢? try { logger.error("Exception: " + e); Connection connection = ConnectionUtil.getCurrentConnection(); if (connection != null) { //if (!connection.getAutoCommit()) { connection.rollback(); //} //只有用到connection 时再需要回滚事务。 System.out.println("事务回滚"); } } catch (Exception ex) { ex.printStackTrace(); System.out.println("事务回滚时发生错误"); } //重新包装抛出 throw new RuntimeException(e); } finally { ConnectionUtil.closeCurrentConnectionIfNotNull(); } 异常抛出是这样的: 事务自动提交正在关闭,正在修改为手动提交 事务开始 insert into xs_khxx (khbh,xm,xb,nl,sr,zz,dh,yb,e_mail,icid,hyjf) values('008','008','1',8,'2016-01-22 00:00:00.0','8','8','8','8','008',80) 09:15:45,962 [http-bio-8080-exec-3] ERROR CommonsLogger : Exception occurred during processing request: / by zero java.lang.ArithmeticException: / by zero at com.bass.dbglass.action.XsKhxxAction.addGuest(XsKhxxAction.java:111) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:450) at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:289) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:252) at org.apache.struts2.interceptor.DeprecationInterceptor.intercept(DeprecationInterceptor.java:41) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) at org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:256) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:167) at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:265) at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68) at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:138) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:254) at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:254) at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:191) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) at org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:73) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:91) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) at org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:252) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) at com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:100) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) at com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:141) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) at com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:145) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) at com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:171) at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) at com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:139) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:193) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:189) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:54) at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:562) at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77) at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:99) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at com.bass.dbglass.filter.ConnectionFilter.doFilter(ConnectionFilter.java:27) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at com.bass.dbglass.filter.SetEncodingFilter.doFilter(SetEncodingFilter.java:26) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:999) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:565) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:309) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) at java.lang.Thread.run(Thread.java:619) 正在手动提交事务 并没有在过滤器中被捕获。 请高手指点一下?

关于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对象连接都断开了。求教大神们有没有什么靠谱的解决办法

[java新手] IO和网络编程的问题

做网络编程的练习,用socket连接 传输文件,目的是把一个文件传到服务端保存下来 测试结果完全正常,文件也传输完成,但是catch捕捉到了异常???! 当运行服务端时候客户端catch报错,当运行客户端时候服务端catch报错 0.0 代码如下 修改了下代码,我把输出换成e.printStackTrace()打印了,还是这样 结果是实现了的,测试通过,但是有捕获到异常 ``` import java.io.*; import java.net.InetAddress; import java.net.ServerSocket; import java.net.Socket; import org.junit.Test; public class 网络编程_上传 { public static String ClientInteAddress = "127.0.0.1"; public static String str = "9000"; public static String ServerFileAddress = "E:\\111.xls"; public static String ClientFileAddress = "D:\\15916\\下载\\111.xls"; @Test//服务器 public void server() { ServerSocket sss = null; Socket sk = null; InputStream is = null; BufferedInputStream bis = null; FileOutputStream fos = null; try { sss = new ServerSocket(new Integer(str)); sk = sss.accept(); is = sk.getInputStream(); bis = new BufferedInputStream(is); fos = new FileOutputStream(ServerFileAddress); int buffi = 0; byte [] by = new byte[1024]; while ((buffi = bis.read(by)) != -1) { fos.write(by); } fos.close(); bis.close(); sk.close(); sss.close(); } catch (IOException e) { e.printStackTrace(); } finally { try { if (fos != null) {fos.close();} if (bis != null) bis.close(); if (sk != null) sk.close(); if (sss != null) sss.close(); } catch (IOException e) { System.out.println("服务器报错啦!:关闭流出错"); } } } @Test//客户端 public void client() { Socket sk = null; OutputStream os = null; BufferedOutputStream bos = null; FileInputStream fis = null; try { sk = new Socket(InetAddress.getByName(ClientInteAddress), new Integer(str)); os = sk.getOutputStream(); bos = new BufferedOutputStream(os); fis = new FileInputStream(ClientFileAddress); int buffi = 0; byte [] by = new byte[1024]; while ((buffi = fis.read(by)) != -1) { bos.write(by); } fis.close(); bos.close(); sk.close(); } catch (NumberFormatException | IOException e) { e.printStackTrace(); } finally { try { if (sk != null) sk.close(); if (fis != null) fis.close(); if (bos != null) bos.close(); } catch (IOException e) { System.out.println("客户端报错啦!:关闭流出错"); } } } } ```

为什这个处理异常的程序这么写不行?

package exercise_13; public class Exercise13_2 { /** * @param args */ public static void main(String[] args) { java.util.Scanner input=new java.util.Scanner(System.in); int num1 = 0,num2=0; System.out.println("Please enter two integers:"); try{ num1=input.nextInt(); }catch(Exception ex){ System.out.println("You num is wrong,please enter again"); input.nextInt(); }; try{ num2=input.nextInt(); }catch(Exception ex){ System.out.println("Wrong input,input again "); input.nextInt(); }; System.out.println(num1+num2); } } ``` ```

java调用存储过程时的错误

``` public static int getNum(){ Connection conn = null; CallableStatement cs =null; try { conn = JdbcUtils.getConnection(); cs = conn.prepareCall("{call getNum(?)}"); cs.registerOutParameter(1, Types.INTEGER); cs.execute(); int num = cs.getInt(1); return num; } catch (Exception e) { e.printStackTrace(); }finally { try { if(cs!=null){ cs.close(); } } catch (SQLException e) { e.printStackTrace(); } JdbcUtils.free(null, null, conn); } return 0; } ``` 这样写总是返回0,如果改成下面那样就对了,这是为什么 ``` Connection conn = null; CallableStatement cs =null; try { conn = JdbcUtils.getConnection(); cs = conn.prepareCall("{call getNum(?)}"); cs.registerOutParameter(1, Types.INTEGER); ResultSet result=cs.executeQuery(); int num = 0; if(result.next()){ num = result.getInt("num"); } return num; } catch (Exception e) { e.printStackTrace(); }finally { try { if(cs!=null){ cs.close(); } } catch (SQLException e) { e.printStackTrace(); } JdbcUtils.free(null, null, conn); } return 0; } ```

怎么解决java网络通信编程ip和port是从文本框中获取的?

为什么我把connect()方法加入button1的事件中就会黑屏 代码如下 客户端: package sunxu.util; import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.net.InetAddress; import java.net.Socket; import java.net.UnknownHostException; import javax.swing.BorderFactory; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTextArea; import javax.swing.JTextField; public class ClientSocketFrame extends JFrame { /** * */ private static final long serialVersionUID = 1L; private PrintWriter writer; // 声明PrintWriter类对象 private BufferedReader reader; // 声明BufferedReader对象 private Socket socket; // 声明Socket对象 private JTextArea ta_info; // 创建JtextArea对象 JButton button1 = new JButton("Connect"); //private JTextField tf_send; // 创建JtextField对象 private InetAddress sendIp; private int sendPort; private void connect() { // 连接套接字方法 ta_info.append("Connect to server…\n"); // 文本域中信息信息 try { // 捕捉异常 socket = new Socket(sendIp,sendPort); // 实例化Socket对象 while (true) { writer = new PrintWriter(socket.getOutputStream(), true); reader = new BufferedReader(new InputStreamReader(socket .getInputStream())); // 实例化BufferedReader对象 ta_info.append("Client connected…\n"); // 文本域中提示信息 getServerInfo(); } } catch (Exception e) { e.printStackTrace(); // 输出异常信息 } } public static void main(String[] args) { // 主方法 ClientSocketFrame clien = new ClientSocketFrame(); // 创建本例对象 clien.setVisible(true); // 将窗体显示 //clien.connect(); // 调用连接方法 } private void getServerInfo() { try { while (true) { if (reader != null) { String line = reader.readLine();// 读取服务器发送的信息 if (line != null) ta_info.append("接收到服务器发送的信息:" + line + "\n"); // 显示服务器端发送的信息 } } } catch (Exception e) { e.printStackTrace(); } finally { try { if (reader != null) { reader.close();// 关闭流 } if (socket != null) { socket.close(); // 关闭套接字 } } catch (IOException e) { e.printStackTrace(); } } } /** * Create the frame */ public ClientSocketFrame() { super(); setTitle("客户端"); setBounds(100, 100, 361, 257); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final JPanel panel = new JPanel(); getContentPane().add(panel, BorderLayout.NORTH); panel.setBorder(BorderFactory.createTitledBorder("客户机设置:")); final JLabel label = new JLabel(); label.setText("Server IP:"); panel.add(label); JTextField tf_sen= new JTextField(); tf_sen.setPreferredSize(new Dimension(50, 25)); panel.add(tf_sen); final JLabel label1 = new JLabel(); label1.setText("Server Port:"); panel.add(label1); JTextField tf_Port = new JTextField(); tf_Port.setPreferredSize(new Dimension(50, 25)); panel.add(tf_Port); final JButton button1 = new JButton("Connect"); button1.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent e) { try { sendIp=InetAddress.getByName(tf_sen.getText()); } catch (UnknownHostException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } sendPort=Integer.parseInt(tf_Port.getText()); ta_info.append("Connect to server…\n"); // 文本域中信息信息 ta_info.append(sendIp+"\n"); // 文本域中信息信息 ta_info.append(sendPort+"\n"); // 文本域中信息信息 connect(); } }); panel.add(button1); final JPanel panel_1 = new JPanel(); getContentPane().add(panel_1, BorderLayout.SOUTH); final JLabel label_1 = new JLabel(); label_1.setText("Say:"); panel_1.add(label_1); JTextField tf_send = new JTextField(); tf_send.setPreferredSize(new Dimension(220, 25)); panel_1.add(tf_send); final JButton button = new JButton(); button.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent e) { writer.println(tf_send.getText()); // 将文本框中信息写入流 ta_info.append("客户端发送的信息:" + tf_send.getText() + "\n"); // 将文本框中信息显示在文本域中 tf_send.setText(""); // 将文本框清空 } }); button.setText("Say"); panel_1.add(button); final JScrollPane scrollPane = new JScrollPane(); getContentPane().add(scrollPane, BorderLayout.CENTER); ta_info = new JTextArea(); scrollPane.setViewportView(ta_info); // } } 服务器: package sunxu.util; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; import java.awt.Font; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.*; import java.net.*; import javax.swing.BorderFactory; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTextArea; import javax.swing.JTextField; public class ServerSocketFrame extends JFrame { //private JTextField tf_send; private JTextArea ta_info; private PrintWriter writer; // 声明PrintWriter类对象 private BufferedReader reader; // 声明BufferedReader对象 private ServerSocket server; // 声明ServerSocket对象 private Socket socket; // 声明Socket对象socket private int sendPort; public void getServer() { try { server = new ServerSocket(sendPort); // 实例化Socket对象 ta_info.append("服务器套接字已经创建成功\n"); // 输出信息 while (true) { // 如果套接字是连接状态 ta_info.append("等待客户机的连接......\n"); // 输出信息 socket = server.accept(); // 实例化Socket对象 reader = new BufferedReader(new InputStreamReader(socket .getInputStream())); // 实例化BufferedReader对象 writer = new PrintWriter(socket.getOutputStream(), true); getClientInfo(); // 调用getClientInfo()方法 } } catch (Exception e) { e.printStackTrace(); // 输出异常信息 } } private void getClientInfo() { try { while (true) { String line = reader.readLine();// 读取客户端发送的信息 if (line != null) ta_info.append("接收到客户机发送的信息:" + line + "\n"); // 显示客户端发送的信息 } } catch (Exception e) { ta_info.append("客户端已退出。\n"); // 输出异常信息 } finally { try { if (reader != null) { reader.close();// 关闭流 } if (socket != null) { socket.close(); // 关闭套接字 } } catch (IOException e) { e.printStackTrace(); } } } public static void main(String[] args) { // 主方法 ServerSocketFrame frame = new ServerSocketFrame(); // 创建本类对象 frame.setVisible(true); //frame.getServer(); // 调用方法 } public ServerSocketFrame() { super(); setTitle("服务器端程序"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(100, 100, 379, 260); final JScrollPane scrollPane = new JScrollPane(); getContentPane().add(scrollPane, BorderLayout.CENTER); ta_info = new JTextArea(); scrollPane.setViewportView(ta_info); final JPanel panel = new JPanel(); getContentPane().add(panel, BorderLayout.SOUTH); final JLabel label = new JLabel(); label.setText("Say:"); panel.add(label); JTextField tf_send = new JTextField(); tf_send.setPreferredSize(new Dimension(150, 25)); panel.add(tf_send); final JButton button = new JButton(); button.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent e) { writer.println(tf_send.getText()); // 将文本框中信息写入流 ta_info.append("服务器发送的信息是:" + tf_send.getText() + "\n"); // 将文本框中信息显示在文本域中 tf_send.setText(""); // 将文本框清空 } }); button.setText("Say:"); panel.add(button); final JPanel panel_1 = new JPanel(); getContentPane().add(panel_1, BorderLayout.NORTH); panel_1.setBorder(BorderFactory.createTitledBorder("服务器设置:")); final JLabel label_1 = new JLabel(); label_1.setText("Port:"); JTextField tf_sen= new JTextField(); tf_sen.setPreferredSize(new Dimension(220, 25)); panel_1.add(label_1); panel_1.add(tf_sen); final JButton button1 = new JButton("Strat"); button1.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent e) { sendPort=Integer.parseInt(tf_sen.getText()); getServer(); } }); panel_1.add(button1); } }

事务提交过程,出现异常,但是回滚事务失败,这是什么原因

/** *实现事务:Tom 对Jerry 转账500元 * */ public class TransactionTest { public static void update(Connection conn,String sql,Object ... args){ PreparedStatement pstmt = null; try{ pstmt = conn.prepareStatement(sql);//通过SQL语句 创建PreparedStatement 对象。 //利用 for 循环对 SQL 语句中的 PreparedStatement 占位符 ,更新数据。 for(int i = 0;i < args.length;i++){ pstmt.setObject((i+1), args[i]); } //更新执行。 pstmt.executeUpdate(); }catch(Exception e){ e.printStackTrace(); }finally{ //关闭数据库连接。 JDBCTools.release(null, pstmt, null); } } public static void main(String[] args) { Connection conn = null; try{ conn = JDBCTools.getConnection(); //取消默认的提交方式 conn.setAutoCommit(false); String sql = "UPDATE user SET balance = balance - 500 WHERE id = 2000001"; update(conn, sql); /*此处会 报com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException,Table 'ming.users' doesn't exist 但是,整个事务却没有回滚。*/ sql = "UPDATE users SET balance = balance + 500 WHERE id = 2000002"; update(conn,sql); //若事务操作正常,则提交事务 conn.commit(); } catch(Exception e){ //若事务操作出现异常,则需要在异常处理中回滚事务 try { conn.rollback(); } catch (SQLException e1) { e1.printStackTrace(); } e.printStackTrace(); } finally{ JDBCTools.release(null, null, conn); } } }

java socket怎么获取端口心跳包数据?

1、返回400 ``` public static synchronized String tcpPost(String clientIp,String clientPort,String msg){ String rs = ""; if(clientIp==null||"".equals(clientIp)||clientPort==null||"".equals(clientPort)){ logger.error("Ip或端口不存在..."); return null; } int clientPortInt = Integer.parseInt(clientPort); logger.info("clientIp:"+clientIp+" clientPort:"+clientPort); Socket s = null; OutputStream out = null; InputStream in = null; try { s = new Socket(clientIp, clientPortInt); s.setSendBufferSize(4096); s.setTcpNoDelay(true); s.setSoTimeout(60*1000); s.setKeepAlive(true); out = s.getOutputStream(); in = s.getInputStream(); //准备报文msg logger.info("准备发送报文:"+msg); out.write(msg.getBytes("GBK")); out.flush(); byte[] rsByte = readStream(in); if(rsByte!=null){ rs = new String(rsByte, "GBK"); } } catch (Exception e) { logger.error("tcpPost发送请求异常:"+e.getMessage()); }finally{ logger.info("tcpPost(rs):"+rs); ```

关于java线程突然死亡

郁闷了,线程无故自动终止,执行了finally代码段: 下面是线程的RUN方法: [code="java"]public void run () { // Output welcome message to the console labels = ServerLabels.getInstance(); Log4jUtil.info ("------------------------------------------------------------------"); Log4jUtil.info (" 游 戏 平 台 "); Log4jUtil.info ("------------------------------------------------------------------"); Log4jUtil.info (labels.get("author") + ": Bob Marks"); Log4jUtil.info (labels.get("version") + ": " + IJogre.VERSION); Log4jUtil.info ("------------------------------------------------------------------"); Log4jUtil.info (labels.get("persistent.server.data") + ": " + dataConnection.getType()); Log4jUtil.info ("------------------------------------------------------------------"); Log4jUtil.info (labels.get ("games.being.served") + " (" + gameList.size() + "):"); // Load the various games Log4jUtil.info (gameLoader); // End of welcome message Log4jUtil.info ("------------------------------------------------------------------\n"); // Declare server socket to listen for client connections ServerSocket listenSocket = null; try { // Set up the server first of all listenSocket = new ServerSocket (serverPort); while (true) { // listen for and accept the connection Socket clientSocket = listenSocket.accept (); try{ Log4jUtil.info( clientSocket+" HASHCODE "+clientSocket.hashCode() ); BufferedReader br = new BufferedReader (new InputStreamReader (clientSocket.getInputStream(),"UTF-8")); PrintStream pw = new PrintStream (clientSocket.getOutputStream(),true,"UTF-8"); // BufferedReader br = new BufferedReader(new InputStreamReader(clientSocket.getInputStream())); // PrintWriter pw = new PrintWriter(clientSocket.getOutputStream()); String head=null; int count = 0; while(count<=10&&head==null){ if(br.ready()){ char[] by = new char[22]; br.read(by,0,22); head = new String(by); }else{ count++; this.sleep(500); Log4jUtil.info("连接层,流没有准备被读取,所以跳过,等待下次读取并累积读取次数+1:"+count); } } // String head = br.readLine(); if(head!=null&&!head.equals("")){ head = head.trim(); Log4jUtil.info("后台接收消息头:" + head + "&&&:&&&"); if(head.equals("<policy-file-request/>")) { pw.print(this.getXml() + "\0"); pw.flush(); }else if(head.equals("<policy-file-xxquest/>")){ @SuppressWarnings("unused") ServerConnectionThread conn = new ServerConnectionThread (clientSocket,br,pw); pw.println("<table><creatThread/></table>"+"\0"); pw.flush(); Log4jUtil.info("flash直连后台程序"); }else if(head.equals("<policy-file-xyquest/>")){ @SuppressWarnings("unused") ServerConnectionThread conn = new ServerConnectionThread (clientSocket,br,pw); Log4jUtil.info("flash通过中间层转发连后台程序"); } }else{ Log4jUtil.info("连接服务器的时候由于读取到的字符为NULL而关闭对应的SOCKET"); clientSocket.close(); } }catch(Exception e){ //关闭连接 if(clientSocket!=null){ clientSocket.close(); } Log4jUtil.info("捕获异常了,准备对外抛出"+e.getMessage().toString()); //抛出空指针异常,使其被外面的捕获,然后重新启动线程 throw new NullPointerException(); } // Try to connect client to this server //conn.setSendListener (sentListener); //conn.setRecieveListener (recieveListener); } }catch (BindException bindEx) { Log4jUtil.info ("jogre.server.already.running.on.port1: " + serverPort); //System.exit (0); } catch (Exception genEx) { Log4jUtil.info ("jogre.server.already.running.on.port2: " + serverPort); genEx.printStackTrace(); }finally{ // Close the server down again try { Log4jUtil.info ("is over listenSocket close: " + serverPort); if (listenSocket != null) listenSocket.close(); Log4jUtil.info ("is run: " + serverPort); this.run(); } catch (IOException ioEx) { Log4jUtil.info ("listenSocket close exception: " + serverPort); } } }[/code] 日志的信息如下 [code="java"] [framework] 2008-12-21 18:32:06,921 [Thread-2] - Socket[addr=/10.10.10.1,port=2350,localport=1790] HASHCODE 16661568 [framework] 2008-12-21 18:32:06,921 [Thread-2] - 后台接收消息头:<policy-file-request/>&&&:&&& [framework] 2008-12-21 18:32:07,234 [Thread-2] - Socket[addr=/10.10.10.1,port=2351,localport=1790] HASHCODE 2554984 [framework] 2008-12-21 18:32:07,234 [Thread-2] - 后台接收消息头:<policy-file-xxquest/>&&&:&&& [framework] 2008-12-21 18:32:07,859 [Thread-2] - flash直连后台程序 [framework] 2008-12-21 18:32:14,046 [Thread-2] - Socket[addr=/10.10.10.1,port=2353,localport=1790] HASHCODE 27504706 [framework] 2008-12-21 18:32:15,875 [Thread-2] - is over listenSocket close: 1790 [framework] 2008-12-21 18:32:15,875 [Thread-2] - is run: 1790 [framework] 2008-12-21 18:32:15,875 [Thread-2] - ------------------------------------------------------------------ [framework] 2008-12-21 18:32:16,218 [Thread-2] - 游 戏 平 台 [framework] 2008-12-21 18:32:16,218 [Thread-2] - ------------------------------------------------------------------ [framework] 2008-12-21 18:32:16,515 [Thread-2] - Author: Bob Marks [framework] 2008-12-21 18:32:16,515 [Thread-2] - Version: alpha 0.2.3 [framework] 2008-12-21 18:32:16,828 [Thread-2] - ------------------------------------------------------------------ [framework] 2008-12-21 18:32:17,484 [Thread-2] - Persistent Server Data: database [framework] 2008-12-21 18:32:17,484 [Thread-2] - ------------------------------------------------------------------ [framework] 2008-12-21 18:32:17,484 [Thread-2] - Games being served (1): [framework] 2008-12-21 18:32:17,484 [Thread-2] - [controller] hrmajiang [framework] 2008-12-21 18:32:17,781 [Thread-2] - ------------------------------------------------------------------ [framework] 2008-12-21 18:32:22,687 [Thread-2] - Socket[addr=/10.10.10.1,port=3330,localport=1790] HASHCODE 4172024 [framework] 2008-12-21 18:32:26,046 [Thread-2] - is over listenSocket close: 1790 [framework] 2008-12-21 18:32:26,359 [Thread-2] - is run: 1790 [framework] 2008-12-21 18:32:26,359 [Thread-2] - ------------------------------------------------------------------ [framework] 2008-12-21 18:32:26,656 [Thread-2] - 游 戏 平 台 [framework] 2008-12-21 18:32:26,656 [Thread-2] - ------------------------------------------------------------------ [framework] 2008-12-21 18:32:26,656 [Thread-2] - Author: Bob Marks [framework] 2008-12-21 18:32:26,968 [Thread-2] - Version: alpha 0.2.3 [framework] 2008-12-21 18:32:27,281 [Thread-2] - ------------------------------------------------------------------ [framework] 2008-12-21 18:32:27,281 [Thread-2] - Persistent Server Data: database [framework] 2008-12-21 18:32:27,281 [http-8080-Processor21] - Dispatch[/admin/loginAction] to method login returned an exception 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 org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:280) at org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:216) at org.springframework.web.struts.DelegatingActionProxy.execute(DelegatingActionProxy.java:106) at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484) at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274) at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482) at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525) at javax.servlet.http.HttpServlet.service(HttpServlet.java:647) at javax.servlet.http.HttpServlet.service(HttpServlet.java:729) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188) at org.extremecomponents.table.filter.AbstractExportFilter.doFilter(AbstractExportFilter.java:50) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188) at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:75) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:77) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188) at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:174) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:77) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:172) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:875) at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665) at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528) at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81) at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689) at java.lang.Thread.run(Unknown Source) [/code] 问题点是: 1.为什么线程会在无任何异常的情况下终止? [framework] 2008-12-21 18:32:26,046 [Thread-2] - is over listenSocket close: 1790 2.如果使用tomcat5.5做服务器,在设置初始化内存大小和最大内存大小的时候是否有限制?比如不能大于2048MB 因为每次设置2048的时候TOMCAT都无法正常启动,设置成1536MB就可以了

URLConnection无法获得InputStream的问题

我在使用URLConnection的时候遇到以下问题: 1:程序运行到以下代码处停止运行(可能是阻塞): InputStream in = connection.getInputStream(); 2:无法捕获到任何异常 3:URLConnection一直处于正常状态 4:如果通过IE直接访问URL一次, 程序就会顺利执行下去(就像程序中设置了断点,我通过IE访问URL时continue了) 请问各位朋友有没有遇到类似的问题,有没有什么思路和建议? 以下是我的代码: [code="java"]private String readResponse(URLConnection connection, String encoding) { StringBuffer sb = new StringBuffer(); BufferedReader br = null; try { InputStream in = connection.getInputStream(); br = new BufferedReader(new InputStreamReader(in)); String line = br.readLine(); while (line != null) { ..... } } catch (Throwable e) { logger.info("readResponse().catch...",e); e.printStackTrace(); } finally { logger.info("readResponse().finally..."); closeStream(br); } String result = sb.toString(); logger.info("Response is :"); logger.info(result); return result; }[/code]

android写个注册程序时报java.io.StreamCorruptedException

求大神帮忙看一看,困了好久了,还是解决不了,先上点代码 public void onClick(View v) { if (!userpassword1.getText().toString() .equals(userpassword2.getText().toString())) { Toast.makeText(RegActivity.this, "密码不一致!", Toast.LENGTH_LONG) .show(); return; } Socket socket = null; try { socket = new Socket(Tools.IP, Tools.PORT_1); ObjectOutputStream oout = new ObjectOutputStream( socket.getOutputStream()); ObjectInputStream oin = new ObjectInputStream( socket.getInputStream()); Message m1 = new Message(); Hashtable table = new Hashtable(); table.put("userid", useridText.getText().toString()); if (manb.isChecked()) { table.put("sex", "男"); } else { table.put("sex", "女"); } table.put("username", usernameText.getText().toString()); table.put("age", userageText.getText().toString()); table.put("userpassword", userpassword1.getText().toString()); m1.setValue(table); m1.setType(m1.REG); oout.writeObject(m1); oout.flush(); m1 = (Message) oin.readObject(); if (m1.getReturnValue().get("message").toString() .equalsIgnoreCase("ok")) { AlertDialog.Builder bb = new AlertDialog.Builder( RegActivity.this); bb.setTitle("恭喜您,注册成功!"); bb.setMessage("您的ID是:" + m1.getReturnValue().get("userid")); final String userid = m1.getReturnValue().get("userid") .toString(); bb.setNeutralButton("马上登录", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Intent in = new Intent(); in.setClass(RegActivity.this, LoginActivity.class); in.putExtra("userid", userid); startActivity(in); RegActivity.this.finish(); } }); bb.setNegativeButton("退出", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { System.exit(0); } }); bb.create().show(); } else { Toast.makeText( RegActivity.this, "注册失败!" + m1.getReturnValue().get("message") .toString(), Toast.LENGTH_LONG) .show(); } } catch (Exception e) { e.printStackTrace(); Toast.makeText(RegActivity.this, "网络不通!"+e.getMessage(), Toast.LENGTH_LONG) .show(); } finally { try { socket.close(); } catch (IOException e) { } } } 在try...catch那捕捉的异常是null; 不知道是不是自己写的服务器的问题,还是软件中的代码错误 报的警告是 java.io.StreamCorruptedException at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1700) at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1653) at com.erhuo.login.RegActivity$SubmitButtonOnClickListener.onClick(RegActivity.java:88)这里对应的那一行是 m1 = (Message) oin.readObject();

用php写出下面java的代码,不知道php有没有对字节的压缩?

public static byte[] compression(int compressType, String xml) throws IOException { byte[] result=null; if(StringUtils.isNotBlank(xml)){ if(compressType==1){ result=xml.getBytes("utf-8"); ByteArrayOutputStream baos=null; ZipOutputStream zout=null; try { baos=new ByteArrayOutputStream();//捕获内存缓冲区的数据,转换成字节数组 zout=new ZipOutputStream(baos);//调用Zip方法压缩字节数组 zout.putNextEntry(new ZipEntry(System.currentTimeMillis()+".txt"));//需要将待压缩数据以ZipEntry的方式追加到压缩文件中 zout.write(result); zout.closeEntry(); // return baos; result=baos.toByteArray(); } finally{ if(zout!=null){ zout.close(); } if(baos!=null){ baos.close(); } } }else{ result=xml.getBytes("utf-8"); } } return result; }

激活账号的servlet运行报错500,代码是对的,为什么会报错?

报错 ![图片说明](https://img-ask.csdn.net/upload/201904/24/1556071273_272031.png) servlet代码 ``` package servlets; import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import bean.Check; import bean.DB; import bean.Tools; import java.sql.*; public class RegAdminServlet extends HttpServlet { /** * Constructor of the object. */ public RegAdminServlet() { super(); } /** * Destruction of the servlet. <br> */ public void destroy() { super.destroy(); // Just puts "destroy" string in log // Put your code here } /** * The doGet method of the servlet. <br> * * This method is called when a form has its tag value method equals to get. * * @param request the request send by the client to the server * @param response the response send by the server to the client * @throws ServletException if an error occurred * @throws IOException if an error occurred */ public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doPost(request, response); } /** * The doPost method of the servlet. <br> * * This method is called when a form has its tag value method equals to post. * * @param request the request send by the client to the server * @param response the response send by the server to the client * @throws ServletException if an error occurred * @throws IOException if an error occurred */ public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { //用以建立数据库连接的必要信息 String url="jdbc:mysql://localhost:3306/database"; String user="root"; String password="123456"; String adminid = Tools.codeToChinese(request.getParameter("adminid")); String adminpass = request.getParameter("adminpass"); String adminname = Tools.codeToChinese(request.getParameter("adminname")); String admintele = request.getParameter("admintele"); //省略号表示要输入具体的sql语句 String sql="select * from administrator adminID='"+adminid+"'"; //创建各个对象 Connection conn=null; //建立数据库连接的对象 Statement stmt=null; //创建用于执行SQL语句的Statement对象 ResultSet rs=null; //创建结果集对象 HttpSession session = request.getSession(); try{ //建立连接并执行语句 conn=DriverManager.getConnection(url, user, password); stmt=conn.createStatement(); rs=stmt.executeQuery(sql); //其它操作 if(rs.next()) { Check check = new Check(); boolean ck=check.check(adminid, adminpass, adminname, admintele); if(ck) { DB db = new DB(); StringBuffer newsql = new StringBuffer(); newsql.append("UPDATE administrator SET adminActivated='1' WHERE adminID='"+adminid+"'"); boolean a = db.executeUpdate(newsql.toString()); if(a){ session.setAttribute("message","激活成功!"); response.sendRedirect("regCheckSuccess.jsp"); } else{ session.setAttribute("message","激活失败,请重新激活!"); response.sendRedirect("regCheckFailure.jsp"); } } else { session.setAttribute("message", "激活失败!用户信息输入错误,请重新输入!"); response.sendRedirect("regCheckFailure.jsp"); } } else { session.setAttribute("message", "账号不存在,请重新输入!"); response.sendRedirect("regMsgAdmin.jsp"); } }catch(SQLException se){ throw new ServletException(se); }finally{ try{rs.close();}catch(SQLException se){} try{stmt.close();}catch(SQLException se){} try{conn.close();}catch(SQLException se){} } response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println("<form method=post action=PotalServlet>"); out.println("<table><tr>"); out.println("<td>请输入用户名</td>"); out.println("<td><input type=text name=username /></td>"); out.println("</tr><tr>"); out.println("<td>请输入密码</td>"); out.println("<td><input type=password name=userpass /></td>"); out.println("</tr><tr>"); out.println("<td><input type=reset value=重填 /></td>"); out.println("<td><input type=submit value=登录 /></td>"); out.println("</tr>"); out.println("</table>"); out.println("</form>"); //out.close()不能调用,否则portal中后面的输出语句将不输出 /*out .println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">"); out.println("<HTML>"); out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>"); out.println(" <BODY>"); out.print(" This is "); out.print(this.getClass()); out.println(", using the POST method"); out.println(" </BODY>"); out.println("</HTML>"); out.flush(); out.close();*/ } /** * Initialization of the servlet. <br> * * @throws ServletException if an error occurs */ public void init() throws ServletException { String classname="com.mysql.jdbc.Driver"; try{ Class.forName(classname); }catch(ClassNotFoundException ce){ throw new ServletException("加载数据库驱动失败"); } } } ``` Check包代码 ``` package bean; import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; public class Check { public static boolean check(String adminid,String adminpass,String adminname,String admintele) { DB db = new DB(); Connection conn=db.createConn(); String sql = "select * from administrator where adminID='"+adminid+"'"; /*Statement stmt = null; ResultSet rs = null;*/ try{ Statement stmt=conn.createStatement(); ResultSet rs=stmt.executeQuery(sql); while(rs.next()) { String adminID = rs.getString("adminID"); String adminPass = rs.getString("adminPass"); String adminName = rs.getString("adminName"); String adminTele = rs.getString("adminTele"); if(adminID.equals(adminid)&&adminPass.equals(adminpass)&&adminName.equals(adminname)&&adminTele.equals(admintele)) { return true; } else { return false; } } }catch(SQLException se){ return false; }finally{ //try{rs.close();}catch(SQLException se){} //try{stmt.close();}catch(SQLException se){} //try{conn.close();}catch(SQLException se){} } return false; } } ``` DB包代码 ``` package bean; //导入创建应用数据要用到的类 import java.sql.DriverManager; import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; public class DB { private String classname="com.mysql.jdbc.Driver"; //数据库驱动类路径 private String url="jdbc:mysql://localhost:3306/database"; //数据库URL private String user="root"; //登录数据库的用户名 private String pwd="123456"; //登录数据库的密码 private Connection conn=null; //申明一个Connection对象 private Statement stmt=null; //声明一个Statement对象 private ResultSet rs=null; /*通过构造方法加载数据库驱动*/ public DB(){ //DB类的构造方法 try{ //必须使用try catch语句捕获加载数据库驱动时可能发生的异常 Class.forName(classname).newInstance(); //加载数据库驱动 }catch (Exception e){ e.printStackTrace(); //输出异常信息 System.out.println("加载数据库驱动失败!!"); } } /*创建数据库连接*/ public Connection createConn(){ try{ conn=DriverManager.getConnection(url, user, pwd); }catch(SQLException e){ e.printStackTrace(); System.out.println("获取数据库连接失败!!"); } return conn; } /*获取Statement对象*/ public void getStmt(){ createConn(); try{ //调用Connection类实例的createStatement()方法创建一个Statement类对象 stmt=conn.createStatement(); }catch(SQLException e){ e.printStackTrace(); System.out.println("创建Statement对象失败!!"); } } /*创建对数据库进行操作的增加、删除和修改的executeUpdate()方法*/ public boolean executeUpdate(String sql){ boolean mark=false; try{ getStmt(); //创建一个Statement对象 int iCount=stmt.executeUpdate(sql); //执行操作,并获取所影响的记录数 if(iCount>0) //更新数据库成功 mark=true; else //更新失败 mark=false; }catch(SQLException e){ e.printStackTrace(); } return mark; } /*查询数据库*/ public ResultSet executeQuery(String sql){ try{ getStmt(); try{ rs=stmt.executeQuery(sql); }catch(Exception e){ e.printStackTrace(); System.out.println("查询数据库失败!!"); } }catch(Exception e){ e.printStackTrace(); } return rs; } public void close(){ try{if(rs!=null)rs.close();}catch(Exception e){} try {stmt.close();}catch(Exception e){} try {conn.close();}catch(Exception e){} } } ``` jsp代码 ``` <%@ page language="java" import="java.util.*" pageEncoding="GB2312"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <title>My JSP 'regAdmin.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> --> <script language="javascript"> function isNull(str) { if (str.length==0) return true; else return false; } function isValidate(form) { adminid=form.adminid.value; adminpass=form.adminpass.value; adminname=form.adminname.value; admintele=form.admintele.value; if(isNull(adminid)) { alert("请输入账号!"); return false; } if(isNull(adminpass)) { alert("请输入密码!"); return false; } if(isNull(adminname)) { alert("请输入姓名!"); return false; } if(isNull(admintele)) { alert("请输入联系方式!"); return false; } return true; } </script> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> </head> <body> <form name="form" action="RegAdminServlet" method="post" onSubmit="return isValidate(form)"><br> <h1 align="center"> 管理员账号激活</h1><hr><p><br> <table width="300" border="0" align="center"> <tr><td valign="top"><br></td><td valign="top"><br></td><td valign="top"><br></td><td valign="top"><br></td><td valign="top"><br></td><td valign="top"><br></td><td valign="top"><br></td><td valign="top"><br></td><td valign="top"><br></td><td valign="top"><br></td></tr><tr> <td valign="top"><br></td><td valign="top"><br></td><td valign="top"><br></td><td valign="top"><br></td><td valign="top"><br></td><td valign="top"><br></td><td valign="top"><br></td><td valign="top"><br></td><td>账 号 :</td> <td><input type="text" name="adminid" /></td> </tr> <tr> <td valign="top"><br></td><td valign="top"><br></td><td valign="top"><br></td><td valign="top"><br></td><td valign="top"><br></td><td valign="top"><br></td><td valign="top"><br></td><td valign="top"><br></td><td>密 码 :</td> <td><input type="password" name="adminpass"/></td> </tr> <tr> <td valign="top"><br></td><td valign="top"><br></td><td valign="top"><br></td><td valign="top"><br></td><td valign="top"><br></td><td valign="top"><br></td><td valign="top"><br></td><td valign="top"><br></td><td>姓 名 :</td> <td><input type="text" name="adminname"/></td> </tr> <tr> <td valign="top"><br></td><td valign="top"><br></td><td valign="top"><br></td><td valign="top"><br></td><td valign="top"><br></td><td valign="top"><br></td><td valign="top"><br></td><td valign="top"><br></td><td>联 系<br>方 式 :</td> <td><input type="text" name="admintele"/></td> </tr> </table><br> <div align="center"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" name="submit" value="激活"/> &nbsp;&nbsp;&nbsp;<input type="reset" name="reset" value="清空"/><br><br><br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="loginAdmin.jsp">【返回】</a> </div> <p> </form> </body> </html> ``` 数据库 ![图片说明](https://img-ask.csdn.net/upload/201904/24/1556071645_465453.png)

大学四年自学走来,这些私藏的实用工具/学习网站我贡献出来了

大学四年,看课本是不可能一直看课本的了,对于学习,特别是自学,善于搜索网上的一些资源来辅助,还是非常有必要的,下面我就把这几年私藏的各种资源,网站贡献出来给你们。主要有:电子书搜索、实用工具、在线视频学习网站、非视频学习网站、软件下载、面试/求职必备网站。 注意:文中提到的所有资源,文末我都给你整理好了,你们只管拿去,如果觉得不错,转发、分享就是最大的支持了。 一、电子书搜索 对于大部分程序员...

在中国程序员是青春饭吗?

今年,我也32了 ,为了不给大家误导,咨询了猎头、圈内好友,以及年过35岁的几位老程序员……舍了老脸去揭人家伤疤……希望能给大家以帮助,记得帮我点赞哦。 目录: 你以为的人生 一次又一次的伤害 猎头界的真相 如何应对互联网行业的「中年危机」 一、你以为的人生 刚入行时,拿着傲人的工资,想着好好干,以为我们的人生是这样的: 等真到了那一天,你会发现,你的人生很可能是这样的: ...

Java基础知识面试题(2020最新版)

文章目录Java概述何为编程什么是Javajdk1.5之后的三大版本JVM、JRE和JDK的关系什么是跨平台性?原理是什么Java语言有哪些特点什么是字节码?采用字节码的最大好处是什么什么是Java程序的主类?应用程序和小程序的主类有何不同?Java应用程序与小程序之间有那些差别?Java和C++的区别Oracle JDK 和 OpenJDK 的对比基础语法数据类型Java有哪些数据类型switc...

我以为我学懂了数据结构,直到看了这个导图才发现,我错了

数据结构与算法思维导图

String s = new String(" a ") 到底产生几个对象?

老生常谈的一个梗,到2020了还在争论,你们一天天的,哎哎哎,我不是针对你一个,我是说在座的各位都是人才! 上图红色的这3个箭头,对于通过new产生一个字符串(”宜春”)时,会先去常量池中查找是否已经有了”宜春”对象,如果没有则在常量池中创建一个此字符串对象,然后堆中再创建一个常量池中此”宜春”对象的拷贝对象。 也就是说准确答案是产生了一个或两个对象,如果常量池中原来没有 ”宜春” ,就是两个。...

技术大佬:我去,你写的 switch 语句也太老土了吧

昨天早上通过远程的方式 review 了两名新来同事的代码,大部分代码都写得很漂亮,严谨的同时注释也很到位,这令我非常满意。但当我看到他们当中有一个人写的 switch 语句时,还是忍不住破口大骂:“我擦,小王,你丫写的 switch 语句也太老土了吧!” 来看看小王写的代码吧,看完不要骂我装逼啊。 private static String createPlayer(PlayerTypes p...

Linux面试题(2020最新版)

文章目录Linux 概述什么是LinuxUnix和Linux有什么区别?什么是 Linux 内核?Linux的基本组件是什么?Linux 的体系结构BASH和DOS之间的基本区别是什么?Linux 开机启动过程?Linux系统缺省的运行级别?Linux 使用的进程间通信方式?Linux 有哪些系统日志文件?Linux系统安装多个桌面环境有帮助吗?什么是交换空间?什么是root帐户什么是LILO?什...

Linux命令学习神器!命令看不懂直接给你解释!

大家都知道,Linux 系统有非常多的命令,而且每个命令又有非常多的用法,想要全部记住所有命令的所有用法,恐怕是一件不可能完成的任务。 一般情况下,我们学习一个命令时,要么直接百度去搜索它的用法,要么就直接用 man 命令去查看守冗长的帮助手册。这两个都可以实现我们的目标,但有没有更简便的方式呢? 答案是必须有的!今天给大家推荐一款有趣而实用学习神器 — kmdr,让你解锁 Linux 学习新姿势...

和黑客斗争的 6 天!

互联网公司工作,很难避免不和黑客们打交道,我呆过的两家互联网公司,几乎每月每天每分钟都有黑客在公司网站上扫描。有的是寻找 Sql 注入的缺口,有的是寻找线上服务器可能存在的漏洞,大部分都...

史上最全的 python 基础知识汇总篇,没有比这再全面的了,建议收藏

网友们有福了,小编终于把基础篇的内容全部涉略了一遍,这是一篇关于基础知识的汇总的文章,请朋友们收下,不用客气,不过文章篇幅肯能会有点长,耐心阅读吧爬虫(七十)多进程multiproces...

讲一个程序员如何副业月赚三万的真实故事

loonggg读完需要3分钟速读仅需 1 分钟大家好,我是你们的校长。我之前讲过,这年头,只要肯动脑,肯行动,程序员凭借自己的技术,赚钱的方式还是有很多种的。仅仅靠在公司出卖自己的劳动时...

女程序员,为什么比男程序员少???

昨天看到一档综艺节目,讨论了两个话题:(1)中国学生的数学成绩,平均下来看,会比国外好?为什么?(2)男生的数学成绩,平均下来看,会比女生好?为什么?同时,我又联想到了一个技术圈经常讨...

85后蒋凡:28岁实现财务自由、34岁成为阿里万亿电商帝国双掌门,他的人生底层逻辑是什么?...

蒋凡是何许人也? 2017年12月27日,在入职4年时间里,蒋凡开挂般坐上了淘宝总裁位置。 为此,时任阿里CEO张勇在任命书中力赞: 蒋凡加入阿里,始终保持创业者的冲劲,有敏锐的...

总结了 150 余个神奇网站,你不来瞅瞅吗?

原博客再更新,可能就没了,之后将持续更新本篇博客。

副业收入是我做程序媛的3倍,工作外的B面人生是怎样的?

提到“程序员”,多数人脑海里首先想到的大约是:为人木讷、薪水超高、工作枯燥…… 然而,当离开工作岗位,撕去层层标签,脱下“程序员”这身外套,有的人生动又有趣,马上展现出了完全不同的A/B面人生! 不论是简单的爱好,还是正经的副业,他们都干得同样出色。偶尔,还能和程序员的特质结合,产生奇妙的“化学反应”。 @Charlotte:平日素颜示人,周末美妆博主 大家都以为程序媛也个个不修边幅,但我们也许...

MySQL数据库面试题(2020最新版)

文章目录数据库基础知识为什么要使用数据库什么是SQL?什么是MySQL?数据库三大范式是什么mysql有关权限的表都有哪几个MySQL的binlog有有几种录入格式?分别有什么区别?数据类型mysql有哪些数据类型引擎MySQL存储引擎MyISAM与InnoDB区别MyISAM索引与InnoDB索引的区别?InnoDB引擎的4大特性存储引擎选择索引什么是索引?索引有哪些优缺点?索引使用场景(重点)...

新一代神器STM32CubeMonitor介绍、下载、安装和使用教程

关注、星标公众号,不错过精彩内容作者:黄工公众号:strongerHuang最近ST官网悄悄新上线了一款比较强大的工具:STM32CubeMonitor V1.0.0。经过我研究和使用之...

如果你是老板,你会不会踢了这样的员工?

有个好朋友ZS,是技术总监,昨天问我:“有一个老下属,跟了我很多年,做事勤勤恳恳,主动性也很好。但随着公司的发展,他的进步速度,跟不上团队的步伐了,有点...

我入职阿里后,才知道原来简历这么写

私下里,有不少读者问我:“二哥,如何才能写出一份专业的技术简历呢?我总感觉自己写的简历太烂了,所以投了无数份,都石沉大海了。”说实话,我自己好多年没有写过简历了,但我认识的一个同行,他在阿里,给我说了一些他当年写简历的方法论,我感觉太牛逼了,实在是忍不住,就分享了出来,希望能够帮助到你。 01、简历的本质 作为简历的撰写者,你必须要搞清楚一点,简历的本质是什么,它就是为了来销售你的价值主张的。往深...

大学一路走来,学习互联网全靠这几个网站,最终拿下了一把offer

大佬原来都是这样炼成的

离职半年了,老东家又发 offer,回不回?

有小伙伴问松哥这个问题,他在上海某公司,在离职了几个月后,前公司的领导联系到他,希望他能够返聘回去,他很纠结要不要回去? 俗话说好马不吃回头草,但是这个小伙伴既然感到纠结了,我觉得至少说明了两个问题:1.曾经的公司还不错;2.现在的日子也不是很如意。否则应该就不会纠结了。 老实说,松哥之前也有过类似的经历,今天就来和小伙伴们聊聊回头草到底吃不吃。 首先一个基本观点,就是离职了也没必要和老东家弄的苦...

为什么你不想学习?只想玩?人是如何一步一步废掉的

不知道是不是只有我这样子,还是你们也有过类似的经历。 上学的时候总有很多光辉历史,学年名列前茅,或者单科目大佬,但是虽然慢慢地长大了,你开始懈怠了,开始废掉了。。。 什么?你说不知道具体的情况是怎么样的? 我来告诉你: 你常常潜意识里或者心理觉得,自己真正的生活或者奋斗还没有开始。总是幻想着自己还拥有大把时间,还有无限的可能,自己还能逆风翻盘,只不是自己还没开始罢了,自己以后肯定会变得特别厉害...

什么时候跳槽,为什么离职,你想好了么?

都是出来打工的,多为自己着想

为什么程序员做外包会被瞧不起?

二哥,有个事想询问下您的意见,您觉得应届生值得去外包吗?公司虽然挺大的,中xx,但待遇感觉挺低,马上要报到,挺纠结的。

当HR压你价,说你只值7K,你该怎么回答?

当HR压你价,说你只值7K时,你可以流畅地回答,记住,是流畅,不能犹豫。 礼貌地说:“7K是吗?了解了。嗯~其实我对贵司的面试官印象很好。只不过,现在我的手头上已经有一份11K的offer。来面试,主要也是自己对贵司挺有兴趣的,所以过来看看……”(未完) 这段话主要是陪HR互诈的同时,从公司兴趣,公司职员印象上,都给予对方正面的肯定,既能提升HR的好感度,又能让谈判气氛融洽,为后面的发挥留足空间。...

面试阿里p7,被按在地上摩擦,鬼知道我经历了什么?

面试阿里p7被问到的问题(当时我只知道第一个):@Conditional是做什么的?@Conditional多个条件是什么逻辑关系?条件判断在什么时候执...

你期望月薪4万,出门右拐,不送,这几个点,你也就是个初级的水平

先来看几个问题通过注解的方式注入依赖对象,介绍一下你知道的几种方式@Autowired和@Resource有何区别说一下@Autowired查找候选者的...

面试了一个 31 岁程序员,让我有所触动,30岁以上的程序员该何去何从?

最近面试了一个31岁8年经验的程序猿,让我有点感慨,大龄程序猿该何去何从。

大三实习生,字节跳动面经分享,已拿Offer

说实话,自己的算法,我一个不会,太难了吧

程序员垃圾简历长什么样?

已经连续五年参加大厂校招、社招的技术面试工作,简历看的不下于万份 这篇文章会用实例告诉你,什么是差的程序员简历! 疫情快要结束了,各个公司也都开始春招了,作为即将红遍大江南北的新晋UP主,那当然要为小伙伴们做点事(手动狗头)。 就在公众号里公开征简历,义务帮大家看,并一一点评。《启舰:春招在即,义务帮大家看看简历吧》 一石激起千层浪,三天收到两百多封简历。 花光了两个星期的所有空闲时...

立即提问
相关内容推荐