北大青鸟第一单元项目 (小说管理系统)

注意:

   此项目使用DOM4j 解析XML文件 请自备DOM4j 并导入

 

小说类

View Code
 1 package books;
 2 
 3 import java.io.Serializable;
 4 
 5 public class Book implements Serializable {
 6     private String booktype;            //小说类型
 7     private String bookname;           //小说名称
 8     private String bookauthor;         //小说作者
 9     private String bookintroduction;   //小说简介
10     private String bookContent;      //小说内容
11     
12     
13     
14     public String getBooktype() {
15         return booktype;
16     }
17     public void setBooktype(String booktype) {
18         this.booktype = booktype;
19     }
20     public String getBookname() {
21         return bookname;
22     }
23     public void setBookname(String bookname) {
24         this.bookname = bookname;
25     }
26     public String getBookauthor() {
27         return bookauthor;
28     }
29     public void setBookauthor(String bookauthor) {
30         this.bookauthor = bookauthor;
31     }
32     public String getBookintroduction() {
33         return bookintroduction;
34     }
35     public void setBookintroduction(String bookintroduction) {
36         this.bookintroduction = bookintroduction;
37     }
38     public String getBookContent() {
39         return bookContent;
40     }
41     public void setBookContent(String bookContent) {
42         this.bookContent = bookContent;
43     }
44     
45     
46 
47 }

序列化传送对象

View Code
 1 package books;
 2 
 3 import java.io.File;
 4 import java.io.Serializable;
 5 import java.util.List;
 6 
 7 /**
 8  * 序列化传送对象
 9  * @author Empty-heart
10  *
11  */
12 public class Datas implements Serializable {
13     private String flag;               //功能块标记
14     private String type;               //小说类型标记
15     private Use use;                   //用户类  
16     private Book book;                 //小说类
17     private List list;                 //集合类
18     private File file;                 //文件
19     private String path;               //小说路径
20 
21     public String getPath() {
22         return path;
23     }
24 
25     public void setPath(String path) {
26         this.path = path;
27     }
28 
29     public File getFile() {
30         return file;
31     }
32 
33     public void setFile(File file) {
34         this.file = file;
35     }
36 
37     public List getList() {
38         return list;
39     }
40 
41     public void setList(List list) {
42         this.list = list;
43     }
44 
45     public String getType() {
46         return type;
47     }
48     
49     public void setType(String type) {
50         this.type = type;
51     }
52     public Book getBook() {
53         return book;
54     }
55 
56     public void setBook(Book book) {
57         this.book = book;
58     }
59 
60     public Use getUse() {
61         return use;
62     }
63 
64     public void setUse(Use use) {
65         this.use = use;
66     }
67 
68     public String getFlag() {
69         return flag;
70     }
71 
72     public void setFlag(String flag) {
73         this.flag = flag;
74     }
75  
76 }


客户端功能类

