I am developing a project "Expense Tracker" .This is my second project, Im Stuck with this error.
HTTP Status 500 – Internal Server Error Type Exception Report
Message Unable to compile class for JSP:
Description The server encountered an unexpected condition that prevented it from fulfilling the request.
Exception:
org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: \[1\] in the generated java file: \[E:\\ECLIPSE.metadata.plugins\\org.eclipse.wst.server.core\\tmp3\\work\\Catalina\\localhost\\OnlineExpenseManager\\org\\apache\\jsp\\index_jsp.java\]
The type org.hibernate.SessionFactory cannot be resolved. It is indirectly referenced from required .class files
An error occurred at line: \[15\] in the generated java file: \[E:\\ECLIPSE.metadata.plugins\\org.eclipse.wst.server.core\\tmp3\\work\\Catalina\\localhost\\OnlineExpenseManager\\org\\apache\\jsp\\index_jsp.java\]
Only a type can be imported. org.hibernate.SessionFactory resolves to a package
An error occurred at line: \[17\] in the jsp file: \[/index.jsp\]
SessionFactory cannot be resolved to a type
14: \<%@include file="component/NavBar.jsp" %\>
15:
16: \<%
17: SessionFactory factory=HibernateUtil.getSessionFactory();
18: out.print(factory);
19: %\>
20:
An error occurred at line: \[17\] in the jsp file: \[/index.jsp\]
The method getSessionFactory() from the type HibernateUtil refers to the missing type SessionFactory
14: \<%@include file="component/NavBar.jsp" %\>
15:
16: \<%
17: SessionFactory factory=HibernateUtil.getSessionFactory();
18: out.print(factory);
19: %\>
20:
Stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:102)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:214)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:600)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:381)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:351)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:335)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:597)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:398)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:383)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:331)
javax.servlet.http.HttpServlet.service(HttpServlet.java:583)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
Note The full stack trace of the root cause is available in the server logs.
This is my hibernate class:
package com.db;
import java.util.Properties;
import org.hibernate.SessionFactory;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment;
import org.hibernate.service.ServiceRegistry;
import com.entity.User;
public class HibernateUtil {
private static SessionFactory sessionFactory;
public static SessionFactory getSessionFactory() {
if(sessionFactory == null) {
Configuration configuration = new Configuration();
Properties properties =new Properties();
properties.put(Environment.DRIVER, "com.mysql.cj.jdbc.Driver");
properties.put(Environment.URL, "jdbc:mysql://localhost:3306/expense_tracker_db");
properties.put(Environment.USER, "root");
properties.put(Environment.PASS, "MyNewPass");
properties.put(Environment.DIALECT, "org.hibernate.dialect.MySQLDialect");
properties.put(Environment.HBM2DDL_AUTO, "update");
properties.put(Environment.SHOW_SQL, true);
properties.put(Environment.USE_SECOND_LEVEL_CACHE, true);
properties.put(Environment.CACHE_REGION_FACTORY, "org.hibernate.cache.ehcache.internal.EhcacheRegionFactory");
configuration.setProperties(properties);
configuration.addAnnotatedClass(User.class);
ServiceRegistry serviceRegistry=new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()).build();
sessionFactory=configuration.buildSessionFactory(serviceRegistry);
}
return sessionFactory;
}
}
This is my index file
<%@page import="com.db.HibernateUtil "%>
<%@ page import="org.hibernate.SessionFactory" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<%@include file="component/all_css.jsp" %>
</head>
<body>
<%@include file="component/NavBar.jsp" %>
<%
SessionFactory factory=HibernateUtil.getSessionFactory();
out.print(factory);
%>
<div id="carouselExampleControls" class="carousel slide" data-bs-ride="carousel">
<div class="carousel-inner">
<div class="carousel-item active">
<img src="img/1.jpg" class="d-block w-100" alt="..." height="670px">
</div>
<div class="carousel-item">
<img src="img/2.jpg" class="d-block w-100" alt="..."height="670px">
</div>
<div class="carousel-item">
<img src="img/3.jpg" class="d-block w-100" alt="..."height="670px">
</div>
</div>
<button class="carousel-control-prev" type="button" data-bs-target="#carouselExampleControls" data-bs-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="visually-hidden">Previous</span>
</button>
<button class="carousel-control-next" type="button" data-bs-target="#carouselExampleControls" data-bs-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="visually-hidden">Next</span>
</button>
</div>
</body>
</html>
I tried to change the tomcat server version