1
I’m trying to create a web application and want to use java and html. Good after everything set up and ready for a small connection test the following error occurs:
Fev 09, 2016 1:28:02 PM org.apache.catalina.core.StandardWrapperValve invoke
GRAVE: Servlet.service() for servlet [jsp] in context with path [/TesteTemplateImport] threw exception [java.lang.NullPointerException] with root cause
java.lang.NullPointerException
at org.apache.jsp.main_jsp._jspService(main_jsp.java:190)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:438)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:673)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1526)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1482)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
I am beginner and never created a web application, follows below my algorithm for connection with the bank:
package teste;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class Conexao {
static final String JDBC_DRIVER = "org.firebirdsql.jdbc.FBDriver";
static final String DB_URL = "jdbc:firebirdsql:192.168.1.225/3050:D:/Dados/Suporte/Sisplan/Base/Belfast.GDB?sql_dialect=3";
static final String USER = "SYSDBA";
static final String PASS = "masterkey";
public static Connection getConexao() throws SQLException {
try {
Class.forName(JDBC_DRIVER);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
return DriverManager.getConnection(DB_URL, USER, PASS);
}
}
There is one small detail I believe I should mention, this error occurs not at the time I start the server. It starts the application running in eclipse, I go to the web browser type the server address, it opens the page but when I run a select ai yes the error log appears.
This is my code inside the html page:
<%@ page import="teste.Conexao" %>
<%@ page import="teste.UsuarioDao" %>
<%@ page import="teste.Usuario" %>
<%
UsuarioDao udao = new UsuarioDao();
Usuario usuario = (Usuario) udao.buscar("12345678");
out.print(usuario.getNome());
%>
Here is my select:
public Usuario buscar(String rg) {
conectar();
String sql = "SELECT nome FROM ENTIDADE_001 WHERE CODCLI = " + rg;
try {
ResultSet rs = st.executeQuery(sql);
while (rs.next()) {
String rG = rs.getString("rg");
String nome = rs.getString("nome");
pessoa = new Usuario(rG, nome);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
desconectar();
}
return pessoa;
}
And yes. I already added . correct jar with the same version of my jdk and my HAVA_HOME environment variable has no whitespace and this pointing correctly to my jdk folder.
You do
Conexao.getConexao();
on your page, but does not make use (at least with the codes you posted) of this element. Another doubt I have is about the instantiation of the elementpessoa
, which is returned in the methodbuscar
. If no user is found, which return to the page?– Weslley Tavares
True friend, I didn’t even notice. But this code I copied from a tab I was using for alteration and testing. It went unnoticed. But ultimately the getConexao() method is called within the connect() method. And the return to the page is just the name of the user printed between ready texts here of the template. Simple thing just to test the connection.
– Cesar Roberto Martins
I modified the algorithm to remove any doubt. After all it can be a trivial thing that is causing so many headaches for one day.
– Cesar Roberto Martins
Have you checked whether the "rg" being passed as a method parameter
buscar
is, in fact, with the amount you are sending?– Weslley Tavares
I just tested here friend, passing the number of an existing rg in my table worked. However I need to search this value through a form of my login page. I tried request.getParameter("passoword"); within the scope of the <%> tag. However it is obvious that I am doing this wrong since it worked now with the rg set directly in the search method(). Some post to help me on this?
– Cesar Roberto Martins