| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 504 人关注过本帖
标题:Servlet 与Applet 的简单通信,怎么参数老是传不过来呀!
只看楼主 加入收藏
ranran
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2007-4-14
收藏
 问题点数:0 回复次数:0 
Servlet 与Applet 的简单通信,怎么参数老是传不过来呀!

Servlet程序:ServletPage1.java
package ServletAndAppletComunication;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;

public class ServletPage1 extends HttpServlet {
private static final String CONTENT_TYPE = "text/html; charset=GBK";
//Initialize global variables
public void init() throws ServletException {
}
//Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head><title>ServletPage1</title></head>");
out.println("<body bgcolor=\"#ffffff\">");
out.println("<center><b>Servlet通过param标记传递参数给Applet</b>");
out.println("<br><applet code=\"AppletPage1\""+ "width=\"200\" height=\"200\">");
out.println("<param name=\"Data\" value=\"");
out.println(java.text.DateFormat.getDateInstance().format(new java.util.Date())+"\">");
out.println("</applet>");
// out.println("<p>The servlet has received a " + request.getMethod() + ". This is the reply.</p>");
out.println("</center>");
out.println("</body></html>");
}
//Process the HTTP Post request
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}
//Clean up resources
public void destroy() {
}
}
Applet程序: AppletPage1.java
package ServletAndAppletComunication;

import java.awt.*;
import java.awt.event.*;
import java.applet.*;

public class AppletPage1 extends Applet
{
Label label = new Label();
//Construct the applet
public AppletPage1()
{
}
//Initialize the applet
public void init()
{
try {
jbInit();
}
catch(Exception e)
{
e.printStackTrace();
}
}
//Component initialization
private void jbInit() throws Exception
{
this.setSize(200,200);
label.setText("服务器时间是:"+this.getParameter("Data"));
this.add(label,null);
}
//Get Applet information
public String getAppletInfo()
{
return "读取Servlet传过来的参数";
}
}

搜索更多相关主题的帖子: request private package public import 
2007-04-14 14:09
快速回复:Servlet 与Applet 的简单通信,怎么参数老是传不过来呀!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.042507 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved