Tenho o seguinte software, ele deve permitir que eu passe um arquivo, vai emitir uma mensagem no console para apenas para positivar o acesso a uma classe e lista o resultado na página, estou começando e não sei o motivo do seguinte erro:
Os arquivos são os seguintes:
Principal.html
Neste arquivo inicio o programa, ele tem um input para o arquivo e um submit
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Manipulador</title>
</head>
<body>
<form method="get" action="ArqSQL.do">
<input type="file" name="arquivo" size="chars" />
<input type="submit" value="Envia Arquivo" />
</form>
</body>
</html>
EntradaArquivo.java
Este é o Servlet deve listar o conteúdo do arquivo, acredito que faça isto no console
package Model;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class EntradaArquivo extends HttpServlet {
private static final long serialVersionUID = 1L;
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
ArquivoSQL arqsql = new ArquivoSQL();
String endereco = req.getParameter("arquivo");
ServletContext context = getServletContext();
String enderecoCompleto = context.getRealPath(endereco);
BufferedReader buff = new BufferedReader(new FileReader(enderecoCompleto));
String str;
while((str = buff.readLine()) != null) {
System.out.println(str); //Lista o que tem no seu arquivo
arqsql.trataArquivo(str);
}
buff.close();
}
}
web.xml
Este arquivo deve apontar para o servidor qual arquivo executar (EntradaArquivo.java) quando a função ArqSQL.do for usada
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<servlet>
<servlet-name>ManipuladorSQL</servlet-name>
<servlet-class>Model.EntradaArquivo</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ManipuladorSQL</servlet-name>
<url-pattern>/ManipuladorSQL/ArqSQL.do*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>Principal.html</welcome-file>
</welcome-file-list>
</web-app>
ArquivoSQL.java
Este só escreve uma mensagem no console, mas para frente deverá trabalhar no conteúdo antes de devolver à página
package Model;
public class ArquivoSQL {
public void trataArquivo(String str) {
if(str.equals("o")) {
System.out.println("achei a linha que tem escrito SELECT nela!!");
}
}
}
É meu primeiro programa Web e não sei onde estou errando, o que quero é pegar um arquivo trabalhar no conteúdo e listar na página, mas no momento só repassar um OK já está bom, se precisarem de mais informações é só falar.