0
I’m doing a basic user registration with Servlet
.
When I click on the sign up button I get the following error page (everything has been revised and is in perfect working, I believe it is something related to Hibernate, but nothing that I have solved):
HTTP Status 500 – Internal Server Error
Type Exception Report
Message Servlet execution threw an exception
Description The server encountered an unexpected condition that prevented it from fulfilling the request.
Exception
javax.servlet.ServletException: Servlet execution threw an exception
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
Root Cause
java.lang.NoSuchMethodError: org.jboss.logging.Logger.debugf(Ljava/lang/String;I)V
org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilderOrNull(HibernatePersistenceProvider.java:88)
org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilderOrNull(HibernatePersistenceProvider.java:61)
org.hibernate.ejb.HibernatePersistence.getEntityManagerFactoryBuilderOrNull(HibernatePersistence.java:101)
org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:50)
org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:54)
javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:55)
javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:39)
servlet.CadastroServlet.doPost(CadastroServlet.java:87)
javax.servlet.http.HttpServlet.service(HttpServlet.java:661)
javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
Note The full stack trace of the root cause is available in the server logs.
Apache Tomcat/8.5.33
This is my persistence.xml:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1"
xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:
xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="prova3bPU" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<class>model.entities.Users</class>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="hibernate.cache.provider_class"
value="org.hibernate.cache.NoCacheProvider"/>
<property name="javax.persistence.jdbc.url"
value="jdbc:mysql://localhost:3306/prova3b"/>
<property name="javax.persistence.jdbc.user" value="root"/>
<property name="javax.persistence.jdbc.driver"
value="com.mysql.jdbc.Driver"/>
<property name="javax.persistence.jdbc.password" value="t759m1546"/>
<property name="javax.persistence.schema-generation.database.action"
value="create"/>
</properties>
</persistence-unit>
</persistence>
This is my Servlet:
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String nome = request.getParameter("username");
String email = request.getParameter("email");
String senha = request.getParameter("password");
String confirm_senha = request.getParameter("confirm_senha");
EntityManagerFactory emf = Persistence.createEntityManagerFactory("prova3bPU");
UsersJpaController objJpa = new UsersJpaController(emf);
Users user = new Users();
user.setUsername(nome);
user.setEmail(email);
user.setPassword(senha);
if(senha == confirm_senha){
objJpa.create(user);
request.setAttribute("resp", "efetuado");
request.getRequestDispatcher("cadastro_response.jsp").forward(request, response);
} else {
request.setAttribute("resp", "negado");
request.getRequestDispatcher("cadatro_response.jsp").forward(request, response);
}
processRequest(request, response);
}
Favour [Edit] the question by adding persistence.xml. The problem of putting only links is that they may be inaccessible (which is what happened now, I tried to access codeshare but it is giving error). Putting it in question, everyone can have complete information without relying on other sites. Understand better in https://pt.meta.stackoverflow.com/a/5489/112052
– hkotsubo
Good afternoon friend, thank you for the comment. I just made the edition, I hope you improve the understanding of the question and can help me...
– A. Fernando
What’s on line 87
CadastroServlet.java
? Edit your question and post the code for us to see, please. Ah, and your string comparisonif (senha == confirm_senha)
is wrong, read here (and be careful with null strings).– Piovezan
Right, replace the comparison to "if(password.equals(confirm_password))" and the content of line 87 is the statement of Entitymanagerfactory emf = Persistence.createEntityManagerFactory("prova3bPU");
– A. Fernando