Skip to content

Tag: servlets

Variable returns null

In my project ,I need to pass the “price” value which is retrieved from the database in “” to “display.jsp”.I have achieved it, but the problem is…. I also need to pass the “price” value from “display.jsp” to “seat.jsp”. When I tried, it returns null value for the price variable. display.jsp seat.jsp How can I achieve this? Kindly answer

java.lang.IllegalStateException: ServletConfig has not been initialized in Tests

Here is my Servlet. It gets a String that I’ve put in a ServletContext in my Listener. Here is the Test class The exception I have Code from GenericServlet (javax package) where the exception happens But how do I pass ServletConfig to Generic Servlet or Initialize it? Answer Create a mock ServletConfig, mock its getServletContext() method to return your mocked

Should I use ThreadLocal to store connections?

I code my Test project and it is prohibited to use Spring and Hibernate there. I wanted to manage my transactions from Service layer. For this I have created a class that gets a Connection from the pool and puts it in the ThreadLocal. This is an example of the fields and the method. The class has also close, rollback

Log4j2 tomcat 10 memory leaks on shutdown

I have memory leaks at my tomcat 10.0.16 servlet application. I am using Log4j2 2.17.2 version, and after tomcat shutdown I see next logs: My pom.xml for Log4j2 is: And also log4j2 config Most common fix is to add log4j-jakarta-web, but this does not works for me Answer Fully deleting target folder and recompiling my project seems like resolved my

Java ClassVersionError although version seems to be okay

I’m getting the following error in my java web app (The application launches okay but when I click a button following error occurs). I’m using Tomcat (7.0.109) to run this application. java.lang.UnsupportedClassVersionError: FileDetailsServlet has been compiled by a more recent version of the Java Runtime (class file version 59.0), this version of the Java Runtime only recognizes class file versions

Session created by Tomcat

I am learning session with servlets and i read in the book that to create a session we need to call as below. HttpSession session = request.getSession() This causes the web container to create a session ID and send it back to client so that client can attach it with every subsequent request to the server. When i open developer