I have a small chatting App in Java SE for Desktop, I want to implement the same for Web as well, I have ChatServer as :
public class ChatServer extends Thread {
public static final int DEFAULT_PORT = 6035;
public static String initServer() {
String msg = "";
int port = DEFAULT_PORT;
ServerSocket serverSocket = null;
Socket socket = null;
try {
serverSocket = new ServerSocket(port);
msg = "Listening on port " + port;
while (true) {
socket = serverSocket.accept();
/*System.out.println("Connection receive from "
+ socket.getRemoteSocketAddress());*/
ChatHandler handler = new ChatHandler(socket);
handler.start();
}
} catch (IOException ioe) {
System.err.println("Usage: java ChatServer [port]");
System.err.println("Where options include:");
System.err.println("\tport the port on which to listen.");
msg = "Usage: java ChatServer [port]";
System.exit(0);
} finally {
try {
serverSocket.close();
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
return msg;
}
}
Now to call this in index.jsp, I have :
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<h1><%=pkj.com.lenvel.ChatServer.initServer() %></h1>
</body>
</html>
the above code is not showing any message and I'm still confused, where to implement code for Client?