赞
踩
目录
需求说明
建立在线迷你TXT小说的客户端和服务器端通信连接
分析
创建服务器端线程类,并循环监听状态
创建客户端,请求服务器并发送消息
服务器端响应客户端
需求说明
实现完成登录、注册、退出、返回功能
分析
技能分析:解析XML
使用dom4j解析XML文档的
下载路径:dom4j 1.6.1 API.1 API
需求说明
实现完成小说查询列表的功能
分析
通过获取服务端小说存放路径下所有文件
将序号与小说分别存放在map的key和value中
通过遍历map,在输入key获取小说名
需求说明
实现完成在线阅读小说功能
分析
通过遍历的小说目录选择阅读对象
将服务端目录小说对象添加到Map中
根据用户选择的序号,查找小说名和路径并显示内容
需求说明
实现完成下载小说功能
分析
在配制文件添加下载路径的配制项
根据用户选择的小说读取小说源文件
把读取的文件写到对应下载路径中
需求说明
实现完成上传小说功能
分析
根据用户输入的小说路径,读取源文件
根据配制文件的小说路径,将读取的源文件写入相应位置
刚下载的我们右键选择
- package com.lx.client;
-
- import java.io.IOException;
- import java.net.InetSocketAddress;
- import java.net.Socket;
- import java.util.Scanner;
-
- public class ClientTest {
-
-
-
-
- static Socket socket=null;
- Scanner sc =new Scanner(System.in);
- static UserClientService userClientService;
-
- public static void main(String[] args) throws IOException {
- ClientTest clientTest = new ClientTest();
- clientTest.clientInit();
- //封装了接收数据和发送数据的api 功能
- DataUtil dataUtil = new DataUtil(socket);
- userClientService= new UserClientService(dataUtil,new ResultUtil(clientTest,dataUtil));
- clientTest.welcome();
- }
-
- //初始化---连接服务器
- public void clientInit() throws IOException {
- //连接服务器
- socket = new Socket();
- socket.connect(new InetSocketAddress(8080));
- }
-
-
-
- //欢迎界面
- public void welcome() throws IOException {
- System.out.println("====欢迎来到哈哈小说系统====");
- System.out.println("-------1、登录系统-------");
- System.out.println("-------2、注册用户-------");
- System.out.println("-------3、退出系统-------");
- System.out.println("-----输入序号进行操作------");
- String no = sc.nextLine();
- if(no.equals("1")){
- userClientService.login();
- } else if (no.equals("2")) {//注册
- userClientService.register();
- }else {
- System.out.println("----欢迎下次使用本系统-----");
- System.exit(0);
- }
-
- }
-
-
- //登录之后的二级菜单
- public String menu(){
- //System.out.println("登录或者注册成功!!");
- System.out.println("-------选择序号操作------");
- System.out.println("-------1.阅读小说-------");
- System.out.println("-------2.上传小说-------");
- System.out.println("-------3.下载小说-------");
- System.out.println("-------4.退出系统-------");
- System.out.println("------请输入功能序号-----");
- String info = sc.nextLine();
- return info;
- }
-
-
-
-
-
-
-
- }
- package com.lx.client;
-
- import java.io.IOException;
- import java.net.InetSocketAddress;
- import java.net.Socket;
- import java.util.Scanner;
-
- public class ClientTest {
-
-
-
-
- static Socket socket=null;
- Scanner sc =new Scanner(System.in);
- static UserClientService userClientService;
-
- public static void main(String[] args) throws IOException {
- ClientTest clientTest = new ClientTest();
- clientTest.clientInit();
- //封装了接收数据和发送数据的api 功能
- DataUtil dataUtil = new DataUtil(socket);
- userClientService= new UserClientService(dataUtil,new ResultUtil(clientTest,dataUtil));
- clientTest.welcome();
- }
-
- //初始化---连接服务器
- public void clientInit() throws IOException {
- //连接服务器
- socket = new Socket();
- socket.connect(new InetSocketAddress(8080));
- }
-
-
-
- //欢迎界面
- public void welcome() throws IOException {
- System.out.println("====欢迎来到哈哈小说系统====");
- System.out.println("-------1、登录系统-------");
- System.out.println("-------2、注册用户-------");
- System.out.println("-------3、退出系统-------");
- System.out.println("-----输入序号进行操作------");
- String no = sc.nextLine();
- if(no.equals("1")){
- userClientService.login();
- } else if (no.equals("2")) {//注册
- userClientService.register();
- }else {
- System.out.println("----欢迎下次使用本系统-----");
- System.exit(0);
- }
-
- }
-
-
- //登录之后的二级菜单
- public String menu(){
- //System.out.println("登录或者注册成功!!");
- System.out.println("-------选择序号操作------");
- System.out.println("-------1.阅读小说-------");
- System.out.println("-------2.上传小说-------");
- System.out.println("-------3.下载小说-------");
- System.out.println("-------4.退出系统-------");
- System.out.println("------请输入功能序号-----");
- String info = sc.nextLine();
- return info;
- }
-
-
-
-
-
-
-
- }
- package com.lx.client;
-
- /**
- * 阅读;下载;上传功能实现
- */
-
- import com.lx.BookClientService;
- import com.lx.Contain;
- import com.lx.MessageEntity;
-
- import java.io.*;
- import java.util.Map;
- import java.util.Scanner;
- import java.util.concurrent.TimeUnit;
-
- public class ResultUtil {
- ClientTest ct;
- DataUtil dataUtil;
-
- byte[] bs = new byte[512];
-
- BookClientService bookClientService = new BookClientService();
-
- Scanner sc = new Scanner(System.in);
- ObjectOutputStream ois = null;
-
-
- public ResultUtil(ClientTest ct, DataUtil dataUtil) {
- this.ct = ct;
- this.dataUtil = dataUtil;
- }
-
- public void postUserResult(String result) throws IOException {
- if (result.equals(Contain.LOGINSUCRESULT)) {
- System.out.println("----【温馨提示】登录成功----");
- String info = ct.menu();
- postBookResult(info);
- } else if (result.equals(Contain.LOGINFAIRESULT)){
- System.out.println("【温馨提示】登录失败--重写操作");
- ct.welcome();
- } else if (result.equals(Contain.REGISTERSUCRESULT)) {
- System.out.println("----【温馨提示】注册成功----");
- String info = ct.menu();
- postBookResult(info);
-
- } else if (result.equals(Contain.REGISTERFAIRESULT)) {
- System.out.println("【温馨提示】注册失败--重写操作");
- ct.welcome();
- }
- }
-
-
- //统一处理二级菜单的 操作序号
- int page = 1;
- public void postBookResult(String info) throws IOException {
- if (info.equals("1")) {
-
- //查询小说列表
- //提示--输入小说名字进行阅读
- //把小说名字发送给服务器
- //服务器:通过IO流读取小说内容---字符流
- //BufferedReader br = null;
- // br.readLine()
- //下载之前先要做查询
- //List<String> list = bookClientService.queryPrintAllBook(dataUtil);
-
-
- Map<String, String> bookMap = bookClientService.queryPrintAllBook(dataUtil);
-
-
- System.out.println("请选择下面显示的小说名字进行阅读");
-
-
-
- for (Map.Entry<String, String> entry : bookMap.entrySet()) {
- System.out.println(entry.getKey() + "." + entry.getValue());
- }
-
- System.out.println("请输入小说序号:--------------");
- String bookName = sc.next();
- String bookNames = bookMap.get(bookName);//收集到用户输入的小说名字
-
-
- if (!bookMap.containsKey(bookName)){
- System.out.println("【温馨提示】没有该序号的小说");
- System.out.println("----请输入已有的小说序号----");
- }
-
- int page = 1;//记录页数
-
- while (true) {
-
- MessageEntity messageEntity = new MessageEntity();//new一个MessageEntity用于传信息
- messageEntity.setOprator(6);//当选择阅读功能时向服务端传入6,执行6操作
- messageEntity.setBookName(bookNames);
- messageEntity.setPage(page);
- dataUtil.sendData(messageEntity);
- String receiveData = dataUtil.receiveData();
- System.out.println(receiveData);
- System.out.println("----------------第"+page+"页----------------");
- System.out.println("-------------------------------------");
- System.out.println("请选择操作:1.下一页-2.上一页-3.返回-4.退出");
- int i = sc.nextInt();
- if (i == 1){
-
- if(receiveData.equals("end")){
- System.out.println("【温馨提示】这是小说的最后一页!");
- }else {
- page+=1;
- }
-
-
- }else if (i == 2){
- if(page ==1){
- System.out.println("【温馨提示】这是小说的第一页!");
-
- }else {
- page-=1;
-
- }
-
- }else if (i == 3){
- String r = ct.menu();
- postBookResult(r);//返回菜单
- break;
- }else if (i == 4){
- System.out.println("----欢迎下次使用本系统----");
- System.exit(0);//表示退出程序·
- }
- }
-
-
-
-
- } else if (info.equals("2")) {
-
- System.out.println("请输入小说路径和名字");
- // D:\code_new\novelReading\book\11天龙八部.txt
- String bookPathName = sc.next();
-
-
- //为了获取文件的大小 ---百分比
- File file = new File(bookPathName);
- //整个文件的字节数
- long length = file.length();
-
- System.out.println("文件长度=" + length + "个字节");
-
- //上传----先读到内容---写出去网络
- FileInputStream fis = new FileInputStream(file);
-
- //服务器那边不知道你的文件名 ---告诉服务器文件名
- String bookName = bookPathName.substring(bookPathName.lastIndexOf("\\"));
- int total = 0;//每次读取的字节数---读到文件末尾-1
- double temp = 0.0;//累计读了多少
- boolean flag = true;
- while ((total = fis.read(bs)) != -1) {
- temp += total;
- try {
- //为了效果----模拟网络延迟
- //本机不存在网络延迟----没有效果
- TimeUnit.MILLISECONDS.sleep(1);
- } catch (InterruptedException e) {
- throw new RuntimeException(e);
- }
- MessageEntity messageEntity = new MessageEntity();
- messageEntity.setOprator(3);
- if (flag) {
- messageEntity.setBookName(bookName);
- flag = false;
- }
- messageEntity.setContent(new String(bs, 0, total));
- dataUtil.sendData(messageEntity);
- //如果接受成功 这一次读取的内容上传成功
- String s = dataUtil.receiveData();
- System.out.print("已经完成:" + String.format("%.1f", (temp / length) * 100) + "%\r");
- }
-
- System.out.println("【温馨提示】上传进度=100%");
- System.out.println("-【温馨提示】上传完成-");
- MessageEntity messageEntity = new MessageEntity();
- messageEntity.setOprator(3);
- messageEntity.setContent("end");
- dataUtil.sendData(messageEntity);
-
- String r = ct.menu();
- postBookResult(r);
-
-
- } else if (info.equals("3")) {
- //下载之前先要做查询
-
- Map<String, String> bookMap = bookClientService.queryPrintAllBook(dataUtil);
-
- System.out.println("请选择下面显示的小说名字进行下载");
-
-
-
- for (Map.Entry<String, String> entry : bookMap.entrySet()) {
- System.out.println(entry.getKey() + "." + entry.getValue());
- }
-
-
- System.out.println("请输入小说序号:--------------");
- String bookName = sc.next();
- if (!bookMap.containsKey(bookName)){
- System.out.println("【温馨提示】没有该序号的小说");
- System.out.println("----请输入已有的小说序号----");
- }
- String bookNames = bookMap.get(bookName);//收集到用户输入的小说名字
-
-
-
- MessageEntity messageEntity = new MessageEntity();
- messageEntity.setOprator(4);
- messageEntity.setBookName(bookNames);
- dataUtil.sendData(messageEntity);
-
- File file = new File(Contain.downloadPath + "\\" + bookNames);
- if (!file.exists()) {
- file.createNewFile();
- }else {
- file.delete();
- file.createNewFile();
- }
- while (true) {
- String downLoadContent = dataUtil.receiveData();
-
-
- if (downLoadContent.endsWith("end")) {
- System.out.println("-----下载完成!----");
- FileOutputStream fos = new FileOutputStream(file, true);
- fos.write(downLoadContent.replaceAll("end","").getBytes());
- break;
- }
- FileOutputStream fos = new FileOutputStream(file, true);
- fos.write(downLoadContent.getBytes());
-
- }
-
-
- String s = ct.menu();
- postBookResult(s);
-
-
- }else if (info.equals("4")) {
- System.out.println("欢迎下次使用本系统!---");
- System.exit(0);//退出系统
- }
-
- }
-
-
- }
- package com.lx.client;
-
- import com.lx.MessageEntity;
- import com.lx.UserEntity;
-
- import java.io.IOException;
- import java.util.Scanner;
-
- public class UserClientService {
- DataUtil dataUtil;
- ResultUtil resultUtil;
- public UserClientService(DataUtil dataUtil, ResultUtil resultUtil){
- this.dataUtil =dataUtil;
- this.resultUtil = resultUtil;
- }
- Scanner sc =new Scanner(System.in);
- public void login() throws IOException {
-
- System.out.println("请输入登录的用户名:");
- String username = sc.nextLine();
- System.out.println("请输入登录的密码:");
- String password = sc.nextLine();
- UserEntity userEntity = new UserEntity();
- userEntity.setPassword(password);
- userEntity.setUsername(username);
- //chuangei fuwq
-
- MessageEntity messageEntity = new MessageEntity();
- messageEntity.setOprator(1);
- messageEntity.setUserEntity(userEntity);
-
-
- dataUtil.sendData(messageEntity);
-
- //接受数据
- String s = dataUtil.receiveData();
- //根据服务器返回的结果取完成不同的处理
- resultUtil.postUserResult(s);
-
- }
-
- public void register() throws IOException {
-
- System.out.println("请输入注册的用户id:");
- String userId = sc.nextLine();
- System.out.println("请输入注册的用户账号:");
- String username = sc.nextLine();
- System.out.println("请输入注册的密码:");
- String password = sc.nextLine();
-
- UserEntity userEntity = new UserEntity();
- userEntity.setUsername(username);
- userEntity.setId(Integer.parseInt(userId));
- userEntity.setPassword(password);
-
- MessageEntity messageEntity= new MessageEntity();
- messageEntity.setOprator(2);
- messageEntity.setUserEntity(userEntity);
-
- dataUtil.sendData(messageEntity);
- String s = dataUtil.receiveData();
- resultUtil.postUserResult(s);
- }
-
-
- }
- package com.lx.server;
-
- import com.lx.Contain;
- import com.lx.MessageEntity;
- import org.dom4j.DocumentException;
-
- import java.io.*;
- import java.net.InetSocketAddress;
- import java.net.ServerSocket;
- import java.net.Socket;
- import java.text.DecimalFormat;
-
- public class ServerApp {
-
- UserService userService = new UserService();
-
- public static final String REGISTERSUCRESULT="100";
- public static final String REGISTERFAIRESULT="101";
- public static final String LOGINSUCRESULT="200";
- public static final String LOGINFAIRESULT="201";
-
- Socket socket =null;
- OutputStream os=null;
- InputStream is =null;
-
- ObjectInputStream ois =null;
- ObjectOutputStream oos = null;
-
-
- byte[] bs = new byte[256];
- char[] cs = new char[1000];
-
- File uploadFile =null;
-
-
- public static void main(String[] args) throws IOException, ClassNotFoundException, DocumentException {
- new ServerApp().init();
-
- }
-
- public void init() throws IOException, ClassNotFoundException, DocumentException {
-
- ServerSocket serverSocket = new ServerSocket();
- serverSocket.bind(new InetSocketAddress(8080));
- //监听
- socket = serverSocket.accept();
- System.out.println("一个用户连接"+socket.getInetAddress());
-
- postClientMessage();
-
- //因为我服务器可能需要和客户端发送消息
- //由于发送的不是对象 所以不需要对象流
-
- }
-
- public void postClientMessage() throws IOException, ClassNotFoundException, DocumentException {
- //由于约定了发送的是messageEnttiy对象 所有通过对象流获取发送过来的对象
- if(ois==null) {
- os = socket.getOutputStream();
- is = socket.getInputStream();
- ois = new ObjectInputStream(is);
- }
-
- while (true) {
- //发送一个对象
- //获取输入流--->客户端可能给我发消息 读取客户端发送的消息
- //接受客户端的数据
- MessageEntity m = (MessageEntity) ois.readObject();
- if (m.getOprator() == 1) {//登录
- //客户端输入的用户名和密码
- String result = userService.login(m.getUserEntity());
- //把登录结果write给客户端
- os.write(result.getBytes());
- //为了服务器不停止---不断的阻塞读取客户端发送的消息
- } else if (m.getOprator() == 2) {
- String register = userService.register(m.getUserEntity());
- os.write(register.getBytes());
- } else if (m.getOprator() == 3) {//上传小说
-
- //当次上传小说的内容
- String content = m.getContent();
- if(content.equals("end")){
- //一部小说已经传完
- uploadFile=null;
- continue;
- }
- //这部分内容写到--对应的文件夹当中去---
- //1、文件文件
- if(uploadFile==null){
- uploadFile = new File(Contain.bookPath + "\\" + m.getBookName());
- }
- if (!uploadFile.exists()) {//如果文件不存在则创建
- uploadFile.createNewFile();
- }else {
- if (!XMLUtil.isEmpty(m.getBookName())) {//服务器已经存在小说 重写上传
- uploadFile.delete();//先删除
- uploadFile.createNewFile();//重写创建
- }
-
- }
- FileWriter fileWriter = new FileWriter(uploadFile,true);
- fileWriter.write(content);
- //这一次成功
- os.write("success".getBytes());
- fileWriter.close();
- }else if(m.getOprator()==4){//下载
-
- //获取现需要下载的小说的名字
- String bookName = m.getBookName();
- String downLoadPath = Contain.bookPath+"\\"+ bookName;
-
- File downLoadFile = new File(downLoadPath);
- FileInputStream fis = new FileInputStream(downLoadFile);
- DecimalFormat df = new DecimalFormat("#.0");
- int total =0;
-
- while ((total = fis.read(bs))!=-1){
- String message = new String(bs,0,total);
-
- os.write(message.getBytes());
- }
- //读完了
- os.write("end".getBytes());
- }else if(m.getOprator()==5){//查询小说列表
-
- String bookList="";
- File file = new File(Contain.bookPath);
- String[] list = file.list();
- for (String s : list) {
- bookList+=s+"-";
- }
- os.write(bookList.getBytes());
-
- }else if(m.getOprator()==6){//阅读
-
- //获取现需要下载的小说的名字
- String bookName = m.getBookName();//获取用户选择的小说名字
- String downLoadPath = Contain.bookPath+"\\"+ bookName;//获取到该小说在服务器的路径
- File downLoadFile = new File(downLoadPath);
- FileReader fr = new FileReader(downLoadFile);
- int total =0;
-
- int pages = (m.getPage()-1)*1000;
- fr.skip(pages);
- System.out.println(m.getPage());
- System.out.println(pages);
- if ((total = fr.read(cs))!=-1) {
-
- String message = new String(cs,0,total);
- os.write(message.getBytes());
- //System.out.println(message.getBytes());
- //os.write(pages);
- }else {
- //读完了
- os.write("end".getBytes());
- }
-
- }
- }
- }
- }
- package com.lx.server;
-
- import com.lx.UserEntity;
- import org.dom4j.DocumentException;
-
- import java.util.List;
-
- public class UserService {
-
- public String login(UserEntity entity) throws DocumentException {
- List<UserEntity> userEntities = XMLUtil.parseXml();
- //通过stream流来判断用户名和密码是否合格
- long count = userEntities.stream()
- .filter(e -> e.getUsername().equals(entity.getUsername()))
- .filter(e -> e.getPassword().equals(entity.getPassword())).count();
- if(count==1){
- return ServerApp.LOGINSUCRESULT;
- }else {
- return ServerApp.LOGINFAIRESULT;
- }
- }
-
-
- public String register(UserEntity userEntity){
- try {
- //注册成功
- XMLUtil.updateXml(userEntity);
- return ServerApp.REGISTERSUCRESULT;
- }catch (Exception e){
- //注册失败
- e.printStackTrace();
- return ServerApp.REGISTERFAIRESULT;
- }
-
- }
- }
- package com.lx.server;
-
- import com.lx.UserEntity;
- import org.dom4j.Document;
- import org.dom4j.DocumentException;
- import org.dom4j.Element;
- import org.dom4j.io.OutputFormat;
- import org.dom4j.io.SAXReader;
- import org.dom4j.io.XMLWriter;
-
- import java.io.File;
- import java.io.FileWriter;
- import java.io.IOException;
- import java.util.ArrayList;
- import java.util.Iterator;
- import java.util.List;
-
- public class XMLUtil {
-
- static List<UserEntity> list = new ArrayList<>();
-
-
- public static List<UserEntity> getList() {
- return list;
- }
-
- static String xmlFilePath = "D:\\桌面\\课件\\java\\14.在线小说阅读项目资料\\client2\\server\\src\\Users.xml";
-
- static Document document = null;
- /**
- * 获取所有xml当中的元素
- * @return
- * @throws DocumentException
- */
- public static List<UserEntity> parseXml() throws DocumentException {
- list.clear();
- Element rootElement = init();
- //遍历根节点下面所有的节点
- Iterator<Element> iterator = rootElement.elementIterator();
- while (iterator.hasNext()){
- //一个子元素---根元素下面的子元素
- Element element = iterator.next();
- //获取元素的属性
- // element.attribute("userId");
- Element username = element.element("username");
- String usernameValue = username.getStringValue();
- Element pwd = element.element("pwd");
- String pwdValue = pwd.getStringValue();
- UserEntity userEntity = new UserEntity();
- userEntity.setUsername(usernameValue);
- userEntity.setPassword(pwdValue);
- list.add(userEntity);
-
- }
-
-
- return list;
- }
-
-
-
- public static void updateXml(UserEntity userEntity) throws IOException, DocumentException {
-
- Element rootElement = init();
- //往根元素下面添加一个元素 user
- Element element = rootElement.addElement("user");
- //给先添加的user元素添加一个属性 userId
- element.addAttribute("userId",userEntity.getId()+"");
-
- element.addElement("username").setText(userEntity.getUsername());
-
- element.addElement("pwd").setText(userEntity.getPassword());
-
- OutputFormat format = OutputFormat.createPrettyPrint();
- format.setEncoding("UTF-8");
- FileWriter fw = new FileWriter(xmlFilePath);
- XMLWriter xw = new XMLWriter(fw,format);
- xw.write(document);
- xw.close();
- fw.close();
-
- }
-
-
-
- public static Element init() throws DocumentException {
-
- List<UserEntity> list = new ArrayList<>();
-
- File xmlFile = new File(xmlFilePath);
- //实例化SAXReader对象 读取xml
- SAXReader saxReader = new SAXReader();
- //整个xml的内容----Document
- document = saxReader.read(xmlFile);
- //根元素节点
- Element rootElement = document.getRootElement();
-
- return rootElement;
- }
-
-
- //判断s 是否为null 或者“”
- public static boolean isEmpty(String s){
- if(s==null){
- return true;
- }else if(s.equals("")){
- return true;
- }
- return false;
- }
-
- }
- package com.lx;
-
- import com.lx.client.DataUtil;
-
- import java.io.IOException;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
-
- public class BookClientService {
-
- //查询服务器上小说列表
- public Map<String, String> queryPrintAllBook(DataUtil dataUtil) throws IOException {
- List<String> list = new ArrayList<>();
- Map<String,String> map = new HashMap<>();
- MessageEntity messageEntity =new MessageEntity();
- //只需要带一个操作
- messageEntity.setOprator(5);
- dataUtil.sendData(messageEntity);
- //阻塞
- String s = dataUtil.receiveData();
- String[] split = s.split("-");
-
- int i =1;
- for (String s2 : list) {
- map.put(i+"",s2);
-
- i++;
- }
- return map;
- }
- }
- package com.lx;
-
- public class Contain {
- //默认的下载路径(此处应将两个路径修改为绝对路径即完整路径)
- public static final String downloadPath="src\\com\\lx\\client\\book";
- //服务端保存的小说路径
- public static final String bookPath = "src\\com\\lx\\server\\book";
-
-
-
- public static final String REGISTERSUCRESULT="100";
- public static final String REGISTERFAIRESULT="101";
-
- public static final String LOGINSUCRESULT="200";
- public static final String LOGINFAIRESULT="201";
-
- public static final String FLAGSTR="j#";
- }
- package com.lx;
-
- import java.io.Serializable;
-
- public class MessageEntity implements Serializable {
- //执行什么操作
- /**
- * oprator
- * 1、登录
- * 2、注册
- * 3、选择阅读小说
- * 4、上传小说
- * 5、下载小说
- */
-
- private String bookName;//书名
- private String content;//传输的内容
- private int page;//记录页码
- private int oprator;//operate功能选项
- private UserEntity userEntity;
-
-
- public void setBookName(String bookName) {
- this.bookName = bookName;
- }
-
- public String getBookName() {
- return bookName;
- }
-
- public void setContent(String content) {
- this.content = content;
- }
-
- public String getContent() {
- return content;
- }
-
- public int getOprator() {
- return oprator;
- }
-
- public void setOprator(int oprator) {
- this.oprator = oprator;
- }
-
- public UserEntity getUserEntity() {
- return userEntity;
- }
-
- public void setUserEntity(UserEntity userEntity) {
- this.userEntity = userEntity;
- }
-
- public int getPage() {
- return page;
- }
-
- public void setPage(int page) {
- this.page = page;
- }
- }
- package com.lx;
-
- import java.io.Serializable;
-
- public class UserEntity implements Serializable {
-
- private String username;//用户名,账号
- private String password;//密码
- private Integer id;//id
-
-
- public String getUsername() {
- return username;
- }
-
- public void setUsername(String username) {
- this.username = username;
- }
-
- public String getPassword() {
- return password;
- }
-
- public void setPassword(String password) {
- this.password = password;
- }
-
- public Integer getId() {
- return id;
- }
-
- public void setId(Integer id) {
- this.id = id;
- }
- }
输入记录的账号密码进行登陆
通过本地绝对路径上传到服务端,并显示上传进度
通过输入相应字符实现翻页
在项目中,我们通过创建客户端和服务器端,使用Socket编程实现了客户端和服务器端之间的通信。通过IO流和字符流,实现了小说的异步传输,提高了数据传输的效率和用户的阅读体验。
项目的主要功能包括登录、注册、退出、返回功能,以及小说查询、在线阅读、下载和上传功能。用户可以通过登录功能进行账号验证,并可以注册新账号。在查询功能中,用户可以根据关键字、分类等条件进行小说的查询,并以列表形式展示查询结果。在阅读功能中,用户可以在线阅读小说,并进行字体调整、自动书签等个性化设置。此外,用户还可以将小说下载到本地设备,以便离线阅读。作者可以通过上传功能将自己的小说上传到系统中,供其他用户阅读。
在项目的实现中,需要编写客户端和服务器端的代码,以实现功能的交互与通信。前端界面可以通过其他技术实现,例如使用HTML、CSS和JavaScript等前端开发技术。
总的来说,该项目利用Java的网络编程和IO流特性,实现了一个基于网络的在线小说阅读系统。通过提供方便的登录、注册、查询、阅读、下载和上传功能,为用户提供了优质的在线阅读体验。项目的实现可以进一步完善和扩展,例如引入数据库来存储用户信息和小说数据,加入缓存机制以提高系统性能等。
总而言之,开发基于Java的在线小说阅读系统是一项具有挑战性但非常有意义的任务。通过克服技术难题、合理设计架构和关注用户体验,可以实现一个高效、稳定且易于使用的在线阅读平台。这个项目也为我提供了宝贵的学习和成长机会,拓展了我的技术能力。我期待能够继续探索和完善这个项目,并将所学应用于未来的项目开发中。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。