How to differ sessions in browser-tabs?

You can use HTML5 SessionStorage (window.sessionStorage). You will generate a random id and save in session Storage per Browser Tab. Then each browser tab has his own Id. Data stored using sessionStorage do not persist across browser tabs, even if two tabs both contain webpages from the same domain origin. In other words, data inside … Read more

Simplest way to serve static data from outside the application server in a Java web application

I’ve seen some suggestions like having the image directory being a symbolic link pointing to a directory outside the web container, but will this approach work both on Windows and *nix environments? If you adhere the *nix filesystem path rules (i.e. you use exclusively forward slashes as in /path/to/files), then it will work on Windows … Read more

Eclipse Build Path Nesting Errors

I had the same problem even when I created a fresh project. I was creating the Java project within Eclipse, then mavenize it, then going into java build path properties removing src/ and adding src/main/java and src/test/java. When I run Maven update it used to give nested path error. Then I finally realized -because I … Read more

How to specify the default error page in web.xml?

On Servlet 3.0 or newer you could just specify <web-app …> <error-page> <location>/general-error.html</location> </error-page> </web-app> But as you’re still on Servlet 2.5, there’s no other way than specifying every common HTTP error individually. You need to figure which HTTP errors the enduser could possibly face. On a barebones webapp with for example the usage of … Read more

How to get request URI without context path?

If you’re inside a front contoller servlet which is mapped on a prefix pattern such as /foo/*, then you can just use HttpServletRequest#getPathInfo(). String pathInfo = request.getPathInfo(); // … Assuming that the servlet in your example is mapped on /secure/*, then this will return /users which would be the information of sole interest inside a … Read more

Servlet for serving static content

I came up with a slightly different solution. It’s a bit hack-ish, but here is the mapping: <servlet-mapping> <servlet-name>default</servlet-name> <url-pattern>*.html</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>default</servlet-name> <url-pattern>*.jpg</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>default</servlet-name> <url-pattern>*.png</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>default</servlet-name> <url-pattern>*.css</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>default</servlet-name> <url-pattern>*.js</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>myAppServlet</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> This basically just maps all content files by extension to the default servlet, and … Read more

HttpServletRequest – how to obtain the referring URL?

It’s available in the HTTP referer header. You can get it in a servlet as follows: String referrer = request.getHeader(“referer”); // Yes, with the legendary misspelling. You, however, need to realize that this is a client-controlled value and can thus be spoofed to something entirely different or even removed. Thus, whatever value it returns, you … Read more

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