Olá pessoal, sou novato por aqui e com java também.
Gostaria de uma ajudinha para descobrir onde escrevi errado o nome do servlet.
O meu aplicativo é um mini-chat. Ele funciona no Eclipse mas quando monto no Tomcat ele não funciona.
Segue o trecho do código abaixo. Caso precise do código completo é só falar. O meu objetivo é colocar o meu jogo na internet já que está pronto no eclipse.
Provavelmente é o URL(getCodeBase() que não acertei o nome do servlet a ser chamado.
String getNextMessage() {
String nextMessage = null;
while (nextMessage == null) {
try {
// URL url = new URL(getCodeBase(), “/servlet/ChatServlet”);
// URL url = new URL(getCodeBase(), “chat”); //produção
URL url = new URL(getCodeBase(), “<a href="http://localhost:8080/chatWebServer/chat">http://localhost:8080/chatWebServer/chat</a>”); //desenvolvimento
HttpMessage msg = new HttpMessage(url);
InputStream in = msg.sendGetMessage();
DataInputStream data = new DataInputStream(
new BufferedInputStream(in));
nextMessage = data.readLine();
}
catch (SocketException e) {
// Can’t connect to host, report it and wait before trying again
System.out.println("Can’t connect to host: " + e.getMessage());
try { Thread.sleep(5000); } catch (InterruptedException ignored) { }
}
catch (FileNotFoundException e) {
// Servlet doesn’t exist, report it and wait before trying again
System.out.println("Resource not found: " + e.getMessage());
try { Thread.sleep(5000); } catch (InterruptedException ignored) { }
}
catch (Exception e) {
// Some other problem, report it and wait before trying again
System.out.println("General exception: " +
e.getClass().getName() + ": " + e.getMessage());
try { Thread.sleep(1000); } catch (InterruptedException ignored) { }
}
}
return nextMessage + “\n”;
}