View Code
  1 package books;
  2 
  3 import java.io.BufferedReader;
  4 import java.io.File;
  5 import java.io.FileInputStream;
  6 import java.io.IOException;
  7 import java.io.InputStreamReader;
  8 import java.io.ObjectInputStream;
  9 import java.io.ObjectOutputStream;
 10 import java.net.Socket;
 11 import java.util.List;
 12 
 13 import javax.swing.Box.Filler;
 14 
 15 
 16 public class scoket_data {
 17      Socket s = null;
 18      ObjectOutputStream objout = null;
 19      ObjectInputStream objin = null;
 20      Datas datas = null;
 21      
 22      /**
 23       * 创建Socket端点
 24       * 创建输入、输出流
 25       */
 26     public void initSocket(){
 27         try {
 28             s = new Socket("192.168.10.222", 1314);
 29             objout = new ObjectOutputStream(s.getOutputStream());
 30             objin = new ObjectInputStream(s.getInputStream());
 31             datas = new Datas();
 32         } catch (Exception e) {
 33             e.printStackTrace();
 34         }
 35     }
 36     
 37     /**
 38      * 关闭各种资源
 39      */
 40     public void closeSocket(){
 41         try {
 42             objin.close();
 43             objout.close();
 44             s.close();
 45         } catch (IOException e) {
 46             e.printStackTrace();
 47         }
 48     }
 49     
 50     /**
 51      * 登陆功能
 52      */
 53     public Datas login(String usename, String password) {
 54         try {
 55             initSocket();
 56             datas.setFlag(Use.SYS_LOGIN);
 57             Use use = new Use();
 58             use.setUsename(usename);
 59             use.setPassword(password);
 60             datas.setUse(use);
 61             objout.writeObject(datas);
 62             datas = (Datas) objin.readObject();
 63         } catch (IOException e) {
 64             e.printStackTrace();
 65         } catch (ClassNotFoundException e) {
 66             e.printStackTrace();
 67         }finally {
 68             closeSocket();
 69         }
 70         return datas;
 71     }
 72 
 73     /**
 74      * 注册功能
 75      * @param name
 76      * @param pass1
 77      * @return
 78      */
 79     public Datas registration(String name, String pass1) {
 80           try {
 81               initSocket();
 82               datas.setFlag(Use.SYS_REGISTRATION);
 83               Use use = new Use();
 84               use.setUsename(name);
 85               use.setPassword(pass1);
 86               datas.setUse(use);
 87             objout.writeObject(datas);
 88             datas = (Datas) objin.readObject();
 89         } catch (IOException e) {
 90             e.printStackTrace();
 91         } catch (ClassNotFoundException e) {
 92             e.printStackTrace();
 93         }finally {
 94             closeSocket();
 95         }
 96         return datas;
 97     }
 98 
 99     /**
100      * 查看小说
101      * @return
102      */
103     public Datas book(String type) {
104         try {
105             initSocket();
106             datas.setFlag(Use.SYS_BOOK);
107             if(type.equals("wuxia")) {
108             datas.setType(Use.SYS_WUXIABOOK);
109             }else if(type.equals("yanqing")) {
110                 datas.setType(Use.SYS_YANQINGBOOK);
111             }
112             objout.writeObject(datas);
113             datas = (Datas) objin.readObject();
114         } catch (IOException e) {
115             e.printStackTrace();
116         } catch (ClassNotFoundException e) {
117             e.printStackTrace();
118         }finally {
119             closeSocket();
120         }
121         return datas;
122     }
123 
124     /**
125      * 下载小说
126      * @param bookname
127      */
128     public Datas downbook(String type, String bookname) {
129         try {
130             initSocket();
131             datas.setFlag(Use.SYS_DOWNLOAD);
132             Book book = new Book();
133             book.setBookname(bookname);
134             book.setBooktype(type);
135             datas.setBook(book);
136             objout.writeObject(datas);
137             datas = (Datas) objin.readObject();
138         } catch (IOException e) {
139             e.printStackTrace();
140         } catch (ClassNotFoundException e) {
141             e.printStackTrace();
142         }finally {
143             closeSocket();
144         }
145         return datas;
146     }
147 
148     /**
149      * 上传小说
150      * @param bookname
151      * @param bookauthor
152      * @param bookintroduction
153      * @param path
154      * @return
155      */
156     public Datas upbook(String bookname, String bookauthor,
157             String bookintroduction, String path, String type) {
158          
159         try {
160             FileInputStream fis = new FileInputStream(path);
161             System.setIn(fis);
162             BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));
163             String str1 = "";
164             String str2 = null;
165             while((str2 = buf.readLine()) != null){
166                 str1 = str1.concat(str2);
167             }
168             fis.close();
169             initSocket();
170             datas.setFlag(Use.SYS_UPLOAD);
171             datas.setPath(path);
172             Book book = new Book();
173             book.setBookname(bookname);
174             book.setBookauthor(bookauthor);
175             book.setBookintroduction(bookintroduction);
176             book.setBooktype(type);
177             book.setBookContent(str1);
178             datas.setBook(book);
179             objout.writeObject(datas);
180             datas = (Datas) objin.readObject();
181         } catch (IOException e) {
182             e.printStackTrace();
183         } catch (ClassNotFoundException e) {
184             e.printStackTrace();
185         }finally {
186             closeSocket();
187             
188         }
189         
190         return datas;
191     }
192 
193 }

