Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > Servlets
| Search | Today's Posts | Mark Forums Read
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Servlets section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old August 29th, 2016, 01:55 AM
Registered User
Points: 5, Level: 1
Points: 5, Level: 1 Points: 5, Level: 1 Points: 5, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2016
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default how to write user input to web server

Hi, I need your help to write online user input into text file on hosting apache tomcat server.
  #2 (permalink)  
Old June 5th, 2018, 07:21 AM
Registered User
Points: 15, Level: 1
Points: 15, Level: 1 Points: 15, Level: 1 Points: 15, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2018
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

package test;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;

public class TestServerSocket {

public static void main(String args[]) throws IOException {
final int portNumber = 81;
System.out.println("Creating server socket on port " + portNumber);
ServerSocket serverSocket = new ServerSocket(portNumber);
while (true) {
Socket socket = serverSocket.accept();
OutputStream os = socket.getOutputStream();
PrintWriter pw = new PrintWriter(os, true);
pw.println("What's you name?");

BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
String str = br.readLine();

pw.println("Hello, " + str);
pw.close();
socket.close();

System.out.println("Just said hello to:" + str);
}
}
}


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to save user input in Excel from web page onlyshails Javascript 6 March 25th, 2015 11:02 AM
Not allowed the user to write anything to that dri vinothsiva VB.NET 1 March 23rd, 2007 11:44 AM
Not allowed the user to write anything to that dri vinothsiva Visual Studio 2005 0 March 23rd, 2007 09:01 AM
write info from user input into a text file pkdev Classic ASP Components 1 September 20th, 2003 01:59 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.