我一直做B/S模式,现由于公司项目需要
需开发一套C/S模式运用程序软件
个人提出:使用J2SE开发
但由于对于J2SE的不了解,有以下几个疑问
疑问
1:J2SE开发出来的C/S程序,其运行速度如何?(我听说很慢,但我用ECL感觉还是不错呀)
2:C/S MVC架构怎么样实现?展现层跟逻辑层之间的通信是如何的实现的?
3:C/S中的服务端客户端的实现?比如在服务器上运行个小服务器,客户端就是直接操作那个小服务器进行数据交换?这个是怎么
做的?
4:基于要懂得跟明白以上几点,我应该学些什么书?JFC?SWING?还是什么的书籍,请指出

解决方案 »

  1.   

    j2se做C/S好像不是最好的工具1、速度慢,很慢倒也谈不上C/S好像基本不需要考虑服务器吧,jdbc连接数据库就ok了
      

  2.   

    1楼不要误导LZ。
    J2SE是一个平台不是一个工具,如果你做过B/S,并使用了MVC模式,相信C/S下不成问题。
    展现层跟逻辑层之间的通信是通过socket,建议看一下《java网络编程》。
    C/S的服务端和客户端分别只是实现了socket接口的类,具体做法,LZ自己看书吧!
      

  3.   

    可以用socket接口。
    我是用Rmi——远程方法调用,速度好象还不慢,关键在于的你怎样处理,任何一个开发平台,如果你不合理地在服务端与客户端之间交换数据,而且很频繁的话,那系统是不可能高效的。
      

  4.   

    其实看上去好像你的意识是不想改动太多源代码,那么你可以做成C/S,B/S结合的方式。
    说的简单点,就是把一些常用的基本操作做成客户端,交互的部分调用IE并且给地址栏赋值,然后就是B/S操作了
      

  5.   

    guoxyj 首先谢谢你,但你的回答跟感觉是错误的。也许我描述有问题Lisliefor 非常谢谢你,你说的就是我的疑问。我以前从BS模式,但对MVC有个概念不是很清楚。我看别人做的C/S模式
    服务器端都有个小东西运行(也就是服务器),然后客户端跟它进行数据交换。具体说到SOCKET接口,我还不是很清楚,了解过,有没有书直接说到C/S方面的例子?
    fenglibing 谢谢你,我马上去看zouzhiqiangzzq  谢谢你!帮忙顶jinggangshi 谢谢,恩,看样子C/S上的部署就是这个SOCKET接口这里baobao28 谢谢,我就是要重新做个平台东西,呵呵。基本上一个新软件,从部署,到最后。由于对J2SE的不是很了解,所以先问问,到时候下手不至于慌乱
      

  6.   

    部署倒不是很难的事情。
    首先你得下载一个JDK,如果要用到数据库,那么相应的DBMS是必须的。至于MVC模式,如果是小系统的话,MVC模式反而会增加代码量。有一些相关的Demo,解释起来还是比较麻烦的。View层使用的webwork的标签,数据持久层用hibernate,Model层设计业务层接口,实现与业务逻辑分离......期间的配置比较麻烦。
    不过以前倒写过更简单的,jsp + servlet的MVC模式,没有用到什么框架,只需要一小段连接池的配置即可。但这个例子找不到了,如果整理出来,就发给你了。这里给一个简单的socket的示例吧:
    客户端:
    package test;import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.io.PrintWriter;
    import java.net.Socket;public class TimeClient { Socket client; boolean STS = true; PrintWriter out; BufferedReader getMsg; public TimeClient() {
    try {
    client = new Socket("127.0.0.1", 7002); // 与本机在7002端口进行通信 out = new PrintWriter(client.getOutputStream());
    while(STS) {
    out.println("!");
    out.flush();

    // 包装输入流,接受到信息后,后台输出,并传送"end"信息
    getMsg = new BufferedReader(new InputStreamReader(client
    .getInputStream()));
    String line = getMsg.readLine();
    System.out.println(line); if (!line.equals("")) {
    out.println("end");
    out.flush(); STS = false;
    } Thread.sleep(2000);
    }
    } catch (IOException e) {
    System.err.println(e);
    } catch (InterruptedException ee) {
    System.err.println(ee);
    } finally {
    try {
    client.close();
    out.close();
    getMsg.close();
    } catch (IOException ee) {
    System.out.println(ee);
    }
    }
    } public static void main(String args[]) {
    new TimeClient();
    }
    }
    服务端:
    package test;import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.io.PrintWriter;
    import java.net.ServerSocket;
    import java.net.Socket;
    import java.util.Calendar;
    import java.util.GregorianCalendar;public class TimeServer { boolean STS = true; ServerSocket server; Socket con; BufferedReader in = null; PrintWriter out = null; String timeInfo; public TimeServer() { try {
    // 开始监听
    System.out.println("Server has been started !");
    server = new ServerSocket(7002);
    while (STS) {
    con = server.accept(); // 包装输入/输出流
    in = new BufferedReader(new InputStreamReader(con
    .getInputStream()));
    out = new PrintWriter(con.getOutputStream()); // 判断接收的信息是否为客户端传来的数据
    String line = in.readLine();
    System.out.println("line:" + line);
    if (line.equals("!")) {
    // 获取系统时间,写入字符串"timeInfo"
    Calendar now = new GregorianCalendar();
    int hour = now.get(Calendar.HOUR_OF_DAY);
    int minute = now.get(Calendar.MINUTE);
    int second = now.get(Calendar.SECOND); timeInfo = ""; // 清理上一次时间.这句必须加,不然,这个字符串越来越长 // 这里可以单独提取一个方法出来,处理字符串
    if (hour <= 9)
    timeInfo += "0" + hour + ":";
    else
    timeInfo += hour + ":";
    if (minute <= 9)
    timeInfo += "0" + minute + ":";
    else
    timeInfo += minute + ":";
    if (second <= 9)
    timeInfo += "0" + second;
    else
    timeInfo += second; // 写入输出流,并清缓存
    out.println(timeInfo);
    out.flush();
    } else if (line.equals("end")) {
    STS = false; // 当接收到关闭信息后,关闭服务
    }
    }
    } catch (IOException e) {
    System.err.println(e);
    } finally {
    } // 善后
    try {
    server.close();
    con.close();
    out.close();
    in.close();
    } catch (IOException ee) {
    System.out.println(ee);
    }
    } public static void main(String args[]) {
    new TimeServer();
    }
    }先运行服务端程序,不然会抛出异常:
    java.net.ConnectException: Connection refused: connect
    Exception in thread "main" java.lang.NullPointerException
    at test.TimeClient.<init>(TimeClient.java:49)
    at test.TimeClient.main(TimeClient.java:59)因为服务器没有监听这个端口,而导致,连接被拒绝。
      

  7.   

    只要你要你的用户UI设计、监听类、业务逻辑类、数据访问类分离开,基本上就算实现了MVC模式。
      

  8.   

    只要实现UI设计、监听类、业务逻辑类、数据访问类的分离,就算实现了MVC模式。
      

  9.   

    Lisliefor 谢谢,MVC我已经很清晰拉,昨天看拉哈,对SOCKET的使用也明白拉些
    要的就是这东西
    剩下就是UI界面设计拉,SWING类.
    不知道JAVA有没有跟DF那种可拖拉来实现界面设计,感觉这样就方便多拉,在界面方面
      

  10.   

    ECLIPSE的有没可视化的插件?
    我习惯那ECLIPSE
    有没有这方面的书,学习下!
      

  11.   

    Eclipse 有 SWT Designer。不过对系统的要求比较高。
      

  12.   

    Jigloo SWT/Swing GUI Builder for Eclipse :http://cloudgarden.com/jigloo/--->Download and Installation:Please note: if you have installed 4.0 RC1 or RC2 you will need to delete these folders from the plugins and features folders in eclipse before installing version 4.0.
    Alternatively, you can download the zip file from here. Unzip it into the eclipse folder so that the structure is eclipse/plugins/com.cloudgarden.jigloo_4.0.0click "here" for downloading.It's a file of zip, extract it,than enter "features" and "plugins" file, paste the content to your installed path of eclipse. Than restart eclipse.
      

  13.   

    click the link "Documentation", there are some examples for swing and swt, you need them.A Jigloo Swing TutorialA Jigloo SWT TutorialA Jigloo Swing Application Framework (JSR 296) Tutorial