服务端功能类

View Code
  1 package books;
  2 
  3 import java.io.File;
  4 import java.io.FileNotFoundException;
  5 import java.io.FileOutputStream;
  6 import java.io.IOException;
  7 import java.io.OutputStreamWriter;
  8 import java.io.PrintWriter;
  9 import java.io.UnsupportedEncodingException;
 10 import java.util.ArrayList;
 11 import java.util.Iterator;
 12 import java.util.List;
 13 
 14 import org.dom4j.Document;
 15 import org.dom4j.DocumentException;
 16 import org.dom4j.Element;
 17 import org.dom4j.io.OutputFormat;
 18 import org.dom4j.io.SAXReader;
 19 import org.dom4j.io.XMLWriter;
 20 
 21 
 22 
 23 public class server_data {
 24     /**
 25      * 登陆功能
 26      * 建立document对象 读取配置文件
 27      */
 28     public int Login(String usename, String password) {
 29         int val = 0;     //返回值 
 30         SAXReader sax = new SAXReader();
 31         try {
 32             Document doc = sax.read(new File("user.xml"));
 33             List<?> list = doc.selectNodes("/uses/use");
 34             Iterator<?> iterator = list.iterator();
 35             while(iterator.hasNext()) {
 36                 Element use = (Element) iterator.next();
 37                 String name = use.attribute("usename").getValue();
 38                 String pass = use.attribute("password").getValue();
 39                 if(name.equals(usename) && pass.equals(password)) {        
 40                     val = 1;
 41                 }
 42             }
 43             
 44         } catch (DocumentException e) {
 45             e.printStackTrace();
 46         }
 47 
 48         return val;
 49     }
 50 /**
 51  * 注册功能
 52  * @param usename
 53  * @param password
 54  * @return
 55  */
 56     public int registration(String usename, String password) {
 57         int val = 0;
 58         try {
 59             SAXReader sax = new SAXReader();
 60             Document doc = sax.read(new File("user.xml"));
 61             List<?> listuse = doc.selectNodes("/uses/use");
 62             Iterator<?> iterator = listuse.iterator();
 63             while(iterator.hasNext()) {
 64                 Element elementuse = (Element) iterator.next();
 65                 String nameuse = elementuse.attribute("usename").getValue();
 66                 if(!(nameuse.equals(usename))) {
 67                     List<?> listuses = doc.selectNodes("uses");
 68                     Element uses = (Element) listuses.get(0);
 69                     Element use = uses.addElement("use");
 70                     use.addAttribute("usename", usename);
 71                     use.addAttribute("password", password);
 72 
 73                     XMLWriter writer = new XMLWriter(new FileOutputStream(new File("user.xml")));
 74                     writer.write(doc);
 75                     writer.close();
 76                     val = 1;
 77                 }
 78             }
 79             
 80         } catch (DocumentException e) {
 81             e.printStackTrace();
 82         } catch (UnsupportedEncodingException e) {
 83             e.printStackTrace();
 84         } catch (FileNotFoundException e) {
 85             e.printStackTrace();
 86         } catch (IOException e) {
 87             e.printStackTrace();
 88         }
 89         return val;
 90     }
 91     
 92     /**
 93      * 武侠小说集合
 94      */
 95     public  List<Book> wuxiabooklist() {
 96         try {
 97             SAXReader sax = new SAXReader();
 98             Document doc = sax.read(new File("wuxiabooks.xml"));
 99             List<?> list = doc.selectNodes("/books/book");
100             Iterator<?> iterator = list.iterator();
101             List<Book> booklist = new ArrayList<Book>();
102             while(iterator.hasNext()) {
103                 Book book = new Book();
104                 Element bookx = (Element) iterator.next();
105                 String bookname = bookx.attribute("bookname").getValue();
106                 String bookauthor = bookx.attribute("bookauthor").getValue();
107                 String bookintroduction = bookx.attribute("bookintroduction").getValue();
108                 String bookContent = bookx.attribute("bookContent").getValue();
109                 
110                 book.setBookname(bookname);
111                 book.setBookauthor(bookauthor);
112                 book.setBookintroduction(bookintroduction);
113                 book.setBookContent(bookContent);
114                 booklist.add(book);
115             }
116             return booklist;        
117         } catch (DocumentException e) {
118             e.printStackTrace();
119         }
120         return null;
121         
122     }
123     
124     /**
125      * 言情小说集合
126      * @return
127      */
128     public  List<Book> yanqingbooklist() {
129         try {
130             SAXReader sax = new SAXReader();
131             Document doc = sax.read(new File("yanqingbooks.xml"));
132             List<?> list = doc.selectNodes("/books/book");
133             Iterator<?> iterator = list.iterator();
134             List<Book> booklist = new ArrayList<Book>();
135             while(iterator.hasNext()) {
136                 Book book = new Book();
137                 Element bookx = (Element) iterator.next();
138                 String bookname = bookx.attribute("bookname").getValue();
139                 String bookauthor = bookx.attribute("bookauthor").getValue();
140                 String bookintroduction = bookx.attribute("bookintroduction").getValue();
141                 String bookContent = bookx.attribute("bookContent").getValue();
142                 
143                 book.setBookname(bookname);
144                 book.setBookauthor(bookauthor);
145                 book.setBookintroduction(bookintroduction);
146                 book.setBookContent(bookContent);
147                 
148                 booklist.add(book);
149             }
150             
151             return booklist;        
152         } catch (DocumentException e) {
153             e.printStackTrace();
154         }
155         return null;
156         
157     }
158     public File downbook(String type ,String bookname) {
159         try {
160             File file = new File("F://downbook");
161             file.mkdir();
162             File filebook = new File(file, bookname + ".txt");
163             filebook.createNewFile();
164             List list = new ArrayList();
165             if(type.equals("wuxia")) {
166                 list = wuxiabooklist();
167             }else if(type.equals("yanqing")) {
168                 list = yanqingbooklist();
169             }
170             for(int i = 0; i<list.size(); i++) {
171                 Book book = (Book) list.get(i);
172                 if(bookname.equals(book.getBookname()));
173                 String bookContent = book.getBookContent();
174                 PrintWriter pw = new PrintWriter(filebook);
175                 pw.write(bookContent);
176                 pw.flush();
177             }
178             return file;
179         } catch (FileNotFoundException e) {
180             e.printStackTrace();
181         } catch (IOException e) {
182             e.printStackTrace();
183         }
184         return null;
185     }
186     
187     /**
188      * 长传小说
189      * @param book
190      * @param file
191      * @return
192      */
193     public int upbook(Book book, String path) {
194         int val = 0;
195         SAXReader sax = new SAXReader();
196         Document doc = null;
197         File files = null;
198             try {
199 /*                FileReader fr = new FileReader(new File(path));
200                 char[] buf = new char[1024];
201                 fr.read(buf);
202                 String by = buf.toString();
203                 buf.*/
204                 if(book.getBooktype().equals("wuxia")) {
205                  doc = sax.read(new File("wuxiabooks.xml"));
206                  files = new File("wuxiabooks.xml");
207                 }else if(book.getBooktype().equals("yanqing")) {
208                  doc = sax.read(new File("yanqingbooks.xml"));
209                  files = new File("yanqingbooks.xml");
210                 }
211                 List list = doc.selectNodes("/books");
212                 Element books = (Element) list.get(0);
213                 Element upbook = books.addElement("book");
214                 upbook.addAttribute("bookname", book.getBookname());
215                 upbook.addAttribute("bookauthor", book.getBookauthor());
216                 upbook.addAttribute("bookintroduction", book.getBookintroduction());
217                 upbook.addAttribute("bookContent", book.getBookContent());
218                 val = 1;
219 //                fr.close();
220                 
221                 XMLWriter writer =  null;//new XMLWriter(new FileWriter(files));
222                 OutputFormat format = OutputFormat.createPrettyPrint();
223                 format.setEncoding("GBK");
224                 writer = new XMLWriter(new OutputStreamWriter(new 
225                         FileOutputStream(files), format.getEncoding()), format);
226                          writer.write(doc);
227 //                writer.write(doc);
228                 writer.close();
229             } catch (DocumentException e) {
230                 e.printStackTrace();
231             } catch (FileNotFoundException e) {
232                 e.printStackTrace();
233             } catch (IOException e) {
234                 e.printStackTrace();
235             }
236             
237         
238         return val;
239     }
240 }

