Estoy intentando hacer integracion de Struts2-Hibernate-DisplayTags y he ido solucionando los errores que me han aparecido, pero de este no logro salir.
type Informe de Excepción
mensaje javax.servlet.ServletException: La ejecución del Servlet lanzó una excepción
descripción El servidor encontró un error interno que hizo que no pudiera rellenar este requerimiento.
excepción
org.apache.jasper.JasperException: javax.servlet.ServletException: La ejecución del Servlet lanzó una excepción
org.apache.jasper.servlet.JspServletWrapper.handle JspException(JspServletWrapper.java:549)
org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:455)
org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet .java:728)
causa raíz
java.lang.ExceptionInInitializerError
net.viralpatel.struts.displaytag.HibernateUtil.<cl init>(HibernateUtil.java:22)
net.viralpatel.struts.displaytag.UserAction.execut e(UserAction.java:25)
org.apache.struts.chain.commands.servlet.ExecuteAc tion.execute(ExecuteAction.java:58)
org.apache.struts.chain.commands.AbstractExecuteAc tion.execute(AbstractExecuteAction.java:67)
org.apache.struts.chain.commands.ActionCommandBase .execute(ActionCommandBase.java:51)
org.apache.commons.chain.impl.ChainBase.execute(Ch ainBase.java:191)
org.apache.commons.chain.generic.LookupCommand.exe cute(LookupCommand.java:305)
org.apache.commons.chain.impl.ChainBase.execute(Ch ainBase.java:191)
org.apache.struts.chain.ComposableRequestProcessor .process(ComposableRequestProcessor.java:283)
org.apache.struts.action.ActionServlet.process(Act ionServlet.java:1913)
org.apache.struts.action.ActionServlet.doGet(Actio nServlet.java:449)
javax.servlet.http.HttpServlet.service(HttpServlet .java:621)
javax.servlet.http.HttpServlet.service(HttpServlet .java:728)
org.apache.jasper.runtime.PageContextImpl.doForwar d(PageContextImpl.java:746)
org.apache.jasper.runtime.PageContextImpl.forward( PageContextImpl.java:716)
org.apache.jsp.index_jsp._jspService(index_jsp.jav a:65)
org.apache.jasper.runtime.HttpJspBase.service(Http JspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet .java:728)
org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:432)
org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet .java:728)
org.hibernate.service.classloading.spi.ClassLoadin gException: Unable to load class [com.mysql.jdbc.Driver]
org.hibernate.service.classloading.internal.ClassL oaderServiceImpl.classForName(ClassLoaderServiceIm pl.java:146)
org.hibernate.service.jdbc.connections.internal.Dr iverManagerConnectionProviderImpl.configure(Driver ManagerConnectionProviderImpl.java:104)
org.hibernate.service.internal.StandardServiceRegi stryImpl.configureService(StandardServiceRegistryI mpl.java:75)
org.hibernate.service.internal.AbstractServiceRegi stryImpl.initializeService(AbstractServiceRegistry Impl.java:159)
org.hibernate.service.internal.AbstractServiceRegi stryImpl.getService(AbstractServiceRegistryImpl.ja va:131)
org.hibernate.engine.jdbc.internal.JdbcServicesImp l.buildJdbcConnectionAccess(JdbcServicesImpl.java: 223)
org.hibernate.engine.jdbc.internal.JdbcServicesImp l.configure(JdbcServicesImpl.java:89)
org.hibernate.service.internal.StandardServiceRegi stryImpl.configureService(StandardServiceRegistryI mpl.java:75)
org.hibernate.service.internal.AbstractServiceRegi stryImpl.initializeService(AbstractServiceRegistry Impl.java:159)
org.hibernate.service.internal.AbstractServiceRegi stryImpl.getService(AbstractServiceRegistryImpl.ja va:131)
org.hibernate.cfg.SettingsFactory.buildSettings(Se ttingsFactory.java:77)
org.hibernate.cfg.Configuration.buildSettingsInter nal(Configuration.java:2276)
org.hibernate.cfg.Configuration.buildSettings(Conf iguration.java:2272)
org.hibernate.cfg.Configuration.buildSessionFactor y(Configuration.java:1741)
net.viralpatel.struts.displaytag.HibernateUtil.<cl init>(HibernateUtil.java:20)
net.viralpatel.struts.displaytag.UserAction.execut e(UserAction.java:25)
org.apache.struts.chain.commands.servlet.ExecuteAc tion.execute(ExecuteAction.java:58)
org.apache.struts.chain.commands.AbstractExecuteAc tion.execute(AbstractExecuteAction.java:67)
org.apache.struts.chain.commands.ActionCommandBase .execute(ActionCommandBase.java:51)
org.apache.commons.chain.impl.ChainBase.execute(Ch ainBase.java:191)
org.apache.commons.chain.generic.LookupCommand.exe cute(LookupCommand.java:305)
org.apache.commons.chain.impl.ChainBase.execute(Ch ainBase.java:191)
org.apache.struts.chain.ComposableRequestProcessor .process(ComposableRequestProcessor.java:283)
org.apache.struts.action.ActionServlet.process(Act ionServlet.java:1913)
org.apache.struts.action.ActionServlet.doGet(Actio nServlet.java:449)
javax.servlet.http.HttpServlet.service(HttpServlet .java:621)
javax.servlet.http.HttpServlet.service(HttpServlet .java:728)
org.apache.jasper.runtime.PageContextImpl.doForwar d(PageContextImpl.java:746)
org.apache.jasper.runtime.PageContextImpl.forward( PageContextImpl.java:716)
org.apache.jsp.index_jsp._jspService(index_jsp.jav a:65)
org.apache.jasper.runtime.HttpJspBase.service(Http JspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet .java:728)
org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:432)
org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet .java:728)
causa raíz
Por lo que se ve, según entiendo, me pide el driver jdbc y lo tiene puesto como siempre, en los demás proyectos funciona.
La configuración del hibernate.cfg.xml es la siguiente:
Código:
La Action es esta:<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN" "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory> <!-- Database connection settings --> <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property> <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/bbw</property> <property name="hibernate.connection.username">root</property> <property name="hibernate.connection.password">root</property> <!-- JDBC connection pool (use the built-in) --> <property name="connection.pool_size">1</property> <!-- SQL dialect --> <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property> <!-- Enable Hibernate's automatic session context management --> <property name="hibernate.current_session_context_class">thread</property> <mapping resource="ForbesData.hbm.xml"/> </session-factory> </hibernate-configuration>
Código:
Saludos. package net.viralpatel.struts.displaytag; import java.util.ArrayList; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.struts.action.Action; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; import org.hibernate.HibernateException; import org.hibernate.Session; import org.hibernate.Transaction; public class UserAction extends Action { private final static String SUCCESS = "success"; public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { //Parte de la Query Transaction Tx=null; Session session = HibernateUtil.getSessionFactory().openSession(); System.out.println("userAction"); ArrayList<ForbesData> lista = null; try { Tx = session.beginTransaction(); String query = "SELECT * FROM forbes"; lista=(ArrayList<ForbesData>) session.createQuery(query).list(); System.out.println(lista); //session.close(); Tx.commit(); } catch (HibernateException e) { e.printStackTrace(); } UserForm userForm = (UserForm) form; userForm.setForbesList(lista); return mapping.findForward(SUCCESS); } }