JWorld@TW the best professional Java site in Taiwan
      註冊 | 登入 | 全文檢索 | 排行榜  

» JWorld@TW » Servlet/JSP 討論區  

按列印兼容模式列印這個話題 列印話題    把這個話題寄給朋友 寄給朋友   
reply to postflat modego to previous topicgo to next topic
本主題所含的標籤
無標籤
作者 請教有關於用servlet實踐thin client概念的問題
butalpha





發文: 5
積分: 0
於 2006-09-08 17:17 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
我心中有個servlet疑問不知如何解決,因此來請教各位前輩:

我想在server端將applet執行完畢,讓client端只看到applet的執行結果(實現thin client的概念)

可是我在網路上找好久,這個論壇內也找過了,都沒有我想要的答案。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.io.*;
 
public class sendApplet extends Applet implements ActionListener
{  Label sendlabel;
  Label messageInfo;
  Button sendButton;
  TextField messageText;  //新增一個文字方塊textfield
  TextField sendText;
  URLConnection connect;
  String message;
    URL chatURL;
 
  public String getAppletInfo()
  {  return "sendApplet - Applet to communicate with receiveServlet";
  }
 
  public synchronized void init()
  {  super.init();
    resize(500,300);
    sendlabel = new Label("Enter Message: ");
    messageInfo = new Label("What you have send: ");
    sendButton = new Button("Send");
    sendText = new TextField(40);
    messageText = new TextField(40);
    messageText.setEditable(false);
 
    //下面實作一個Panel
    Panel mainp = new Panel();
    GridBagLayout gbl = new GridBagLayout();
    GridBagConstraints gbc = new GridBagConstraints();
    gbc.weightx = 0;
    gbc.weighty = 0;
    gbc.gridx = 0;
    gbc.gridy = 0;
    gbc.gridwidth = 10;
    gbc.gridheight= 1;
    gbc.anchor = GridBagConstraints.CENTER;
    gbc.fill = GridBagConstraints.NONE;
    mainp.setLayout(gbl);
    gbl.setConstraints(sendlabel,gbc);
    mainp.add(sendlabel);
    gbc.gridy = 1;
    gbc.gridwidth = 9;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbl.setConstraints(sendText,gbc);
    mainp.add(sendText);
    gbc.gridx = 9;
    gbc.gridwidth = 1;
    gbc.fill = GridBagConstraints.NONE;
    gbl.setConstraints(sendButton,gbc);
    mainp.add(sendButton);
    gbc.gridx = 0;
    gbc.gridy = 2;
    gbc.gridwidth = 10;
    gbl.setConstraints(messageInfo,gbc);
    mainp.add(messageInfo);
    gbc.gridy = 3;
    gbc.weighty = 100;
    gbc.gridheight = 10;
    gbc.fill = GridBagConstraints.BOTH;
    gbl.setConstraints(messageText,gbc);
    mainp.add(messageText);
        sendButton.addActionListener(this);
    //把實作出來的Panel加入Applet
    setLayout(new BorderLayout());
    add("Center", mainp);
    chatURL = getCodeBase();
  }
 
  public synchronized void start()
  {
  }
  public synchronized void stop()
  {
  }
  public synchronized void destroy()
  {
  }
 
  //方法send 把client端在applet 中輸入的字串送給Servlet,然後把Servlet 的處理結果顯示出來
  private void Send()
  {  message = sendText.getText();
    sendText.setText("");//清除用戶的輸入資訊
        messageText.setText("message");
    //showStatus("Message send!");
    //把輸入的字串轉化為 x-www-form-urlencoded 格式
    String queryString ="/servlet/ReceiveServlet?message="+URLEncoder.encode(message);
    p("Attempting to send: "+message);
 
    //建立與Servlet的聯接,並取得Servelt的輸出資訊
    try
    {  connect = (new URL(chatURL,queryString)).openConnection();
      showStatus("open connection!!!");
      connect.setDefaultUseCaches(false);//下次連接不用Cache
      connect.setUseCaches(false);//這次連接亦不用Cache
      connect.setDoInput(true);//打開淂流用於讀數據
      connect.setDoOutput(false);//不能用於寫資料
      connect.connect();//server與client的真正連接
      p("Connecting to "+connect);
      showStatus("Open Stream!");
      DataInputStream in = new DataInputStream(connect.getInputStream());
      showStatus("reading!");
      message = in.readLine();
 
      while(message!=null)
      {  messageText.setText(message);
        message = in.readLine();
      }//end while
    }//end try
        catch(MalformedURLException e2)
        {  System.err.println("Malformedurlexception:"+e2.toString());
        }//end catch
        catch(IOException e1)
        {  System.err.println(e1.toString());
        }
  }//end Send
  //applet process client action
    public void actionPerformed(ActionEvent e)
    {  if(e.getSource()==sendButton)
        {  Send();
        }
    }
    private void p(String debug)
    {  messageText.setText(debug);
        //System.out.println("app-servlet:"+debug);
    }
}


上面是一個網路上的例子,我抓來測試用

不過這看起來client端仍然要下載applet才能執行對吧?

雖然是透過servlet來傳送value,不過還不是我想要的
(server端執行完所有事情,client只負責顯示結果)

不知道各位前輩有什麼建議、方法,可以提供給我參考的嗎?

感激不盡


reply to postreply to post
話題樹型展開
人氣 標題 作者 字數 發文時間
1421 請教有關於用servlet實踐thin client概念的問題 butalpha 4028 2006-09-08 17:17
976 Re:請教有關於用servlet實踐thin client概念的問題 kebin_liu 158 2006-09-08 20:28
1192 Re:請教有關於用servlet實踐thin client概念的問題 butalpha 257 2006-09-10 10:08
» JWorld@TW »  Servlet/JSP 討論區

reply to postflat modego to previous topicgo to next topic
  已讀文章
  新的文章
  被刪除的文章
Jump to the top of page

JWorld@TW 本站商標資訊

Powered by Powerful JuteForum® Version Jute 1.5.8