org.apache.jasper.JasperException: java.lang.ClassNotFoundException: org.apache.jsp.WEB_002dINF.view.all_002demployees_jsp
У меня возникла ошибка, когда я запустил приложение
org.apache.jasper.JasperException: java.lang.ClassNotFoundException: org.apache.jsp.WEB_002dINF.view.all_002demployees_jsp.
вот мой view:
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<body>
<h2>All Employees</h2>
<br>
<table>
<tr>
<th>Name</th>
<th>Surname</th>
<th>Department</th>
<th>Salary</th>
</tr>
<c:forEach var="emp" items="${allEmps}">
<tr>
<td>${emp.name}</td>
<td>${emp.surname}</td>
<td>${emp.department}</td>
<td>${emp.salary}</td>
</tr>
</c:forEach>
</table>
</body>
</html>
класс контроллер:
package com.maksimov.spring.mvc_hibernate_aop.controller;
import com.maksimov.spring.mvc_hibernate_aop.dao.EmployeeDAO;
import com.maksimov.spring.mvc_hibernate_aop.entity.Employee;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import java.util.List;
@Controller
public class MyController {
@Autowired
private EmployeeDAO employeeDAO;
@RequestMapping("/")
public String showAllEmployees(Model model){
List<Employee> allEmployees = employeeDAO.getAllEmployees();
model.addAttribute("allEmps", allEmployees);
return "all-employees";
}
}
класс DAO:
package com.maksimov.spring.mvc_hibernate_aop.dao;
import com.maksimov.spring.mvc_hibernate_aop.entity.Employee;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.query.Query;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@Repository
public class EmployeeDAOImpl implements EmployeeDAO {
@Autowired
private SessionFactory sessionFactory;
@Override
@Transactional
public List<Employee> getAllEmployees() {
Session session = sessionFactory.getCurrentSession();
Query<Employee> query = session.createQuery("from Employee");
List<Employee> allEmployees = query.getResultList();
return allEmployees;
}
}
applicationContext:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">
<context:component-scan base-package="com.maksimov.spring.mvc_hibernate_aop" />
<mvc:annotation-driven/>
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/view/" />
<property name="suffix" value=".jsp" />
</bean>
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close">
<property name="driverClass" value="com.mysql.cj.jdbc.Driver" />
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/my_db?useSSL=false" />
<property name="user" value="bestuser" />
<property name="password" value="bestuser" />
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="packagesToScan" value="com.maksimov.spring.mvc_hibernate_aop.entity" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean>
<bean id="transactionManager"
class="org.springframework.orm.hibernate5.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<tx:annotation-driven transaction-manager="transactionManager" />
</beans>
такая ошибка вылезает, когда я запускаю приложение:
Ответы (1 шт):
Автор решения: Roman C
→ Ссылка
Точно, в методе контроллера неверно указана вьюха. Надо поправить
@RequestMapping("/")
public String showAllEmployees(Model model){
List<Employee> allEmployees = employeeDAO.getAllEmployees();
model.addAttribute("allEmps", allEmployees);
return "all_employees";
}
На странице JSP используется библиотека JSTL старой версии, поэтому тэги не работают.