How do I get a list of all HttpSession objects in a web application?

No, the Servlet API doesn’t provide a way. You really have to get hold of them all with help of a HttpSessionListener. You can find several examples in the following answers: How to find HttpSession by jsessionid? How to find number of active sessions per IP? How to check Who’s Online? How to invalidate another … Read more

What is the significance of url-pattern in web.xml and how to configure servlet?

url-pattern is used in web.xml to map your servlet to specific URL. Please see below xml code, similar code you may find in your web.xml configuration file. <servlet> <servlet-name>AddPhotoServlet</servlet-name> //servlet name <servlet-class>upload.AddPhotoServlet</servlet-class> //servlet class </servlet> <servlet-mapping> <servlet-name>AddPhotoServlet</servlet-name> //servlet name <url-pattern>/AddPhotoServlet</url-pattern> //how it should appear </servlet-mapping> If you change url-pattern of AddPhotoServlet from /AddPhotoServlet to /MyUrl. … Read more

Best option for Session management in Java

The session management (client identification, cookie handling, saving session scoped data and so on) is basically already done by the appserver itself. You don’t need to worry about it at all. You can just set/get Java objects in the session by HttpSession#setAttribute() and #getAttribute(). Only thing what you really need to take care of is … Read more

Unit testing a Java Servlet

Most of the time I test Servlets and JSP’s via ‘Integration Tests’ rather than pure Unit Tests. There are a large number of add-ons for JUnit/TestNG available including: HttpUnit (the oldest and best known, very low level which can be good or bad depending on your needs) HtmlUnit (higher level than HttpUnit, which is better … Read more

Getting IP address of client [duplicate]

As @martin and this answer explained, it is complicated. There is no bullet-proof way of getting the client’s ip address. The best that you can do is to try to parse “X-Forwarded-For” and rely on request.getRemoteAddr(); public static String getClientIpAddress(HttpServletRequest request) { String xForwardedForHeader = request.getHeader(“X-Forwarded-For”); if (xForwardedForHeader == null) { return request.getRemoteAddr(); } else … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)