dabadaba
dabadaba

Reputation: 9512

Java Web Application error. JSP import doesn't work

I am getting started with web application development with Java and I am following a tutorial book to learn. I am using Spring Tool Suite as IDE.

I am supposed to develop a CRUD application step by step, and everything was ok till it wasn't, I am stuck I can't figure out what to do. The solutions I found did not work or are too general.

I got to a point where I have to create a java file containing a DataBaseHelper class. I wasn't very sure where to save it so I just did it in the WebContent folder (I am using a Maven web application "skeleton"). I tried moving it to WEB-INF/lib but it doesn't work anyway.

I am pretty sure that the package containing the DataBaseHelper class is not being imported. The IDE notified me of this, I found that going to Projects>Clear everything would be ok, but it wasn't. It only corrected one line. I used the IDE Validate tool on the file and the lines with the issues and now the IDE is cool with me. It's not working anyway.

When I browse to the jsp file in localhost I get either this error:

enter code herejava.lang.ClassNotFoundException: org.apache.jsp.xxxxxxxxxx_jsp

or this one:

org.apache.jasper.JasperException: cannot compile class for JSP

Here's my java file that whose class I am trying to import:

package com.arquitecturajava;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class DataBaseHelper {
    // blah blah...
}

And one of the JSPs which is not working:

<%@ page import="com.arquitecturajava.DataBaseHelper" %>
<%
    // blah blah...
%>

I have literally no idea what to do.

EDIT: Full stack trace, as requested:

Estado HTTP 500 - Cannot compile class for JSP

type Exception report

message Cannot compile class for JSP

description  The server found an internal error that made it unable to fill this requirement 

exception

org.apache.jasper.JasperException: Cannot compile class for JSP: 

error happened in line: [14] in the generated file: [/home/kpagcha/springsource/vfabric-tc-server-developer-2.9.4.RELEASE/base-instance/work/Catalina/localhost/Aplicacion01HTML/org/apache/jsp/InsertarLibro02_jsp.java]
Only a type can be imported. com.arquitecturajava.DataBaseHelper resolves to a package

error happened in line: 11 in the jsp file: /InsertarLibro02.jsp
DataBaseHelper cannot be resolved to a type
8:  String consultaSQL = "insert into Libros(isbn, titulo, categoria) values ";
9:  consultaSQL += "('" + isbn + "', " + titulo + "', " + categoria + "')";
10:     
11:     DataBaseHelper db = new DataBaseHelper();
12:     int filas = db.modificarRegistro(consultaSQL);
13:     response.sendRedirect("MostrarLibros02.jsp");
14: %>


error happened in line: 11 in the jsp file: /InsertarLibro02.jsp
DataBaseHelper cannot be resolved to a type
8:  String consultaSQL = "insert into Libros(isbn, titulo, categoria) values ";
9:  consultaSQL += "('" + isbn + "', " + titulo + "', " + categoria + "')";
10:     
11:     DataBaseHelper db = new DataBaseHelper();
12:     int filas = db.modificarRegistro(consultaSQL);
13:     response.sendRedirect("MostrarLibros02.jsp");
14: %>


Stacktrace:
    org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:103)
    org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:366)
    org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:468)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:378)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:353)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:340)
    org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:646)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:357)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:728)

And the other error, that happens when I refresh the page 2-3 times. Both errors change randomly.

Estado HTTP 500 - java.lang.ClassNotFoundException: org.apache.jsp.InsertarLibro02_jsp

type Exception Report

mensaje java.lang.ClassNotFoundException: org.apache.jsp.InsertarLibro02_jsp

descripción The server found an internal error that made it unable to fill this requirement 

exception

org.apache.jasper.JasperException: java.lang.ClassNotFoundException: org.apache.jsp.InsertarLibro02_jsp
    org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:177)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:369)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:728)

causa raíz

java.lang.ClassNotFoundException: org.apache.jsp.InsertarLibro02_jsp
    java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    java.security.AccessController.doPrivileged(Native Method)
    java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:132)
    org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:63)
    org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:172)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:369)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:728)

note  The complete trace of the cause of this error can be found in the diary files of VMware vFabric tc Runtime 2.9.4.RELEASE/7.0.47.A.RELEASE.

Upvotes: 0

Views: 1319

Answers (1)

keivn
keivn

Reputation: 114

Im think you have to put your java file in to the scr folder not your webContent, webContent is for html or jsp file only

Upvotes: 1

Related Questions