appel d'une classe dans une autre classe
Bonjour à tous,
voici mon code principal qui fonctionne correctement, mais sous mon bouton envoi j'aimerai que s'exécute le code telnet qui suit comment dois je faire pour l'appeler??
Code:
1 2 3 4 5 6 7 8
| public static void telnet()
{
principal.outstr("<html><head></head>",false);
principal.outstr("<body>",false);
principal.outstr("<form method=\"POST\" action=\"??\">",false);
principal.outstr("<tr><td><INPUT TYPE=\"submit\" VALUE=\"Envoi\">\n",false);
principal.outstr("</center></body></html>",true);
} |
code telnet :
Code:
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
| public class telnet extends HttpServlet {
public static void main( String args[]) throws IOException{
String hote="***";
Socket socket = new Socket(hote, 23);
// Input
InputStream is = socket.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
// Output
OutputStream os = socket.getOutputStream();
OutputStreamWriter osw = new OutputStreamWriter(os, "ASCII");
PrintWriter pw = new PrintWriter(osw);
pw.println("HELO");
pw.flush();
String line = br.readLine();
if (!"WELCOME".equals(line)) throw new RuntimeException("Protocol error");
pw.println("GET /toto"); pw.flush();
line = br.readLine();
}
} |