服务端

View Code
 1 package books;
 2 
 3 import java.io.File;
 4 import java.io.IOException;
 5 import java.io.ObjectInputStream;
 6 import java.io.ObjectOutputStream;
 7 import java.net.ServerSocket;
 8 import java.net.Socket;
 9 import java.util.ArrayList;
10 import java.util.List;
11 
12 public class serversocket {
13 
14     /**
15      * @param args
16      * @throws IOException
17      * @throws ClassNotFoundException
18      */
19     public static server_data server = new server_data();
20     public static int val = 0; // 标记
21     public static Datas datas = new Datas();
22     public static void main(String[] args) {
23         ServerSocket ss = null;
24         ObjectInputStream objin = null;
25         ObjectOutputStream objout= null;
26         Socket s = null;
27         try {
28             ss = new ServerSocket(1314);
29             while (true) {
30                  s = ss.accept();
31                 System.out.println(s.getInetAddress().getHostAddress());
32                 
33                  objin = new ObjectInputStream(s.getInputStream());
34                  objout = new ObjectOutputStream(
35                         s.getOutputStream());
36                 
37                 datas = (Datas) objin.readObject();
38                 if (datas.getFlag().equals(Use.SYS_LOGIN)) {
39                     val = server.Login(datas.getUse().getUsename(), datas.getUse()
40                             .getPassword());
41                     if (val == 1) {
42                         datas.setFlag(Use.SYS_OK);
43                     } 
44                     objout.writeObject(datas);
45                 }else if(datas.getFlag().equals(Use.SYS_REGISTRATION)) {
46                     val = server.registration(datas.getUse().getUsename(), datas.getUse().getPassword());
47                     if(val == 1) {
48                         datas.setFlag(Use.SYS_OK);
49                     }
50                     objout.writeObject(datas);
51                 }else if(datas.getFlag().equals(Use.SYS_BOOK)) {
52                     List list = new ArrayList();
53                     if(datas.getType().equals(Use.SYS_WUXIABOOK)) {
54                         list = server.wuxiabooklist();
55                     }else if(datas.getType().equals(Use.SYS_YANQINGBOOK)){
56                         list = server.yanqingbooklist();

57                     }
58                     datas.setList(list);
59                     objout.writeObject(datas);
60                 }else if(datas.getFlag().equals(Use.SYS_DOWNLOAD)) {
61                     File file = server.downbook(datas.getBook().getBooktype(), datas.getBook().getBookname());
62                     datas.setFlag(Use.SYS_OK);
63                     datas.setFile(file);
64                     objout.writeObject(datas);
65                 }else if(datas.getFlag().equals(Use.SYS_UPLOAD)) {
66                     int val = server.upbook(datas.getBook(), datas.getPath());
67                     if(val == 1) {
68                         datas.setFlag(Use.SYS_OK);
69                     }
70                     objout.writeObject(datas);
71                 }
72             }     
73         } catch (IOException e) {
74             e.printStackTrace();
75         } catch (ClassNotFoundException e) {
76             e.printStackTrace();
77         }finally {
78             try {
79                 s.close();
80                 ss.close();
81                 objin.close();
82                 objout.close();
83             } catch (IOException e) {
84                 e.printStackTrace();
85             }
86         }
87     }
88 }

