Applet与Servlet通讯 (片段源码)

耿殿东A

耿殿东A

2016-02-19 13:26

下面请跟着图老师小编一起来了解下Applet与Servlet通讯 (片段源码),精心挑选的内容希望大家喜欢,不要忘记点个赞哦!

  Applet与Servlet通讯 (源码) 作者:jdeveloper
  
  Applet source (partly)
  ...
  
  
  

  showStatus(textField1.getText());
  URL servlet = new URL(this.getDocumentBase(),"servlet/GetParameterServlet");
  URLConnection connection = servlet.openConnection();
  connection.setUseCaches(false);
  connection.setDoOutput(true);
  ByteArrayOutputStream byteStream = new ByteArrayOutputStream(1024);
  PrintWriter out = new PrintWriter(byteStream, true);
  String postData = "Name=" + URLEncoder.encode(textField1.getText());
  out.print(postData);
  out.flush();
  String lengthString = String.valueOf(byteStream.size());
  connection.setRequestProperty("Content-Length", lengthString);
  connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
  byteStream.writeTo(connection.getOutputStream());
  BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream()));
  textArea1.setText("");
  String s;
  for(; (s = br.readLine()) != null && s.length() 0; textArea1.appendText(s + ""));
   ...

  Servlet source
  
  
  
  

  // GetParameterServlet
  import Java.io.*;
  import javax.servlet.*;
  import javax.servlet.http.*;
  import java.util.*;
  
  
  public class GetParameterServlet extends HttpServlet {
   public void doGet(HttpServletRequest request,
   HttpServletResponse response)
   throws ServletException, IOException {
  response.setContentType("text/Html");
  
  PrintWriter out = response.getWriter();
  String title = "Reading Request Parameters";
  String name = request.getParameter("Name");
  out.println(title);
  out.println("Hello: " + name );
  
   }
  
   public void doPost(HttpServletRequest request,
   HttpServletResponse response)
   throws ServletException, IOException {
  doGet(request, response);
   }
  }
  

  
  
  
  
  
  
  --------------------------------------------------------------------------------
展开更多 50%)
分享

猜你喜欢

Applet与Servlet通讯 (片段源码)

编程语言 网络编程
Applet与Servlet通讯 (片段源码)

Applet与Servlet通讯的四种方法及其比较

编程语言 网络编程
Applet与Servlet通讯的四种方法及其比较

s8lol主宰符文怎么配

英雄联盟 网络游戏
s8lol主宰符文怎么配

Applet与Application合并

编程语言 网络编程
Applet与Application合并

JAVA卡与APPLET

编程语言 网络编程
JAVA卡与APPLET

lol偷钱流符文搭配推荐

英雄联盟 网络游戏
lol偷钱流符文搭配推荐

JSP与Servlet之一

Java JAVA基础
JSP与Servlet之一

JSP与Servlet之二

Java JAVA基础
JSP与Servlet之二

lolAD刺客新符文搭配推荐

英雄联盟
lolAD刺客新符文搭配推荐

win10 edge浏览器怎么样

win10 edge浏览器怎么样

C++箴言:只要有可能就推迟变量定义

C++箴言:只要有可能就推迟变量定义
下拉加载更多内容 ↓