会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 133413个问题
Python 全系列/第六阶段:数据库与AI协同技术实战/MySQL数据库的使用 38161楼
人工智能/第二阶段:人工智能基础-Python基础/Python集合操作 38163楼

老师您好请问下这个问题怎么解决 网上百度查没找到解决办法

package com.bjsxt.server;

import java.io.DataOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.net.ServerSocket;
import java.net.Socket;


public class TestServerV3 {

	public static void main(String[] args) {
		
		System.out.println("服务器已启动");
		//创建ServerSocket对象
		ServerSocket serverSocket = null;
		ObjectInputStream objectInputStream = null;
		DataOutputStream dataOutputStream = null;
		try {
			serverSocket = new ServerSocket(3333);
			//监听客户端
			Socket client = serverSocket.accept();
			//获取对象输入流
			objectInputStream = new ObjectInputStream(client.getInputStream());
			String massage="";
			//判断是否登录成功
			User user = (User)objectInputStream.readObject();
			if(user.getName().equals("xpx")&&user.getPassword().equals("123")) {
				massage="登录成功";
			}else {
				massage="密码错误请重新登录";
			}
			dataOutputStream = new DataOutputStream(client.getOutputStream());
			dataOutputStream.writeUTF(massage);
			System.out.println("IP地址:"+client.getInetAddress().getHostAddress());
			System.out.println("主机名:"+client.getInetAddress().getHostName());
		} catch (IOException | ClassNotFoundException e) {
			e.printStackTrace();
		}finally {
			if(dataOutputStream!=null) {
				try {
					dataOutputStream.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			if(objectInputStream!=null) {
				try {
					objectInputStream.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			if(serverSocket!=null) {
				try {
					serverSocket.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
	}
}
报错信息
Exception in thread "main" java.lang.ClassCastException: com.bjsxt.client.User cannot be cast to com.bjsxt.server.User
	at com.bjsxt.server.TestServerV3.main(TestServerV3.java:31)
package com.bjsxt.client;

import java.io.DataInputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;import java.io.ObjectInputStream.GetField;
import java.net.Socket;
import java.util.Scanner;


public class TestClientV3 {

	public static void main(String[] args) {
		Socket client = null;
		ObjectOutputStream objectOutputStream = null;
		DataInputStream dataInputStream = null;
		try {
			//创建Socket对象
			client = new Socket("127.0.0.1", 3333);
			//获取输出流
			objectOutputStream = new ObjectOutputStream(client.getOutputStream());
			objectOutputStream.writeObject(getUser());
			//获取输入流
			dataInputStream = new DataInputStream(client.getInputStream());
			System.out.println(dataInputStream.readUTF());
		} catch (IOException e) {
			e.printStackTrace();
			//关闭流
		}finally {
			if(dataInputStream!=null) {
				try {
					dataInputStream.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			if(objectOutputStream!=null) {
				try {
					objectOutputStream.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			if(client!=null) {
				try {
					client.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
	}
	
	/**
	 * 通过键盘录入用户登录信息
	 * @return
	 */
	public static User getUser() {
		Scanner scanner = new Scanner(System.in);
		System.out.println("请输入用户名:");
		String username = scanner.next();
		System.out.println("请输入用户密码:");
		String password = scanner.next();
		return new User(username,password);
	}
}

报错信息

java.io.EOFException
	at java.io.DataInputStream.readUnsignedShort(Unknown Source)
	at java.io.DataInputStream.readUTF(Unknown Source)
	at java.io.DataInputStream.readUTF(Unknown Source)
	at com.bjsxt.client.TestClientV3.main(TestClientV3.java:28)


JAVA 全系列/第二阶段:JAVA 基础深化和提高/网络编程(旧) 38164楼
Python 全系列/第二阶段:Python 深入与提高/异常机制 38166楼
JAVA 全系列/第一阶段:AI驱动的JAVA编程/面向对象详解和JVM底层内存分析 38168楼
Python 全系列/第八阶段:轻量级Web开发利器-Flask框架/虚拟环境 38172楼

不知道怎么了出了这个警告,然后tomcat访问8080也挂起了

image.png

信息:启动服务Tomcat

三月282020 10:51:23上午org.apache.catalina.core.StandardEngine startInternal

信息:启动Servlet引擎:Apache Tomcat/7.0.47

三月282020 10:51:27上午org.apache.catalina.core.ApplicationContext日志

信息:在类路径上未检测到Spring WebApplicationInitializer类型

三月282020 10:51:27上午org.apache.catalina.core.ApplicationContext日志

信息:初始化Spring根WebApplicationContext

log4j:警告找不到logger(org.springframework.web.context.ContextLoader)的附加程序。

log4j:WARN请正确初始化log4j系统。

log4j:WARN有关详细信息,请参见http://logging.apache.org/log4j/1.2/faq.html#noconfig。

[INFO] Creating Tomcat server configuration at D:\workspace\ego-manager-web\target\tomcat
[INFO] create webapp with contextPath: 
三月 28, 2020 10:51:23 上午 org.apache.coyote.AbstractProtocol init
信息: Initializing ProtocolHandler ["http-bio-8080"]
三月 28, 2020 10:51:23 上午 org.apache.catalina.core.StandardService startInternal
信息: Starting service Tomcat
三月 28, 2020 10:51:23 上午 org.apache.catalina.core.StandardEngine startInternal
信息: Starting Servlet Engine: Apache Tomcat/7.0.47
三月 28, 2020 10:51:27 上午 org.apache.catalina.core.ApplicationContext log
信息: No Spring WebApplicationInitializer types detected on classpath
三月 28, 2020 10:51:27 上午 org.apache.catalina.core.ApplicationContext log
信息: Initializing Spring root WebApplicationContext
log4j:WARN No appenders could be found for logger (org.springframework.web.context.ContextLoader).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.


JAVA 全系列/(旧的隐藏)第八阶段:电商高级项目_架构/编码/电商ego-基于SOA架构_Dubbo使用_逆向工程_分页插件完成商品查询 38174楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园
网站维护:百战汇智(北京)科技有限公司
京公网安备 11011402011233号    京ICP备18060230号-3    营业执照    经营许可证:京B2-20212637