客户端

View Code
  1 package books;
  2 
  3 import java.util.ArrayList;
  4 import java.util.Scanner;
  5 
  6 
  7 
  8 public class socket {
  9 
 10     /**
 11      * @param args
 12      * @throws IOException 
 13      * @throws UnknownHostException 
 14      */
 15     public static Scanner scanner = new Scanner(System.in);
 16     public static scoket_data socket = new scoket_data();
 17     public static Datas datas = new Datas();
 18     public static void main(String[] args) {
 19              
 20 
 21  
 22             UI();
 23             System.out.println("程序结束 !");
 24         
 25     }
 26 
 27     public static void UI() {
 28             System.out.println("欢迎使用在线迷你TXT小说管理器");
 29             System.out.println("------------------------------------");
 30             System.out.println("1、登陆\n2、注册\n3、退出");
 31             System.out.println("------------------------------------");
 32             System.out.print("请选择:");
 33             int i =  scanner.nextInt();
 34             if(i == 1) {
 35                   log();
 36             }else if(i==2) {
 37                 while(true) {
 38                     System.out.println("```````````````````````````````");
 39                     System.out.println("当前操作:注册用户");
 40                     System.out.println("```````````````````````````````");
 41                     System.out.print("请输入用户名:");
 42                     String name = scanner.next();
 43                     System.out.print("请输入密码:");
 44                     String pass1 = scanner.next();
 45                     System.out.print("确认密码:");
 46                     String pass2 = scanner.next();
 47                     if(pass1.equals(pass2)) {
 48                         datas = socket.registration(name, pass1);
 49                         if(datas.getFlag().equals(Use.SYS_OK)) {
 50                             System.out.println("用户注册成功,请登陆!");
 51                             log();
 52                             break;
 53                         }else {
 54                             System.out.println("用户已存在!");
 55                         }
 56                     }else {
 57                         System.out.println("两次密码不同!");
 58                     }
 59                 }
 60 
 61                 
 62             }
 63     }
 64     
 65     /**
 66      * 用户登陆界面
 67      */
 68     public static void log() {
 69         while(true) {
 70             System.out.println("```````````````````````````````");
 71             System.out.println("当前操作:用户登陆");
 72             System.out.println("```````````````````````````````");
 73             System.out.print("请输入用户名:");
 74             String name = scanner.next();
 75             System.out.print("请输入密码:");
 76             String password = scanner.next();
 77             datas = socket.login(name, password);
 78             if(datas.getFlag().equals(Use.SYS_OK)) {
 79                 lookbook();
 80                 break;
 81             }else {
 82                 System.out.println("*************************************");
 83                 System.out.println("登陆失败!");
 84                 System.out.println("*************************************");
 85             }
 86        }
 87     }           
 88     /**
 89      * 登陆成功
 90      * 小说列表界面
 91      */
 92     public static void lookbook() {
 93         System.out.println("*************************************");
 94         System.out.println("登陆成功!");
 95         System.out.println("*************************************");
 96         System.out.println("-------------------------------------");
 97         System.out.println("0、返回上级菜单\n1、武侠\n2、言情");
 98         System.out.println("-------------------------------------");
 99         System.out.print("请选择:");
100         int val = scanner.nextInt();
101         if(val == 0) {
102             UI();
103         }else if(val == 1) {
104             booklist("wuxia");
105         }else if(val == 2) {
106             booklist("yanqing");
107         }
108     }
109     
110     /**
111      * 小说选择及查看
112      */
113     public static void booklist(String type) {
114     System.out.println("--------------------武俠小说列表--------------------");
115     System.out.println("序号\t名称\t\t作者\t\t简介");
116     if(type.equals("wuxia")){
117        datas = socket.book(type);
118     }else if(type.equals("yanqing")) {
119         datas = socket.book(type);
120     }
121     ArrayList list = (ArrayList) datas.getList();
122     for(int i=0; i<list.size(); i++) {
123         Book book =  (Book) list.get(i);
124         System.out.println((i+1) + "\t" + book.getBookname() + "\t\t" +
125         book.getBookauthor() + "\t\t" + book.getBookintroduction());
126     }
127     System.out.println("--------------------小说列表结束--------------------");
128     System.out.print("阅读和下载请选择文件序号,上传TXT请输入-1,返回请输入0:");
129     int v = scanner.nextInt();
130     if(v == 0) {
131         lookbook();
132     }else if(v == -1) {
133         upbook(type);
134         }else if(v < (list.size()+1)){
135             Book book = (Book) list.get(v-1);
136             System.out.println(book.getBookContent() + "\n");
137             System.out.println("......,省略内容,请下载阅读");
138             System.out.print("继续显示列表请输入1,下载TXT请输入2:");
139             int down = scanner.nextInt();
140             if(down == 1) {
141                 booklist(type);
142             }else if (down == 2) {
143                 datas = socket.downbook(type,book.getBookname());
144                 if(datas.getFlag().equals(Use.SYS_OK)) {
145                     System.out.println("*************************************");
146                     System.out.println("下载后的文件名是:" + book.getBookname() + ".txt");
147                     System.out.println("下载后的路径是:" + datas.getFile().getPath());
148                     System.out.println("文件下载结果:true");
149                     System.out.println("*************************************");
150                     System.out.print("返回请输入0:");
151                     int y = scanner.nextInt();
152                     if(y == 0) {
153                         lookbook();
154                     }
155                 }else {
156                     System.out.println("服务器上的小说不存在,请联系管理员!");
157                 }
158             }
159        }   
160        }
161   
162     
163     /**
164      * 上传小说
165      */
166     public static void upbook(String type) {
167         System.out.print("请输入小说名:");
168         String bookname = scanner.next();
169         System.out.print("请输入作者:");
170         String bookauthor = scanner.next();
171         System.out.print("请输入简介:");
172         String bookintroduction = scanner.next();
173         System.out.print("请输入上传文件的txt(请注意路径用//):");
174         String path = scanner.next();
175         datas = socket.upbook(bookname, bookauthor, bookintroduction, path, type); 
176         if(datas.getFlag().equals(Use.SYS_OK)) {
177                System.out.println("*************************************");
178                System.out.println("小说保存成功");
179                System.out.println("*************************************");
180                System.out.print("继续上传请输入1,返回输入0:");
181                int n = scanner.nextInt();
182               if(n == 1) {
183                   upbook(type);
184               }else if(n == 0) {
185                   lookbook();
186                }
187        }
188     } 
189 } 

用户类和标记常量

View Code
 1 package books;
 2 
 3 import java.io.Serializable;
 4 
 5 public class Use implements Serializable {
 6     private String usename;
 7     private String password;
 8     
 9     public static final String SYS_LOGIN = "LOGIN";      //登陸
10     public static final String SYS_REGISTRATION = "REGISTRATION";      //注册
11     public static final String SYS_BOOK = "BOOK";      //看书
12     public static final String SYS_WUXIABOOK = "WUXIABOOK";      //武侠小说    
13     public static final String SYS_YANQINGBOOK = "YANQINGWUXIABOOK";      //武侠小说    
14     public static final String SYS_UPLOAD = "UPLOAD";      //上传
15     public static final String SYS_DOWNLOAD = "DOWNLOAD";      //下载
16     public static final String SYS_OK = "OK";      //成功
17 
18     public String getUsename() {
19         return usename;
20     }
21     public void setUsename(String usename) {
22         this.usename = usename;
23     }
24     public String getPassword() {
25         return password;
26     }
27     public void setPassword(String password) {
28         this.password = password;
29     }
30     
31 
32 }

 

 

posted on 2013-04-11 19:23  DevYong  阅读(1359)  评论(0编辑  收藏  举报

导航